Solved

Resizing in applications developed with MFC

Posted on 1998-07-02
6
513 Views
Last Modified: 2013-11-19
How can I resize the view of an SDI application (developed in C++ using MS Developer studio) so that the view fits on the screen irrespective of the resolution of the monitor it is running on ? Is there a simple way out to do so or do I need to implement a rather complex resizing logic to format the view depending on the available display area ?
0
Comment
Question by:psapra
[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
6 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1318677
View is occupied client area of the parent frame. You need to change frame size. To maximize frame call AgxGetMainWnd()->ShowWindow(SW_SHOWMAXIMIZED)
0
 

Author Comment

by:psapra
ID: 1318678
I guess I did not make my question clear. The view has been designed using the developer studio, which means that every control on the form has a fixed position. It whole form fits nicely on a 1024x768 resolution with small fonts. If the font size is changed to large fonts, the whole application view does not fit on the window and it is necessary to scroll vertically and horizontally to see the entire window. Is there a way to fix this ?
0
 
LVL 1

Expert Comment

by:Arkadiy
ID: 1318679
You run into one of more annoying limitations of diaolg templates. However, overcoming that limitation does requre extensive coding. For a generic way to do it, look at GridBagLayout class in Java. You may come up with something much simpler according to your specific form. In any case, extensive programming is enevitable.
0
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 4

Accepted Solution

by:
piano_boxer earned 100 total points
ID: 1318680
Place a hidden control at the bottom right position of the dialog-template, and use this to resize the frame so that all controls are visible.

BOOL CTestView::OnInitialUpdate()
{
    [......]

    CWnd* pWnd = GetDlgItem(IDC_HIDDEN_CONTROL);
    ASSERT_VALID(pWnd);
    CRect rc;
    pWnd->GetWindowRect(&rc);
    ScreenToClient(&rc);

    // Now rc contains (in left/top) the size of the view
    // that we want.

    // Adjust size of frame (and center on screen)
    CSize size(rc.left, rc.top);
    AdjustFramesizeToFit(size);

    [......]
}



void CTestView::AdjustFramesizeToFit(const CSize size)
{
    CRect rcClient, rcAdjust1, rcAdjust2, rcFrame;

    // Get frame windows client rect
    AfxGetMainWnd()->GetClientRect(&rcClient);

    // Get leftover space for view-area
    AfxGetMainWnd()->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rcAdjust1);

    // Now we know how much space toolbars etc. are taking.
    // Adjust size of frame window
    rcFrame.left = 0;
    rcFrame.top = 0;
    rcFrame.right = rcAdjust1.left + size.cx + (rcClient.right - rcAdjust1.right) + 4;
    rcFrame.bottom = rcAdjust1.top + size.cy + (rcClient.bottom - rcAdjust1.bottom) + 4;

    AfxGetMainWnd()->ClientToScreen(&rcFrame);
    ::AdjustWindowRectEx(&rcFrame, AfxGetMainWnd()->GetStyle(), TRUE, AfxGetMainWnd()->GetExStyle());

    AfxGetMainWnd()->SetWindowPos(
NULL,
rcFrame.left,
rcFrame.top,
rcFrame.Width(),
rcFrame.Height(),
SWP_NOZORDER|SWP_NOMOVE);

    AfxGetMainWnd()->CenterWindow();
}


.

Please note that the function WILL NOT work correctly if the menu bar wraps around because of to small frame!

0
 
LVL 3

Expert Comment

by:eugenem
ID: 1318681
For dynamic dialog templates go to
http://www.codeguru.com/dialog/dialog_toc.shtml
0
 

Author Comment

by:psapra
ID: 1318682
piano_boxer:

I tried doing what you suggested, but it still doesn't resize the application view. Can you offer any further help ?
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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