WM_PAINT and windows messaging

Started by
5 comments, last by vlovich 21 years, 7 months ago
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]
Advertisement
You should set a flag for when the user is clicked and paint accordingly. Then, unset the flag in WM_LBUTTONUP and other messages.

Read the post again. I said the flag method won''t work.
Why would you need to delete the brush in between?
I don''t. I need to do it after the window is drawn.
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]
The problem is that I have to get brushes i created previously back to repaint windows. i''m trying to figure out how to change the background of a window by using only the WM_SETWINDOWLONG. but i don''t know the byte off-set for background.

This topic is closed to new replies.

Advertisement