Solved

How to dynamically change size of a property page in property sheet?

Posted on 2000-03-07
1
523 Views
Last Modified: 2013-11-20
I have a property sheet dialog box with two property pages.
  I have a button(say labled "resize") on one of my property pages.On pressing that button I want to change the size of the property sheet dialog box.
  How is it possible?
  Moreover I want to place the "OK","CANCEL","APPLY" buttons of property sheet at desired locations on dialog box.How is this also possible?


How to dynamically change size of a property page in property sheet?
0
Comment
Question by:sjhunjhunuwala
1 Comment
 

Accepted Solution

by:
maknight earned 50 total points
ID: 2591452
A bit more involved than a 50-pointer, but here goes. . . The trick here, is to actually create the dialog as the largest you want it, add a control (usually a "line") that you can key off of as the bottom of the smallest version of the dialog, and then redraw as needed. You can create a "line" by using the picture frame and collapsing it all the way down. Here's some code as I used it.

    // get current dialog window rectangle
    CRect rcDialog;
    GetWindowRect(&rcDialog);
    int nNewHeight = -1;

    if (bExpand)
        {
        // change caption
        pWndButton->SetWindowText(strLess);

        // calculate new dialog height
        CWnd* pWndLarge = GetDlgItem(nLargeID);
        ASSERT_VALID(pWndLarge);
        CRect rcLarge;
        pWndLarge->GetWindowRect(&rcLarge);
        nNewHeight = rcLarge.top - rcDialog.top;
        }
    else
        {
        // change caption
        pWndButton->SetWindowText(strMore);

        // calculate new dialog height
        CWnd* pWndSmall = GetDlgItem(nSmallID);
        ASSERT_VALID(pWndSmall);
        CRect rcSmall;
        pWndSmall->GetWindowRect(&rcSmall);
        nNewHeight = rcSmall.top - rcDialog.top;
        }

    // set new dialog height
    ASSERT(nNewHeight > 0);
    SetWindowPos(NULL, 0, 0, rcDialog.Width(), nNewHeight, SWP_NOMOVE | SWP_NOZORDER);

    // set the enabled state for controls depending on whether visible or not
    CWnd* pWndControl = GetWindow(GW_CHILD);
    while (pWndControl != NULL)
        {
        CRect rcControl;
        pWndControl->GetWindowRect(&rcControl);
        pWndControl->EnableWindow(rcControl.top <= rcDialog.top + nNewHeight);
        pWndControl = pWndControl->GetWindow(GW_HWNDNEXT);
        }
    CWnd* pWndActiveControl = CWnd::GetFocus();
    if (pWndActiveControl == NULL)
        {
        CWnd* pWndFirstControl = GetNextDlgTabItem(NULL);
        ASSERT_VALID(pWndFirstControl);
        ASSERT(pWndFirstControl->IsWindowEnabled());
        pWndFirstControl->SetFocus();
        }

As for the property page buttons... Use the OnInitDialog override, add a new function (say, MoveTheButtons), get the rectangle for each of the buttons one by one, using:

CWnd* pWndOK = pSheet->GetDialogItem(IDOK);
CRect rcOK;
pWndOK->GetWindowRect(&rcOK);
pWndOK->ScreenToClient(&rcOK);

Then, get the property sheet client rectangle using:
CRect rcClient;
pSheet->GetClientRect(&rcClient);

Next, computer your new desired locations, then call SetWindowPos for each button.

pWndOK->SetWindowPos(NULL, nCurrentX, nTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 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