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


  • Mr

    Posted by psingh on 02/17/2016 06:19am

    create your own button in a modeless property sheet:- GetWindowRect(&rect); SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height() + 33, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); Btn_OK.Create(_T("Ok"), BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, CRect(6, rect.Height() - 30, 80, rect.Height() - 10), this, IDC_OTHER_OUT_OK); CWnd* Btn = GetDlgItem(IDC_OTHER_OUT_OK); ASSERT(Btn); Btn-ShowWindow(SW_SHOW); Btn-EnableWindow(TRUE);

  • 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),

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • The open source cloud computing project OpenStack has come a long way since NASA and Rackspace launched it in 2010. Backed by leading technology infrastructure providers including Cisco, Dell, EMC, HP, IBM, Intel, and VMware, OpenStack underpins significant workloads at an increasingly diverse set of organizations, including BWM, CERN, Comcast, eBay, and Wal-Mart. For CIOs engaged in broader programs to win, serve, and retain customers -- and refocus business technology (BT) spend -- a planned and pragmatic …

  • Protect Your Business against Today's Rapidly Growing Threats Your business, employees, partners, and customers are depending more and more on network connectivity, and protecting data and infrastructure has moved to the top of the IT agenda. You can't arm yourself against today's rapidly increasing threats unless you understand how they work. Read this ebook to learn more about the top 10 DNS attacks that can target your external and internal DNS infrastructure, the impact they can have on the DNS server …

Most Popular Programming Stories

More for Developers

RSS Feeds

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