CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    sunnysky Guest

    In MFC, when opening a file or creating a file, is WM_PAINT generated?

    Hello,

    I am learning MFC programming with the book "Programming Windows with MFC (2nd Edition)". I have some questions about the book example from chapter 9.

    When I open a file or click new file, the function CSquaresView::OnDraw() is called. I checked the stack, the reason is that CView::OnPaint() calls this function. But I don't understand how CView::OnPaint() is called. Is the message WM_PAINT generated if CSingleDocTemplate::OpenDocumentFile() is called by the default setting? Is it possible to change the behavior?

    Thanks,
    Brian

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: In MFC, when opening a file or creating a file, is WM_PAINT generated?

    An application does not (or should not) directly send WM_PAINT message. Instead, it calls a function (Invalidate, InvalidateRect, or one of few others) that invalidates an area of a window. WM_PAINT is further sent by the system, when that area needs to be repainted.

    In our case, the view window is invalidated in the default implementation of CView::OnUpdate. You can put a breakpoint there, then look on call stack window to see what happens before.
    Code:
    void CView::OnUpdate(CView* pSender, LPARAM /*lHint*/, CObject* /*pHint*/)
    {
        ASSERT(pSender != this);
        UNUSED(pSender);     // unused in release builds
    
        // invalidate the entire pane, erase background too
        Invalidate(TRUE);
    }
    That's generally OK, because once the document has been changed, the view must be changed, as well.
    However, if really need it, is possible to change that by overriding CView::OnUpdate and simply do not call the base class method.
    Code:
    void CSDITestView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
    {
        // Do not call base class OnUpdate.
        // Do something else...
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    sunnysky Guest

    Re: In MFC, when opening a file or creating a file, is WM_PAINT generated?

    Thanks a lot. After I set the break point there, I found the reason. When either creating or opening a file, CSingleDocTemplate::OpenDocumentFile() is called. Then it calls InitialUpdateFrame(). Then InitialUpdateFrame() calls CView::OnUpdate().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured