I want to self-draw the title bar of a window with MFC. So I override the OnNcPaint() method of CMainFrame. Everything seems alright, until I click the item in the control menu to make it minimize or maximize. During the minizing or maximizing process, I can see the original title bar appeared. I don't know why this happened. Maybe there are some messages I didn't handle in the process? Need your help. Thanks a lot!
views:
849answers:
4You can use Spy++ to see what messages a window received. I have vague memories of OnSize coming earlier than some messages that I expected.
During the minimize/maximize process? Sounds like min/max animations. You could verify this by disabling the animations via My Computer > Properties > Advanced > (Performance) Settings.
As for the title question, you will get WM_SIZE. Take a look at the docs for CWnd::OnSize.
CMyDialog::OnSize(UINT nType, int cx, int cy)
{
switch (nType)
{
case SIZE_MAXIMIZED:
// window was maximized
break;
case SIZE_MINIMIZED:
// window was minimized
break;
case SIZE_RESTORED:
// misleading - this occurs when restored from minimized/maximized AND
// for normal size operations when already restored
break;
default:
// you could also deal with SIZE_MAXHIDE and SIZE_MAXSHOW
// but rarely need to
break;
}
}
OnShow is called before. OnSize is called after..
I think the values are SW_MAXIMIZE
and SW_MINIMIZE
..
There's also a way to make it so your app doesn't care about the animation settings in windows.
There's an artical about adding your app to the system tray when minimized, that covers the drawing amazingly. It's been years since I used it, but if you can find that, you'll be golden.
You're talking about the window animation, right? Where the window is shown "growing" or "shrinking" from its current size and position to the maximized size or to the taskbar.
That animation is performed independently of the appearance of your window. You can call the DrawAnimatedRects
API function to trigger the animation yourself. It just draws a normal caption bar according to the current display settings.
Notice that other windows with custom-drawn title bars behave the same way. Look at the various versions of Office, for instance. While minimizing or maximizing, the Windows caption bar is drawn, not the customer caption bar. You can also see anomolies when resizing windows that won't take up the full screen. When maximizing the Hearts game, for instance, the animation shows the window expanding to the full width of the screen, but when the animation is over, the window is narrower (but still maximized).
So, to answer your question, no message is sent. The resize animation is performed by the window manager without any assistance or involvement from the window being resized. As far as your program is concerned, the window goes directly from its original size to its new size.