Solved

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

Posted on 2000-03-07
1
525 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

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

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…

863 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

27 Experts available now in Live!

Get 1:1 Help Now