Solved

Resizing in applications developed with MFC

Posted on 1998-07-02
6
497 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
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
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 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

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
Prevent this page from creating additional dialogs. 3 409
post4 challenge 28 93
scoreUp challenge 14 57
wordmultiple challenge 12 121
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

12 Experts available now in Live!

Get 1:1 Help Now