Link to home
Start Free TrialLog in
Avatar of Surfer
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
Avatar of migel
migel

Hi!
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, cx, cy);
}

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(CPoint point)
{
     // TODO: Add your message handler code here and/or call default
     UINT uMsg = CMDIChildWnd::OnNcHitTest(point);
     m_bTrackVertPos = (uMsg == HTBOTTOM || uMsg == HTTOP);
     return uMsg;
}

note WM_NCHITTESTappear in the messages list if you select filter "Window"
Override OnSize (
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
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Surfer

ASKER

Sorry about the delay.  You answered my question.