Solved

Resizing in applications developed with MFC

Posted on 1998-07-02
6
494 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

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

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. …
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

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

18 Experts available now in Live!

Get 1:1 Help Now