HOWTO: How to Change Default Button on CPropertySheet

Article translations Article translations
Article ID: 140587 - View products that this article applies to.
This article was previously published under Q140587
Expand all | Collapse all

On This Page


When a modal CPropertySheet is created, the default button is the OK button. To change the default to a different button, derive a class from CPropertySheet, override OnInitDialog(), and send a message of DM_SETDEFID to the sheet with the ID of the new button.


The IDs of the buttons that are created in a modal CPropertySheet are:
   IDOK            - OK button
   IDCANCEL        - Cancel button
   ID_APPLY_NOW    - Apply button
   IDHELP          - Help button
Before you can set the focus to a button, the button must exist and be enabled. By default, the Apply button on a modal CPropertySheet is not enabled; it has to be explicitly enabled as shown in the sample code in this article.

If you want a button other than these default buttons to have the default focus, you have to create the button, say IDC_MYBUTTON, and set focus to that button using:

Sample Code

// This code sets the Apply button as the default
// CMySheet is derived from CPropertySheet

BOOL CMySheet::OnInitDialog()

        // Enable the Apply button
        GetPage(0)->SetModified ();
        // Set the Apply button as the default button
        SendMessage (DM_SETDEFID, ID_APPLY_NOW);

        return TRUE;


Article ID: 140587 - Last Review: November 21, 2006 - Revision: 2.1
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 4.0 Standard Edition
kbhowto kbpropsheet kbuidesign KB140587
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from