Adding a Button to CPropertySheet

Friday Mar 5th 1999 by Jeremy Davis

Adding a Button to CPropertySheet

In my app I use a CPropertySheet and CPropertyPages to display properties for individual days. If the user wanted all the weeks days to be Setup with the same properties, I wanted a way to copy an individual day's properties to all the other days of the week. The solution I came up with was to create a "Copy" button in the CPropertySheet rather than in each CPropertyPage as show in the picture below...


  • First sub-class CPropertySheet with a class of your own using ClassWizard, say CMyPropertySheet.
  • Next in your MyPropertySheet.h add a member function CButton m_ButtonCopy. Also in your resource.h add a #define IDC_BUTTON_COPY 0x02000. where 0x02000 is a resource ID that has not been used yet.
  • Then over-ride the CPropertySheet::OnInitDialog function and insert the following code...

CRect rect, tabrect;
int width;

//Get button sizes and positions

ScreenToClient(rect); ScreenToClient(tabrect);

//New button -> width, height and Y-coordiate of IDOK
// -> X-coordinate of tab control
width = rect.Width();
rect.left = tabrect.left; rect.right = tabrect.left + width;

//Create new "Add" button and set standard font


If your were to compile at this point you would now see the new Copy button in the CPropertySheet; however the button would not do anything. To handle a single button click added the following line to your message map declaration...

BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)
// NOTE - the ClassWizard will add and remove mapping macros here.

Lastly add a helper function called OnButtonCopy() and insert your code for when the button is clicked.

Download demo project - 17 KB

Download source - 2 KB

Date Last Updated: March 5, 1999

Mobile Site | Full Site