HOWTO: Create a Modeless CPropertySheet With Standard Buttons

Last reviewed: January 5, 1998
Article ID: Q146916
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 5.0

SUMMARY

By default, a modeless CPropertySheet does not have any of the standard buttons that are in a modal CPropertySheet. These are the OK, Cancel, and Apply buttons. For a modeless CPropertySheet, MFC resizes the sheet and hides these buttons in CPropertySheet::OnInitDialog(). To prevent MFC from doing this, derive a class from CPropertySheet, override OnInitDialog(), and set "m_bModeless" to FALSE before CPropertySheet::OnInitDialog(). You should set "m_bModeless" back to TRUE after CPropertySheet::OnInitDialog().

MORE INFORMATION

Note that the standard buttons do not work the same way in a modeless CPropertySheet as they do in a modal one. Namely, the OK and Cancel buttons do not close the CPropertySheet when you click them. They will still send a WM_COMMAND message with IDOK or IDCANCEL to the sheet, and OnOK() or OnCancel() will still be called for the page. You can set up ON_COMMAND() handlers for IDOK and IDCANCEL in the CPropertySheet and call EndDialog() to close the sheet.

Sample Code

// CMySheet is derived from CPropertySheet
BOOL CMySheet::OnInitDialog() {
   m_bModeless = FALSE;
   BOOL bResult = CPropertySheet::OnInitDialog();
   m_bModeless = TRUE;
   return bResult;
}

/* Compile options needed: default
*/


Additional reference words: kbinf 4.00 modeless CPropertySheet buttons
property sheet propertysheet
Keywords : MfcUI kbcode
Technology : kbMFC
Version : WINNT:4.0,4.1,4.2,5.0
Platform : winnt
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.