WM_PAINT and windows messaging
I have a program that changes the background of a window to a certain colour when clicked. This brush is temporarily created. I need to know how to find out when windows has finished doing all the painting on the window so that I can notify the window it can delete the brush. The WM_LBUTTONUP event is a temporary workaround simply because I have other times when the window disappears of the screen and comes back with the use of a scrollbar.
Also, what if I send myself a custom message after I call the InvalidateRect function? Would that allow my message to be handled only after the WM_PAINT? BTW: WM_PAINT is handled right now default by Windows. I could still capture the message and then pass it on by simply calling the return DefWindowProc(blah blah blah....) to have Windows handle the rest of the stuff.
[edited by - vlovich on September 2, 2002 12:54:04 PM]
You should set a flag for when the user is clicked and paint accordingly. Then, unset the flag in WM_LBUTTONUP and other messages.
I would suggest just using a persistant brush that you free only when you plan to re-initializing it to a new color. Really, having a single brush GDI object hanging around in the background isn't going to cause anyone's Win98 to crash from GDI abuse.
GDI and brush handles are just pointers without the *, so you can just set it to NULL to start your app, and then just free the brush before you reassign it. Windows should be smart and ignore the call when a NULL parameter is supplied. If not (really loose pseudo-code because I can't remember the brush-API functions off the top of my head):
if(hBackgroundBrush) DestroyBrush(hBackgroundBrush);
- Air
- Lead Programmer : Hour 13 Studios
[edited by - Air on September 2, 2002 1:51:34 PM]
GDI and brush handles are just pointers without the *, so you can just set it to NULL to start your app, and then just free the brush before you reassign it. Windows should be smart and ignore the call when a NULL parameter is supplied. If not (really loose pseudo-code because I can't remember the brush-API functions off the top of my head):
if(hBackgroundBrush) DestroyBrush(hBackgroundBrush);
- Air
- Lead Programmer : Hour 13 Studios
[edited by - Air on September 2, 2002 1:51:34 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement