Adding a Control to the Property Sheet

Each property page has its own set of controls. The only control that they share are the standard button in the property sheet itself. If you want to add an edit control, a preview button or any other control, you have to do it at run time. The code below shows you how to add an edit control.

Step 1: Derive your own class from CPropertySheet

We cannot use the CPropertySheet class directly, since we need to add a member variable. If you aren't already using a sub-class of CPropertySheet then derive one.

Step 2: Add member variable

Add member variable to the CPropertySheet derived class. The edit control will be created and accessed using this member.
public:
	CEdit m_edit;

Step 3: Create the edit control in OnInitDialog

Override the OnInitDialog() function and add the code to create the edit control to this function. It is a good idea to call the base class version of the function before doing anything specific for the derived class.

The property sheet is first resized to accommodate the new edit control. The edit control is then created at the desired location. The WS_EX_CLIENTEDGE gives it a 3-D look. The edit control is created with a different font than used by other control. We fix this by a call to SetFont() and set the font to be the same as the property sheet.

The text value in the edit control can be set or retrieved using the m_edit object.

BOOL CMyPropSheet::OnInitDialog()
{
	BOOL bResult = CPropertySheet::OnInitDialog();

	CRect rectWnd;
	GetWindowRect(rectWnd);
	SetWindowPos(NULL, 0, 0,
		rectWnd.Width() + 100,
		rectWnd.Height(),
		SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	m_edit.CreateEx( WS_EX_CLIENTEDGE, _T("EDIT"), NULL,
				WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, 
				rectWnd.Width(), 20, 80, 24, m_hWnd, 0, 0 );

	m_edit.SetFont( GetFont() );
	
	CenterWindow();
	return bResult;
}