Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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