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


  • How to add Combo Box To the property sheet ?

    Posted by babumohan on 10/10/2004 05:17am

    I tried to add a combo box to the property sheet like the button in your program. I can see the Combo Box . But I cannot be able to drop down the list of items of Combo Box.
    Lemme know how to fix the issue?
    With regards

    • Add Combobox

      Posted by Jeremy Davis on 10/12/2004 05:42am

      When creating the combobox have you specified the expanded size? When displayed, the combobox will appear closed, but you must create it as if it were expanded. Look at for more help as it's much better than codeguru!

  • Is it possible to locate the button at other place in Propertysheet dialog??

    Posted by Legacy on 04/09/2002 12:00am

    Originally posted by: Santosh

    In this sample, the button is added by taking tabcontrol's
    x and y co-ordinates.

    Is it possible to add it any where in the dialog??

  • Can it work in a modalless propertysheet

    Posted by Legacy on 03/30/2002 12:00am

    Originally posted by: hjzhai

    I read your work,it's great.And I tried to add a button to a modalless propertysheet,but failed.Would you like to give me some advice?
    Thanks in advance!

  • how to add menu to a property sheet

    Posted by Legacy on 03/10/2002 12:00am

    Originally posted by: Gunjan Goel


    can u tell me how to add a menu to a property sheet/property page.
    it cld beadded to a dialog if the style was popup...
    as soon as i made it Child the menu addition option became disabled.

    pls. help

  • How to add the button to the top of the sheet?

    Posted by Legacy on 02/08/2002 12:00am

    Originally posted by: sujith.s

    How can i add the button to the top of a modeless propertysheet?ie. above the property page.

  • I have a solution to my previous Q.!!!!

    Posted by Legacy on 04/09/2001 12:00am

    Originally posted by: Ohad Redlish

    contact me if u r interested:
    and i will show you how to make the unvisible-buttons visible. since in Modeless style, the buttons are invisible, you have to FORCE the system show them.

  • propertySheet and buttons

    Posted by Legacy on 12/14/2000 12:00am

    Originally posted by: Ohad

    i read your advices. i think it's very nice, but how do i make the buttons in a PropertySheet visible, when the sheet is in Modeless style???
    this is much much tougher!!!

    please advise if you know anything
    Ohad R
    SW engineer
    NICE Systems

  • Help me on button in propertysheet

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

    Originally posted by: Hanying chen

    Hi, everyone

    I just used this code. But the button can't work at all. I examed the code carefully, still don't know why. The only difference is my propertysheet is a modeless dialog.
    Is it the reason?


    Hanying Chen

  • Here's a little routine to set tab order of buttons...

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

    Originally posted by: Chris Conn

    BOOL SetTabOrder(BOOL bShowWindow, HWND hWndTop, ...)
    ASSERT(hWndTop != NULL);
    bRtrn = FALSE;
    uiFlags = SWP_NOMOVE | SWP_NOSIZE;

    // Validate that something was sent in
    if (hWndTop != NULL)
    curHwnd = hWndTop,
    prevHwnd = HWND_TOP;

    // Add the show windows if needed
    if (bShowWindow == TRUE)
    uiFlags |= SWP_SHOWWINDOW;

    va_list curArg;
    va_start(curArg, curHwnd );
    // Initialize variable arguments

    // Additional parameters can be optional
    while (curHwnd != NULL)
    // Now add any additional windows into the tab order
    bRtrn = ::SetWindowPos(curHwnd, prevHwnd, 0, 0, 0, 0, uiFlags);

    // Keep track of the last windows handle
    prevHwnd = curHwnd;

    // Get the next argument
    curHwnd = va_arg(curArg, HWND);
    } // while (lpTmp != NULL)

    va_end(curArg); // Reset variable arguments
    } // End of check whether handle is valid

    return bRtrn;
    } // SetTabOrder()

    I've used this successfully for several property sheets that I am currently using (and also dynamically changing by adding additional buttons or other controls). Here's the mechanism that I use to call this function:

    SetTabOrder(TRUE, oNewButton1.GetSafeHwnd(),
    ::GetDlgItem(this->GetSafeHwnd(), IDOK),
    ::GetDlgItem(this->GetSafeHwnd(), IDCANCEL),
    ::GetDlgItem(this->GetSafeHwnd(), ID_APPLY_NOW),
    ::GetDlgItem(this->GetSafeHwnd(), IDHELP),

  • What about Tab order?

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

    Originally posted by: Bill Foust

    Thats a really nice bit of work there. It helped out a lot.

    The one problem I see now is the tab order. It would be nice to be able to tab through the fields of the property page, then to the new button, then to OK, Cancel etc. Right now, you get the page then OK, Cancel, Tabs, and then the new button.

    Also quick note, do the stuff in OnInitDialog as described AFTER calling the base class OnInitDialog. :) That was the first mistake I made. :)


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

Top White Papers and Webcasts

  • Improving data backup and recovery continues to be a top priority among senior IT decision makers, as highlighted in a 2015 IT Spending Intentions survey conducted by ESG. Organizations plan to invest in modernizing data protection, including the cloud. Learn the key considerations when evaluating a cloud-extended data protection solution that provides security, efficiency, effectiveness, and risk mitigation.

  • Today, users, applications, and data exist in more places than ever before, creating an unprecedented challenge for IT. How can IT achieve the flexibility and agility it needs to offer multiple types of applications in multiple locations? To better serve business demands for information everywhere, enterprises must develop new strategies for optimizing multiple kinds of networks. Read this white paper to learn how hybrid networks provide an unprecedented level of network dynamism, enterprise agility, and the …

Most Popular Programming Stories

More for Developers

RSS Feeds

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