Detecting modal dialogs in MFC(在 MFC 中检测模态对话框)
问题描述
如何以编程方式检测我的 MFC 应用程序当前是否正在显示模式对话框或属性表?目前我正在使用以下,但我觉得代码也会触发无模式对话框.
How can I programmatically detect if my MFC application currently is displaying a modal dialog or property sheet? Currently I'm using the following, but I feel that the code also triggers for modeless dialogs.
bool HasModalDialog(const CWnd* pWnd)
{
const CWnd* pChildWnd = pWnd ? pWnd->GetNextWindow(GW_HWNDPREV) : NULL;
while (pChildWnd)
{
if (pWnd == pChildWnd->GetTopLevelParent() &&
(pChildWnd->IsKindOf(RUNTIME_CLASS(CDialog)) ||
pChildWnd->IsKindOf(RUNTIME_CLASS(CPropertySheet))))
{
return true;
}
pChildWnd = pChildWnd->GetNextWindow(GW_HWNDPREV);
}
return false;
}
用法:
HasModalDialog(AfxGetMainWnd())
谁有检测模态对话框的替代方法?
Anyone got a alternative way of detecting modal dialogs?
推荐答案
你试过了吗CWnd::GetLastActivePopup
?
我还没有测试过它是否只适用于模式对话框.
I haven't tested this to see if it'll work for modal dialogs only.
编辑 1: 根据 Raymond Chen,GetLastActivePopup
应该返回当前活动的模态对话框.
Edit 1: According to Raymond Chen, GetLastActivePopup
should return the current active modal dialog.
编辑 2: 检索当前模式窗口的另一种方法可能是修改代码以检查禁用的父/所有者 - 模式对话框应始终 在显示前禁用其所有者.
Edit 2: Perhaps another method to retrieve the current modal window would be to modify your code to check for a disabled parent/owner - modal dialogs should always disable their owner before displaying.
这篇关于在 MFC 中检测模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MFC 中检测模态对话框
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01