Surfer
asked on
CMDIChildWnd maintain a given frame aspect ratio.
VC6/MFC/Win32
I have a MDI that opens various CMDIChildWnd at the same time. My question is this: Each CMDIChildWnd must maintain a given aspect ratio. If I change the size cx, I want cy to move automatically to maintain the set aspect ratio. If I change the cy I also want cx to also maintain the set aspect ratio. All suggestions welcome and code samples greatly appreciated.
Surfer
I have a MDI that opens various CMDIChildWnd at the same time. My question is this: Each CMDIChildWnd must maintain a given aspect ratio. If I change the size cx, I want cy to move automatically to maintain the set aspect ratio. If I change the cy I also want cx to also maintain the set aspect ratio. All suggestions welcome and code samples greatly appreciated.
Surfer
Override OnSize (
UINT nType,
int cx,
int cy );
Checking cx,cy for your problem
UINT nType,
int cx,
int cy );
Checking cx,cy for your problem
sorry migel, your comment had posted while i was typing :)
take it easy :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry about the delay. You answered my question.
you can write something like this:
add Windows message handler for WM_SIZE to the your Child frame:
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
static bool bReEntrant = false;
if (!bReEntrant)
{
bReEntrant = true;
// aspect ratio 3:1
if (m_bTrackVertPos)
cx = 3*cy;
else
cy = cx/3;
SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOMOVE|SWP_NOZORDER);
bReEntrant = false;
}
CMDIChildWnd::OnSize(nType
}
CChildFrame::CChildFrame()
{
// TODO: add member initialization code here
m_bTrackVertPos = false; // flag set when use resize vertical size of the window
}
to handle user click on the top/bottom resizing frame of the window you have to add next message (WM_NCHITTEST) handler:
UINT CChildFrame::OnNcHitTest(C
{
// TODO: Add your message handler code here and/or call default
UINT uMsg = CMDIChildWnd::OnNcHitTest(
m_bTrackVertPos = (uMsg == HTBOTTOM || uMsg == HTTOP);
return uMsg;
}
note WM_NCHITTESTappear in the messages list if you select filter "Window"