MFC 应用程序和非 MFC 模式对话框
我正在为第三方 MFC 应用程序编写 Win32 插件 DLL。 DLL 需要显示模式对话框。当我使用 DialogBox()
或其他普通 Win32 API 执行此操作时(例如,我尝试编写自己的模式循环),主应用程序的窗口不会重绘所有元素:它会重绘标准元素,但不会重绘客户区。无模式对话框显示得很好。
我怀疑发生这种情况是因为 MFC 实际上没有 Win32 意义上的模式对话框。它只能有一个消息循环,而 DialogBox()
中的单独循环会破坏其精密的机制。这是CodeProject 文章对此进行了解释。但这篇 CodeProject 文章已经有 9 年历史了,所以也许从那时起事情就发生了变化。有人可以解释一下吗?该应用程序使用 MFC 8(即 mfc80.dll
)。
更新。这是原始链接问题;它可能包含一些附加信息。
更新2。谢谢大家;我真的很感谢所有的建议,这确实帮助我全面了解事物如何组合在一起。我要探索的第一个途径是使用本机 MFC“模式”对话框。 (由于我是通过 Python 完成所有这些操作,因此我将使用 MFC 的 Python 绑定,pywin32
)。这需要一些时间;准备好后,我将用结果更新帖子。
I'm writing a Win32 plug-in DLL for a third-party MFC app. The DLL needs to display a modal dialog. When I do this using DialogBox()
or other plain Win32 API (e.g. I tried to write my own modal loop), the main application's window doesn't redraw all elements: it redraws standard elements, but not the client area. Modeless dialogs display just fine.
I suspect this happens because MFC doesn't really have modal dialogs in Win32 sense. It can only have one message loop and a separate loop in DialogBox()
disrupts its delicate machinery. Here's a CodeProject article that explains this. But this CodeProject article is 9 years old, so maybe things have changed since then. Could somebody shed some light on this? The app uses MFC 8 (i.e. mfc80.dll
).
Update. Here's a link to the original question; it may contain some additional information.
Update 2. Thanks everyone; I really appreciate all the advice, it certainly helps me to get the big picture of how things fit together. The first path I'm going to explore is to use native MFC 'modal' dialogs. (Since I do all this from Python, I'll use Python bindings for MFC, pywin32
). This will take some time; when it's ready, I'll update the post with results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个线程都可以有一个消息循环。将模式对话框放入单独的线程中,并通过禁用父窗口来模拟 Windows 的标准行为。
编辑:经过一些讨论(见下文),父代码的行为似乎不正确。
尽管如此,我认为还是有可能的解决方法。其中一个可能是父窗口(对于模式对话框,但对于当前行为不正确的窗口来说是子窗口),它覆盖了错误的窗口内容,但从内存中的 DC 重新绘制它以模仿正确的行为。当然,父窗口仍然必须被禁用。另一种解决方案可能是对父窗口进行子类化,以纠正行为。由于插件将在同一进程中运行,因此实现应该很简单。
Every thread can have a message loop. Put your modal dialog into a separate thread and emulate the standard behavior of Windows by disabling the parent window.
Edit: after some discussion (see below) it appears that the parent code behaves incorrectly.
Still, I think there are possible workarounds. One could be a parent window (to the modal dialog, but child to the one that currently behaves incorrectly) that overlays the erroneous window content, but redraws it from a DC in memory to mimic correct behavior. Of course the parent window still would have to be disabled. Another solution may be to subclass the parent window, to correct the behavior. Since the plugin would run within the same process, the implementation should be straightforward.