Getting Latest Rectange & Window Size :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

I have a rectangle of size:

CRect recTmp = CRect(0, 0, 200, 200);

In OnSize() message handler, I'd like to center text and other items inside the rectangle based on the new sizeof the window.

So, if the user resizes the window to CSize newSize(250, 250), the text and items new position will be (125, 125).

Anyways, I need a way to get the most current size of the view rectangle in either CPoint or CSize.

I have tried GetWindowOrg() and GetWindowExt(). I have not gotten any accurate size back from CDC.

Thanks,
Kuphryn
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
This should help: CWnd : : GetClientRect (Note that views & dialogs are both subclasses of CWnd)

The client rectangle is the "inside" part of a view or dialog, which excludes the menu bar, border/frame, and blue title bar.

Also if you add the the OnSize message handler to your view/dialg it gives you the width/height of the client area which can easily be made into a rect (0,0,cx,cy) or point (cx,cy). Just watch out since you get an OnSize message when the window is minimized down to the taskbar.

so in OnSize():

void CMyView : : onSize(UINT nType, int cx, int cy)
{
if (nType != SIZE_MINIMIZED)
{
// do your moving/sizing stuff
}
}