Re: Understanding WM_NCCALCSIZE

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 03/19/04


Date: Fri, 19 Mar 2004 21:34:51 +0100

There are 2 ways that WM_NCCALCSIZE is raised.

#1 with wParam = 0
In this case you should adjust the client rectangle to be some sub-rectangle
of the window rectangle and return zero.

#2 with wParam as 1
In this case you have an option. You can simply adjust the first rectangle
in the array of RECTS in the same way as you did for the first case and
return zero. If you do this the current client rectangle is preserved and
moved to the new position specified in Rect[0] OR;

You can return any combination of the WVR_XXX flags to specify how the
window should be redrawn. One of these flags is WVR_VALIDRECTS which means
that you must also update the rectangles in the rest of the
NCCALCSIZE_PARAMS structure so that:

#1 Rect[0] is the proposed new client position
#2 Rect[1] is the source rectangle or the current window in case you want to
preserve the graphics that are already drawn there.
#3 Rect[2] is the destination rectangle where the source graphics will be
copied to. If this rectangle is a different size to the source the top and
left wil be copied but the graphics will be clipped, not resized. You can
for example copy only a relavent subset of the current client to the new
place.

Hope this helps. I did include the structure for NCCALCSIZE_PARAMS in the
code that went with the article but didn't use case 2

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
Check out February's edition of Well Formed.
Non-client drawing, Graphics Transform stack and Flood-Filling
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at http://bobpowelldotnet.blogspot.com
"J.Marsch" <jeremy@ctcdeveloper.com> wrote in message
news:%23W4HVTdDEHA.3788@TK2MSFTNGP10.phx.gbl...
> Hello all:
> I am creating a control that will have a custom border in its non-client
> area.  This is very similar to Bob Powell's recent article in Well Formed
> magazine.  I think that I have everything working, but there is a point th
at
> I do not understand.
>
> In my case, my control is a container control and not a simple control.
For
> this container control, when I intercept the WM_NCCALCSIZE message, the
> WParam is 1, indicating that the LParam contains an NCCREATESIZEPARAMS
> structure, instead of a simple RECT.
>
> Now here's where I get confused.  My goal is to reduce the size of the
> Client Rectangle so that I have some room in the nonclient area to draw a
> border.
>
> The NCCREATESIZEPARAMS struct contains 3 RECT structs.
> According to msdn, the first rectangle contains the proposed new window
> coordinates.
> The second rectangle contains the coordinates of the window before the
> window was moved or resized.
> The third rectangle contains the coordinates of the windows client area.
> (this rectangle is a bit smaller than the other two)
>
> Now, I'm trying to reduce the size of the client area, so it seemed
logical
> to me that I would want to reduce the size of the third rectangle.
Something
> like this:
>
> ncParams.rgrc2.left += (int)this..BorderWidth;
> ncParams.rgrc2.top += (int)this.BorderWidth;
> ncParams.rgrc2.right -= (int)this.BorderWidth;
> ncParams.rgrc2.bottom -= (int)this.BorderWidth;
>
> However, if I do that, I see this weird effect, where the contents of the
> control get shifted up and to the left to infinity -- the content just
> crawls right off of the viewable area.
>
> Instead, I found that if I make the same alteration to the first rectangle
> (ncParams.rgrc0) instead of the third, the client size ends up being
> corrected exactly as I would have wanted it to be.  I'm happy that it
works,
> but I would like to understand this behavior a bit more.  Can anyone help
me
> out?
>
> Actually, I'd love to understand exactly how to use this message, there
> appear to several different return values that I can set, and I would like
> to know how to use them all.  Is there a good article around on this (I'm
> not really a C++ guy, but I can muddle through if necessary)
>
>


Relevant Pages

  • Re: Opinions on the Law Of Demeter
    ... > implementation of rectangle is sensible or not, ... > rectangle has no way of knowing what's going on....how does the client ... rectangle would have to modify its 'bottom' to some number greater than ... arbitrary changes to those sub-objects. ...
    (comp.object)
  • Understanding WM_NCCALCSIZE
    ... my control is a container control and not a simple control. ... the first rectangle contains the proposed new window ... The third rectangle contains the coordinates of the windows client area. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Full Screen?
    ... You can have a form full screen event if it has thick border and caption. ... attention on the requirement that the CLIENT RECT has to be that big. ... If you meet those requirements Windows will hide the taskbar for you. ... The problem is how to calculate the bounding rectangle of the Form in a way ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: border surrounding an owner-drawn listbox
    ... you can't do this by drawing the client rectangle; you need to get a window ... I can change the shape of a button using SetWindowRgn, but a listbox appears to ... Increasing the clipping rectangle will do no good, because it applies only to the client ... and you can't draw outside the client area. ...
    (microsoft.public.vc.mfc)
  • Re: Opinions on the Law Of Demeter
    ... the point is that the client assumes that the object returned ... but is an object stored in the rectangle. ... > on the servicing class to implement in such a way as to not breach it's ... the fact remains that if client code mutates the ...
    (comp.object)

Quantcast