Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Resizing in applications developed with MFC

Posted on 1998-07-02
6
Medium Priority
?
528 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Accepted Solution

by:
piano_boxer earned 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

571 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