Moving and Resizing the Property Pages

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.

protected:
	m_rectPage;

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)
	//{{AFX_MSG_MAP(CMyPropertySheet)
	:
	:
	//}}AFX_MSG_MAP

	ON_COMMAND(ID_APPLY_NOW, OnApplyNow)
END_MESSAGE_MAP()

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()
{
	Default();

	GetActivePage()->MoveWindow(m_rectPage);
	
	// 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;
		}
		GetActivePage()->MoveWindow(m_rectPage);
		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;
	GetWindowRect(rectWnd);
	SetWindowPos(NULL, 0, 0,
		rectWnd.Width() + 100,
		rectWnd.Height(),
		SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	// Increase width of the tab control by 100 pixel
	GetTabControl()->GetWindowRect(rectWnd);
	GetTabControl()->SetWindowPos(NULL, 0, 0,
			rectWnd.Width() + 100,
			rectWnd.Height(),
			SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

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



Comments

  • Moving the Property page

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

    Originally posted by: H.Basavarajgouda

    Hello,
    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
    Basavaraj

    Reply
  • Don't get TCN_SELCHANGE using wizard mode

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

    Originally posted by: Lance Brown

    
    

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

    Reply
  • Problem with resizing CListCtrl in propertypage

    Posted by Legacy on 11/26/1999 12: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 );
    pWnd->GetWindowRect(&rc);
    // 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

    Reply
  • m_namePage?

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

    Originally posted by: Srecko Tomasovic

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

    Reply
  • Moving Property Sheet when created in Win32

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

    Originally posted by: Leon Brits

    Hi,

    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

    Thanks
    Leon

    Reply
  • Add an Activex Control into property page

    Posted by Legacy on 02/17/1999 12: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


    John

    Reply
  • Another response to Chad's problem

    Posted by Legacy on 02/10/1999 12: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"

    Reply
  • Response to Chad's problem

    Posted by Legacy on 02/08/1999 12: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.

    Reply
  • Default size

    Posted by Legacy on 12/21/1998 12: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.

    thanks

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

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds