Re: Understanding WM_NCCALCSIZE
From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 03/19/04
- Next message: Bob Powell [MVP]: "Re: Rezise Image using Aspect Ratio"
- Previous message: Pete: "Re: Extremely slow drawing speed"
- In reply to: J.Marsch: "Understanding WM_NCCALCSIZE"
- Messages sorted by: [ date ] [ thread ]
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) > >
- Next message: Bob Powell [MVP]: "Re: Rezise Image using Aspect Ratio"
- Previous message: Pete: "Re: Extremely slow drawing speed"
- In reply to: J.Marsch: "Understanding WM_NCCALCSIZE"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|