Solved

CMDIChildWnd maintain a given frame aspect ratio.

Posted on 2001-06-14
6
340 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:Surfer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6190068
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"
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6190084
Override OnSize (
UINT nType,
int cx,
int cy );
Checking cx,cy for your problem
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6190091
sorry migel, your comment had posted while i was typing :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:migel
ID: 6190133
take it easy :-)
0
 
LVL 12

Accepted Solution

by:
migel earned 200 total points
ID: 6276402
Hi!
anybody here??
none??
so I lock this Q.
0
 

Author Comment

by:Surfer
ID: 6278004
Sorry about the delay.  You answered my question.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question