Wild toolbar effect in MFC

This is a discussion on Wild toolbar effect in MFC within the Windows Programming forums, part of the Platform Specific Boards category; OK, it's me again, slowly making my way through all the MFC training material I can find when I tried ...

  1. #1
    Assembler + Basic from 79
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    22

    Exclamation Wild toolbar effect in MFC

    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.

    Code:
    void CMainFrame::OnPaint()
    {
    
    }
    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.

    Code:
    void CMainFrame::OnPaint()
    {
    	
        CBrush* newBrush;
    	CPaintDC paintDC(this);
        // 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));
        else
            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.
        paintDC.SelectObject(oldBrush);
        delete newBrush;
    	
    }
    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)

    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?!?!
    Last edited by Guardian; 05-15-2002 at 05:27 PM.
    Twin engine aircraft are way better. If one engine quits the other takes you to the scene of the crash.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disable button on toolbar - MFC
    By bennyandthejets in forum Windows Programming
    Replies: 0
    Last Post: 05-10-2004, 03:31 AM
  2. MFC :: Dialog ToolBar Won't Show Up ... ?
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 09-05-2003, 05:28 PM
  3. MFC toolbar icons
    By unanimous in forum Windows Programming
    Replies: 0
    Last Post: 01-18-2003, 09:36 AM
  4. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  5. Enable/Disable Toolbar *Buttons* :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-08-2002, 11:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21