Window taking over my WM_NCPAINT message!
Posted on 2002-07-19
Dear programming buddies!
I have written a class that customizes the caption titlebar of my main application window. It stretchblt's it of a series of tileable bitmaps. As a result, the close, minimize and restore buttons are also drawn of a small bitmap.
The effect desired is a titlebar that appears more alive, one that responds to mouse movement where caption buttons light up when moving the cursor over them, as well as WM_LBUTTONDOWN bitmaps etc. That sort of thing.
I have handled WM_NCPAINT, and WM_NCACTIVATE in order to achieve this. But I have come accross a HUGE bug which I can't find to solve.
IN WINDOWS '98 THE FOLLOWING HAPPENS:
After I have received a WM_CONTEXTMENU message, invoked by either mouse or keyboard events, the three buttons as well as the background bitmap around the region of the caption buttons disappear after clicking inside the caption titlebar.
I have used Spy++ to take a look at my messages, and quite strangely Windows performs default processing by drawing your ordinary button type caption buttons as well as a part of the caption bar around the region of the caption buttons. It appears that Windows simply erases my bitmap with its own default button drawing mechanism.
The reason why this puzzles me is the fact that I have not received a WM_NCPAINT message at all, meaning that there is no invalid region on the non-client area. I even tried calling my OnNcPaint() function in between the messages sent on button clicks and mouse movements and after receiving WM_CONTEXTMENU, but only to cause unwanted flickering.
Windows can't be doing DefWindowProc() for drawing default buttons, as this would only happen after I have received WM_NCPAINT, and I am not calling DefWindowProc() in my WM_NCPAINT message handler. My OnNcPaint() message handler is fully responsible for drawing the caption titlebar as well as the window frame.
When I move the window with the caption buttons out of the desktop boundaries, and move it back to a viewable spot, my bitmap buttons reappear, only to disappear mysteriously after you click on the titlebar, or quite so often after a mousemove/hittest message.
IN WINDOWS 2000, SOMETHING SIMILAR HAPPENS:
The whole insident as mentioned above happens with only one difference, Windows only takes over after I have minimized the application by clicking on the taskbar button, WM_CONTEXTMENU has no effect. When I click the minimize button beforehand, it does not affect the application in this way either, only clicking the taskbar causes Windows to take over. After "taskbar minimizing" Windows starts redrawing my caption buttons and the background region around them, thus erasing my blt'ed bitmap. Drawing is done, and WM_NCPAINT is not even in sight in Spy++ (and I am filtering out ALL messages, if you were wondering) !!!
Please note: This all happens in Win32 API code, I'm not using MFC at all.
Please, please, please take a look at this and help me find a solution. If you would like to have the source code, email me at email@example.com.
MY PRESUMPTION IS AS FOLLOWS:
I thought that somewhere along the line, I lost a DC or forgot to restore to the previously selected HGDIOBJ. This was not the matter however, I made dead sure that all my device contexts are restored and my GDI objects are deleted from memory after I have used them and unselected them from their DC's. I think I'm just not catching the right message somewhere along the line, or Windows sets a flag which I know not where to find to reset.
! ! ! PLEEZ HELP ME, I'M HOPELESSLY NOT SURE WHAT TO DO ANYMORE, AND I AM NOT GIVING UP ! ! !