在 MFC 中检测模态对话框 [英] Detecting modal dialogs in MFC

查看:17
本文介绍了在 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 ChenGetLastActivePopup 应该返回当前活动的模态对话框.

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 中检测模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆