Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window region

Status
Not open for further replies.

wanmaster

Programmer
Nov 20, 2000
94
NL
I'm sorry, I had already posted this thread in the C++ forum. But since I still don't have a really satifying solution yet and I have a great confidence in the vb-winapi forum members, I'll ask you guys.
One suggestion I got, is to use the "Microsoft Agent" system. I guess that would work, but I see that as the last option.
Anyway, this was my original question (the only real difference with my vb code is that I didn't repaint the window, but just used the Form.Picture property to add an background image):

I've got a graphical problem using a window region. The application I'm making is a sort of screenmate. It's a ball (the elliptic rgn) with a "3d-picture" that bounches on the window's taskbar. You can pick it up en throw it around.

This all works fine, the only problem is that it flickers.
It makes the image blurry and sometimes you can see the window's original rectangle.

The code is really simple (in order of execution):

- winmain, register wnd class, create wnd etc.
- create & apply region (80x80 px), show window
- main loop:
- update position (based on velocity, gravity etc.)
- move window to new position

and in windowproc
- WM_PAINT: bitblt bmp (dc created using createcompatible dc & select bmp into new dc, no rocket science here..)

I first wrote it in vb, but I ended up using so many winapi calls and subclassing my own window, I decided to switch to c++. The vb-code didn't work much better anyway.

I hope someone can give some advice or tips..
(and please tell me if you need more information about the code).

(thread207-403527)
 
Hi,

Can you post the code you use to reposition the window too? I don't think, as long as the window doesn't clip behind any other window or behind the edge of the screen, you need to redraw it do you?
I think that the problem of the flickering is, that you redraw the window when moving the window, which is (not always) needed.
Perhaps the best thing to do is to post a link to the source or atleast the exe file, so we can see exactly what you want and what is going wrong.

(I noticed that you override the WM_ERASEBKGND message. That is unnecessary if you ask me. If you specify NULL in the hBrush parameter of the WNDCLASS(EX) structure it hasn't got a background either.)
 
Just thought I should mention I am making an app with a lot of moving windows on XP and I got a lot of graphic anomalies using MoveWindow. For some reason SetWindowPlacement does a much better job for rapid movement.

Something I would probably at least consider is to keep an offscreen picture of the ball in a picture with a transparent color for the non-ball part. Before drawing the ball, capture the area that would normally be behind your window, put the ball on that image in a Memory DC, BitBlt it out, revert to the original DC(0)image(without ball), offset the ball to the new position, and Blt it out again, using the rectangular area to erase the old ball. Should be plenty fast enough and guarantee no anomalies which I've found to be quite common myself...



 
Thanks for all your replies. Since it is indeed difficult to describe the graphical problems, I'll give you a (temporary) link to the source code. It's not commented too well, but I think it not too difficult to understand what's going on.

The code is located at:
Remedy
 
I'm sorry for the late response, but I didn't get notified for the response... Anyway, it seems to work fine on my computer. No flickering or anything like that. Also I never see the entire window.

I'm running Win2K SP3 and I compiled it with VB6 SP5

Can you perhaps describe when it goes 'wrong'?
 
Thanks for testing, Lucky.

I'm running the same configuration, 1800 MHz, but a lousy videocard. The problem is (but maybe I'm just too critical) that if you move a window 'over' my window, you can see (for a brief moment) it's actually a square window.
But I've noticed that on slower computers, but equipped with a better (GForce-like) videocard, the problem is less visible.

So maybe, I just have to accept the fact it can't be solved just in code..

Remedy
 
I have a P4B 2400 with a GeForce Ti4400 and I see no problems at all. In fact I find the ball quite funny :) The only oddities about the ball are that it bounces too much (it seems like it'll never stop bouncing :)) and if you move your mouse quickly or quite far, it drops the ball down, instead of throwing it really hard. I think it'll also help a bit for the slower computers if you don't use the transparent window (which is also not very liked by windows). I've seen more than once that using transparent windows causes much problems. The ball isn't really that transparent anyway, so I see no problem in disabling it.
 
Nice job, remedy! You should put that up on downloads as a stress reliever when you get the bugs worked out. "My mini piano" got something like a 300k+ downloads for crying out loud. The oddities were quite pronounced on my Celeron 400 with a Voodoo3. The biggest problem is you can see a rectangle being redrawn in the upper 1/8th of the ball, and a black edge around the ball when moving it quickly, and sometimes the window around it as you mentioned.

For one of my projects I have decided to make a blitter for drawing to the desktop. Blting to the desktop can get a little messy but I think I can keep it clean. I wrote the functions for it already but I did it so quickly that my main loop is really buggy. I need to rewrite the main loop but so far it looks like it will work well. May be a little slow at first but there's plenty of ways to speed it up. I'll try it out on your MindBubble and if it helps I'll post the code. I could run into a "gotchya!" here so dont hold me to it :) Like Luke said the Layered Windows can get a bit messy. My blitter will use offscreen alpha blending instead.

-thibault
 
Hi guys,

Sorry for my late response (short vacation).
I'll keep on optimizing && fixing the code. I've tried a different way of creating irregular shaped windows, but it didn't make much difference in performance. I'll show you anyway:

I used the SetLayeredWindowAttributes function to specify a colorkey:

Code:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const LWA_COLORKEY = 1

Private Sub SetColorKey(ByVal hWnd As Long, ByVal ColorKey As Byte)
    
    'set window style
    SetWindowLong hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
    'set color key
    SetLayeredWindowAttributes hWnd, ColorKey, 0, LWA_ALPHA
End Sub

It is a cool trick, especially when the region is more complex than a simpel circle. But it probably only works on W2K or XP.

I've been thinking ahead, in case I can solve the current problems: what about a LanBubble? Same bubble, but capable of jumping from one desktop to another (using winsock).

Anyway, thanks for all your comments, and I'll let you know about new features (or bugs) if you want..

Remedy
 
hehe. That's a good idea. I can see that being a popular time killer in the workplace. You have a lot of options for the objective of the game as well. Maybe have a pong like rectangle that could knock the bubble back to the thrower really fast, and if it goes past your screen to the next workstation you lose a pt or something. Or have no pts at all. People would love that especially places like call centers or email processing centers where the work can be very monotonous and you're on a big lan.

I haven't had a chance to work on my bltter because I've got a new project that I'm entrenched in(you know how it is).. If you want to try that approach yourself all you do is take the smallest box that contains your Bubble and make an imaginary grid on the desktop where each cell is the size of this box. Then before you draw the object, you grab all the cells that your object's rectangle overlaps, make two copies of this one for the foreground and one for the background to erase your object later. Then place your object on the foreground with TransparentBlt and blt out all the foreground cells to the Desktop(now containing your object). Check if the object has crossed into new cells on the next move. If it hasn't, just copy over the old foreground cells with the old background cells(to get a clean slate) and then put the object on the foreground cells again(in the new position), and blt it out, with the new foreground cells erasing the old part of the object.

It works pretty good on my 400 Celeron. Looked a little better than moving a window to me. I'm having a probelm with the code though because my order of operations is wrong somewhere and it eventually fails to clear the background cells(in memory) correctly so the desktop gets jumbled up. Lotta work though to get it right I dont' have the motivation to fix it at the moment. I think there is another professional technique that just blts the minumum amount of pixels by blting background lines instead of a whole box. I think this may be just as easy as grabbing a whole cell which I did out of laziness. Anywya just felt obliged to mention this in case you thought it might be worth your time... later...

 
Oh - looks like I got back from holiday too late too look at the code, so I can't offer any advice...
 
It's certainly worth examining. And indeed I know how it is (working on a directx8 3d-game right now). But I guess it only shows the importance of a forum. It redirects your attention to old, unfinish, but promising projects.

strongm (or others):
There are some problems with the server I used.
If you want it, I can e-mail it to you.

Remedy
 
Yeah, email it. Here's a throwaway address: amateuractor'AT'hotmail.com
 
Hurrah! Got the code, thanks Remedy. Ran it on a 750 with a GeForce 2 MX400, W98SE, VB6 SP5, and don't get the square window artificat effect that you mention. So, after all that. I don't think I can offer any real advice.
 
Well, at least you got something to play with.. I've got about the same configuration as you, processor is a bit slower though. Maybe time for a new computer... (and hey, it's almost christmas!)

Remedy
 
I've told my wife that a new computer would be nice for Xmas. Oddly, she seems reluctant...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top