Solved

CMDIChildWnd maintain a given frame aspect ratio.

Posted on 2001-06-14
6
326 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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. …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now