 |
NEWBIE
TIP
#7
Sizing an MDI Child Window
If I know I want my view's drawable region to be 100 x 100, how do I make it so?
I am guessing that I need to have the parent-frame do SetWindowPos, and then
that will automatically resize the view after resizing the frame. But how
do I figure out how big the parent frame needs to be?
Try this in CMyView:
// Get the parent frame window. This CWnd function searches up the
// parent chain until a CFrameWnd (or derived class) object is found.
CFrameWnd *pFrame = GetParentFrame();
// Get the size of the client portion of the window.
CRect cRect;
pFrame->GetClientRect( &cRect );
// Get the size of the entire window.
CRect wRect;
pFrame->GetWindowRect( &wRect );
// Calculate the new window size by subtracting out the client
// size, and adding 100 (we want the *client* area to be 100).
wRect.right = wRect.right - cRect.Width() + 100;
wRect.bottom = wRect.bottom - cRect.Height() + 100;
// Now resize the window. Ta-da!
pFrame->SetWindowPos( NULL, 0, 0, Rect.Width(), wRect.Height(),
SWP_NOZORDER | SWP_NOMOVE);
|
Original question posed by Herbert Enderton.
Answer was provided by Rick Murtagh.
We cleaned up the code and provided comments.
Source code
is provided for instructional purposes,
and is released to the public domain.
No claim of ownership is made.
Use it at your own risk.
No warranties are expressed or implied.
The resulting program may not be fully functional.
No animals were used to test this code.
|
Past Tips |
Future Tips |
Home |
Comments on this Tip?
Send us mail.
(Be sure to put the Tip # in the subject.)
Got an idea for a Tip you'd like us to write?
Let us know.
Solved a problem lately that would make a good Tip?
PLEASE tell us about it!!!
We'll give you prominent credit, and we'll even buy you a beer next time you're in town.
|