Solved

CMDIChildWnd maintain a given frame aspect ratio.

Posted on 2001-06-14
6
328 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
sameEnds challenge 3 135
sum28 challenge 31 107
Is there a simple front-end menu system. 9 72
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

26 Experts available now in Live!

Get 1:1 Help Now