Virtual Developer Workshop: Containerized Development with Docker

The size and position of a property page is taken care of by the property sheet. The property sheet provides enough space to accommodate the largest property page. In spite of this, sometime we still need to move or resize the property page. One situation I can think of where we need to move the property page is when we change the font used by the tab control. Any move or resize of the property page should be done only after changing the tab control appropriately (and the rest of the property sheet if needed) otherwise the end result can be very unattractive.

There are two situations where the property sheet will restore the property page based on its original size. This happens when the user clicks on the Apply button or when a different page is selected. Our solution has to handle both these events to be complete.

Step 1: Add CRect variable to track the page size and position

Since we need to change the size/position in response to two events, it's a good idea to store the size and position information in a rect variable. Note that we don't have a different variable for the different pages. All the pages should be the same size and position. If you can think of a reason to have different sizes or positions for different pages then you need to declare more variables.

If you don't already have a derived class of CPropertySheet, you will have to derive one so that you can add the member variable and handle a couple of windows messages.


Step 2: Handle ID_APPLY_NOW in the Property Sheet class

The class wizard won't be able to help you out here so you have to add the message map entry yourself and also declare the function in the class declaration. The message map entry looks like this. You probably have this already declared if you enable the Apply Now button somewhere in your application.
BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)


The handler function is given below. It simply gets the active page and resizes and repositions it using the stored value in m_rectPage. Of course, don't forget the other application specific code that belongs is OnApplyNow().
void CMyPropertySheet::OnApplyNow()

	// Other OnApplyNow code

Step 3: Handle the TCN_SELCHANGE notification

The TCN_SELCHANGE notification is sent by the tab control whenever the selected tab (page) changes. We can handle this notification in the OnNotify() function. When this notification message is received, the new page has not been activated yet. We let the default handler in the control handle the notification before getting the active page and resizing it.
BOOL CMyPropertySheet::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
	NMHDR* pNMHDR = (NMHDR*) lParam;

	BOOL bRet = CPropertySheet::OnNotify(wParam, lParam, pResult);
	if (TCN_SELCHANGE == pNMHDR->code)
		// If the message hasn't been handled yet let the control 
		// handle it. This will ascertain that the new page
		// is activated
		if( !bRet )
			LRESULT lRes = Default();
			if( pResult ) 
				*pResult = lRes;
		return TRUE;
	return bRet;

Step 4: Move / Resize the active property page

A good place for the initial move or resize of the property page is in the OnInitDialog() function. This is a virtual function in CPropertySheet class and is called after the property sheet is created. You should resize the active property page only, since there is no guarantee that the other pages have been created. Here is a sampe code that increases the width of the property page. Note that you also need to resize the property sheet and the tab control so that the page appears proper.
BOOL CMyPropertySheet::OnInitDialog()
	BOOL bResult = CPropertySheet::OnInitDialog();

	// Increase width of the property sheet by 100 pixel
	CRect rectWnd;
	SetWindowPos(NULL, 0, 0,
		rectWnd.Width() + 100,

	// Increase width of the tab control by 100 pixel
	GetTabControl()->SetWindowPos(NULL, 0, 0,
			rectWnd.Width() + 100,

	// Increase the width of the property page by 100 pixels
	CPropertyPage* pPage = GetActivePage();
	m_rectPage.right += 100;
	return bResult;


  • Moving the Property page

    Posted by Legacy on 11/27/2002 08:00am

    Originally posted by: H.Basavarajgouda

    Can u please tell me how to move a property page which doesn't have the title bar to hold and drag..

    So, it should be possible to drag(move)to the new position on the same window..page has to moved by no of pixels exactly equal to the movement of the mouse cursor..

    Please suggest me regarding this at the earliest..

    Thanks in advance

  • Don't get TCN_SELCHANGE using wizard mode

    Posted by Legacy on 10/06/2000 07:00am

    Originally posted by: Lance Brown


    If i use SetWizardMode i don't get TCN_SELCHANGE any more??

  • Problem with resizing CListCtrl in propertypage

    Posted by Legacy on 11/26/1999 08:00am

    Originally posted by: HP Ng

    I tried Zafir's sample. But when I tried to resize the CListCtrl as follows:

    CRect rc;
    CWnd* pWnd = GetDlgItem( IDC_CLISTCTRL_BOX );
    // here set rc to width of property page
    // and make sure it is inside its property page.
    /then make the move as such:
    ScreenToClient( &rc);
    pWnd->MoveWindow( rc );

    I get the following problem:
    The scrool bars ( horizontal and vertical ) does nto show up at all.
    Furthermore, some of the lines in report view mode disappear.

    Any suggestions is appreciated.
    Kind regards,
    HP Ng

  • m_namePage?

    Posted by Legacy on 05/09/1999 07:00am

    Originally posted by: Srecko Tomasovic

    Where is this variable initialized? Because l can't resize page nor tab, Please help?

  • Moving Property Sheet when created in Win32

    Posted by Legacy on 03/05/1999 08:00am

    Originally posted by: Leon Brits


    How do one place the property sheet at a specific place on the screen?
    The callback in the Property Sheet Header does not seem to work.
    Please give solution using Win32 commands


  • Add an Activex Control into property page

    Posted by Legacy on 02/17/1999 08:00am

    Originally posted by: John ZHANG

    I insert an activex control into a dialog in the resource editor, this dialog used for a property page. I can't see this control in the page.
    If you have any idea to make it works please let me know.

    Thanks a lot


  • Another response to Chad's problem

    Posted by Legacy on 02/10/1999 08:00am

    Originally posted by: Jens Merfert

    Like Craig before I also posted a solution to the "minimum width" problem at the section entitled
    "Creating a Property Sheet Inside a Dialog"

  • Response to Chad's problem

    Posted by Legacy on 02/08/1999 08:00am

    Originally posted by: Craig

    See the section entitled
    Creating a Property Sheet Inside a Dialog

    I've just posted a solution to the "minimum width" problem there.

  • Default size

    Posted by Legacy on 12/21/1998 08:00am

    Originally posted by: Chad Chamberlin

    I can make property pages bigger, but have run into what looks like a minimum
    width of 200 pixels, the height can be made very small. I have written several property sheet/page windows before
    so don't need any basic info. Just any ideas on how to make a very narrow property page.


  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date