gpt4 book ai didi

visual-c++ - 有条件地阻止 CPropertySheet 从页面 OnOK 按钮处理程序关闭

转载 作者:行者123 更新时间:2023-12-04 09:38:14 29 4
gpt4 key购买 nike

我刚刚遇到了 CPropertyPage 的问题.

我一直在尝试使用 OnOK处理程序进行一些验证:

void CCalendarSettingsGooglePage::OnOK()
{
bool bHandle = false;

UpdateData(TRUE);

// AJT v20.2.0 — We need to pass "true" so that the error message will display!
if (ValidSettings(true))
{
bHandle = true;
SaveSettings();
}

if (bHandle)
CMFCPropertyPage::OnOK();
}

问题是,工作表仍然关闭。我曾希望防止 CMFCPropertyPage::OnOK会停止工作表关闭。但事实并非如此。

我从 here 了解到 OnOK正在制作 EndDialog(IDOK)称呼。但我不想让我的工作表复杂化。测试在此页面中。所以我需要让工作表知道当用户单击“确定”按钮时它是否应该关闭。

最佳答案

您需要覆盖 OnCommand 属性页的父属性表类的处理程序并拦截 IDOK 的点击命令(将在 wParam 参数中给出)。如果您 不要调用基类 OnCommand但仍然返回 TRUE表示您已处理该命令,则属性表将不会关闭:

BOOL MyPropertySheet::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (wParam == IDOK) { // OK button clicked...
if (!ValidSettings(true)) return TRUE; // NOT valid, prevent further processing.
}
// You can also intercept the "Apply" command by testing for ID_APPLY_NOW

// Everything is OK, so continue processing ...
return CMFCPropertySheet::OnCommand(wParam, lParam);
}

请注意,我假设您的父级源自 CMFCPropertySheet ,但同样适用于“较旧的” CPropertySheet .

关于visual-c++ - 有条件地阻止 CPropertySheet 从页面 OnOK 按钮处理程序关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446954/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com