CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2002
    Posts
    4,640

    [RESOLVED] Calling default in OnNcPaint defore my painting paints over mine?

    Okay, this is been bugging me for the past couple of days. I'm overriding OnNcPaint to do my own caption painting (in a dialog box). If I call "Default" before I do my painting, the default caption and borders remain (as if I'm not painting at all). If I comment out my call to "Default", my caption looks great, but I get no menu bar (yep, I have a menu on the dialog). If I call "DrawMenu" before or after painting, the dialog is all screwed up (and there is no painting in the nonclient area).

    Any ideas on what I might have missed? I'm running VS2012, on Windows 7.

    Viggy

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    I would try to paint your stuff first and remove the painted area from the update region, then call default.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Hmmm, that doesn't seem to be working. In looking at the bounding box for the update region, it looks like it's in client coords, it doesn't include the nc area. In testing (using ValidateRgn), the nc area isn't affected...

    Viggy

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Interesting. From the MSDN:
    The system maintains an update region for the nonclient area. When an application receives a WM_NCPAINT message, the wParam parameter contains a handle to a region defining the dimensions of the update region.
    Since I'm working in MFC, I don't get the wParam argument for my override (I'm handling NC painting in the "OnNcPaint" function). Any idea on how to get the handle to this region from the window? I'm not finding anything in the MSDN.

    Viggy

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Okay, I've attached an example of what I'm trying to do. Build and run the program, and notice that the menu isn't drawn (until you hover the mouse over it). Comment out the "Default()" calls in my "OnNcPaint" and "OnNcActivate" overrides, and all my work goes away!

    Viggy

    NCPaintTest.zip

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Quote Originally Posted by MrViggy View Post
    Interesting. From the MSDN:

    Since I'm working in MFC, I don't get the wParam argument for my override (I'm handling NC painting in the "OnNcPaint" function). Any idea on how to get the handle to this region from the window? I'm not finding anything in the MSDN.

    Viggy
    I always used CWnd::GetCurrentMessage()
    Will play with your test case.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Quote Originally Posted by MrViggy View Post
    Okay, I've attached an example of what I'm trying to do. Build and run the program, and notice that the menu isn't drawn (until you hover the mouse over it). Comment out the "Default()" calls in my "OnNcPaint" and "OnNcActivate" overrides, and all my work goes away!

    Viggy
    I might be wrong, but I don't see where you handle WM_NCCALCSIZE message.
    How does the window know that a part of its client area is painted as a non-client?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  8. #8
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    I tried handling the WM_NCCALCSIZE message, but nothing inside the client area was being painted. I set the rectangles to the coords of the client area.

    I'll give it another shot...

    Thanks!

    Viggy

  9. #9
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    My point is - you shouldn't paint client area in WM_NCPAINT, as it will be clipped out.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  10. #10
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Calling default in OnNcPaint defore my painting paints over mine?

    Correct. I'm not, really. The code excludes the client area from the clipping region, so I don't have to worry about "accidentally" drawing in the client region.

    Also, in reading the MSDN, the WM_NCCALCSIZE tells the system what the valid client area is. My non-client area is the same as the system defaults, so I don't think I need to handle this message...

    Viggy
    Last edited by MrViggy; June 25th, 2013 at 03:09 PM.

  11. #11
    Join Date
    Feb 2002
    Posts
    4,640

    Re: [RESOLVED] Calling default in OnNcPaint defore my painting paints over mine?

    Okay, I finally found one solution to my problem (there may be others). Before I do my painting, I can call the default window proc, passing in a nonclient region that is only the menu area:
    Code:
        CRect rc;  
        GetWindowRect(rc);  
        rc.top = rc.top + ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CYCAPTION);  
        rc.bottom = rc.top + ::GetSystemMetrics(SM_CYMENU);  
        rc.left += ::GetSystemMetrics(SM_CXSIZEFRAME);  
        rc.right -= ::GetSystemMetrics(SM_CXSIZEFRAME);  
        HRGN hRgnCaption = ::CreateRectRgnIndirect(&rc);  
        DefWindowProc(WM_NCPAINT, (WPARAM)hRgnCaption, NULL);  
        DeleteObject(hRgnCaption);
    Thanks for the suggestions!

    Viggy

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