Adding a Control to the Property Sheet | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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;
}
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.