How To Create a Modeless CPropertySheet with Standard Buttons

本文介绍如何在模式对话框CPropertySheet中实现标准的OK、Cancel和Apply按钮功能。通过继承CPropertySheet并覆盖OnInitDialog函数,可以阻止Microsoft Foundation Classes (MFC)隐藏这些按钮。文中提供了一个示例代码,展示了如何使这些按钮在点击时不关闭属性页,而是发送相应的消息。

How To Create a Modeless CPropertySheet with Standard Buttons

This article was previously published under Q146916

This article describes how to implement the standard OK, Cancel, and Apply buttons in a modeless
CPropertySheet object.

For a modeless CPropertySheet, the Microsoft Foundation Classes (MFC) resize the sheet and hide the standard
buttons in the CPropertySheet::OnInitDialog member function. To prevent MFC from doing this, perform the
following steps: ? Derive a class from CPropertySheet and override the OnInitDialog function.
 Set "m_bModeless" to FALSE and remove the WF_CONTINUEMODAL style for "m_nFlags".
 Call CPropertySheet::OnInitDialog.
 Set "m_bModeless" back to TRUE and add the style WF_CONTINUEMODAL to "m_nFlags".
The following sample code illustrates this technique: // CMySheet is derived from CpropertySheet.
// Compile options needed: default.

BOOL CMySheet::OnInitDialog()
{
   m_bModeless = FALSE;
   m_nFlags |= WF_CONTINUEMODAL;

   BOOL bResult = CPropertySheet::OnInitDialog();

   m_bModeless = TRUE;
   m_nFlags &= ~WF_CONTINUEMODAL;
   return bResult;
}

In a modeless CPropertySheet object, the OK and Cancel buttons do not close the property sheet when they are
clicked. They do send a WM_COMMAND message with IDOK or IDCANCEL to the sheet, and the OnOK or OnCancel
functions are called for the page. To close the sheet, you can implement ON_COMMAND handlers for IDOK and
IDCANCEL in the CPropertySheet and call the EndDialog function to close the sheet.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值