HOWTO: How to Change Default Button on CPropertySheet

This article was previously published under Q140587
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
When a modal CPropertySheet is created, the default button is the OKbutton. To change the default to a different button, derive a class fromCPropertySheet, override OnInitDialog(), and send a message of DM_SETDEFIDto the sheet with the ID of the new button.
MORE INFORMATION
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 beenabled. By default, the Apply button on a modal CPropertySheet is notenabled; it has to be explicitly enabled as shown in the sample code inthis article.

If you want a button other than these default buttons to have the defaultfocus, you have to create the button, say IDC_MYBUTTON, and set focusto that button using:
   SendMessage (DM_SETDEFID, IDC_MYBUTTON);				

Sample Code

// This code sets the Apply button as the default// CMySheet is derived from CPropertySheetBOOL CMySheet::OnInitDialog(){        CPropertySheet::OnInitDialog();        // Enable the Apply button        GetPage(0)->SetModified ();        // Set the Apply button as the default button        SendMessage (DM_SETDEFID, ID_APPLY_NOW);        return TRUE;}				
kbinf 4.00
Properties

Article ID: 140587 - Last Review: 12/04/2015 12:31:31 - Revision: 2.1

Microsoft Foundation Class Library 4.2

  • kbnosurvey kbarchive kbhowto kbpropsheet kbuidesign KB140587
Feedback