简体   繁体   English

如何调试MFC中不断丢失的焦点窗口(例如,对话框)?

[英]How can I debug a constantly losing focus window (dialog, for instance) in MFC?

I am maintaining I big and mature application, without background on MFC paradigm and layout. 我正在维护我庞大而成熟的应用程序,没有MFC范例和布局的背景。 I have experience with Qt, OO designs and UI frameworks (I'm aware of each thread responsibility, event loops, event handling hierarchies, etc. 我有Qt,OO设计和UI框架的经验(我知道每个线程的职责,事件循环,事件处理层次结构等。

I'm stuck with a settings CDialog window losing focus constantly, while I'm trying to configure my application. 当我尝试配置应用程序时,我一直在使用设置CDialog窗口不断失去焦点。 I also have a file explorer dialog that behaves exactly the same way. 我还有一个文件浏览器对话框,其行为方式完全相同。 Both are activated by DoModal calls. 两者都通过DoModal调用激活。

I've read that this is probably because I have two modal dialogs competing for focus. 我读到这可能是因为我有两个模态对话框争夺焦点。 How can I debug that? 我该如何调试? What function could I break on to get a helpful callstack, so I can find the offending code? 我可以使用什么函数来获得有用的调用栈,以便找到有问题的代码? Is there an MFC::focusWindow(WHND window) or something that I could intercept? 是否有MFC::focusWindow(WHND window)或我可以拦截的东西?

使用Spy ++监视对话框中发生的消息/事件。

The problem according to your description is that you 'have two modal dialogs competing for focus'. 根据您的描述,问题在于您“有两个模态对话框争夺焦点”。 This should normally not be possible because by definition a modal dialog takes over the application and does not return control to its launch point until the dialog is closed. 通常这是不可能的,因为根据定义,模态对话框将接管应用程序,并且直到对话框关闭后才将控制权返回到其启动点。 Without knowing the architecture of the application, the simplest solution would be to make the settings dialog modeless (create it then call ShowWindow(SW_SHOW) instead of DoModal. This will allow the message loop to run for the other modal dialog but not take focus from your settings dialog unless it is doing it explicitly in its own methods. 在不了解应用程序体系结构的情况下,最简单的解决方案是使设置对话框变为无模式(创建它,然后调用ShowWindow(SW_SHOW)而不是DoModal。这将允许消息循环针对其他模式对话框运行,但不能从中获取焦点您的设置对话框,除非它是在其自己的方法中明确进行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM