OK, it's me again, slowly making my way through all the MFC training material I can find when I tried something and got a big surprise.
I was working with some code to create a simple tool bar. Nothing extravigant just 3 button. I set up the message maps and empty handlers for each button.
This was MFC from scratch so I had built my own handler for ON_WM_PAINT called OnPaint() and derived from CFrameWnd through my CMainFrame class, and the function was also blank.
When I ran it, dispite having WS_CLIPCHILDREN in the create, the toolbar icons would not only get erased if I pulled down the system menu, but the buttons would never rebound after being clicked. Whats more, if I hovered over the sysem EXIT icon till the tool tip appeared, any depressed icon in my toolbar would disappear until another was pressed at which point the missing one would reappear, dispite the tool tip occuring on the other side of the screen.
Obviously I was having repaint problems.
When I added code to the OnPaint handler, everything worked! And the OnPaint has NO code relevent to the toolbar?!?! It's just stuff from the sample code for drawing a stupid colored box. Check the code out.
I tested this in an wizard generated MFC app and it seemed fine but it used the OnDraw in the CView rather then handling the WM_PAINT as I'm doing in the CFrameWnd (or rather what the book is telling me to do)
// Create the approproiate color brush.
if (m_color == Red)
newBrush = new CBrush(RGB(255,0,0));
else if (m_color == Green)
newBrush = new CBrush(RGB(0,255,0));
newBrush = new CBrush(RGB(0,0,255));
// Select the new brush into the DC.
CBrush* oldBrush = paintDC.SelectObject(newBrush);
// Draw the rectangle.
paintDC.Rectangle(50, 70, 300, 340);
// Restore the DC and delete the new brush.
Anyone know what the deal is with handling the WM_PAINT messages through CFrameWnd. What does one need to do to insure the Paint handler will repaint the toolbar if there's nothing else to paint.. (i.e. Before a new document is created in an app)
P.S. If I rem out ALL references to the OnPaint function including the message maps to it and the afx_msg prototypes, the toolbars work properly again?!?!