简体   繁体   English

有时 ShowWindow 从不调用 OnShowWindow 并且主应用程序挂起

[英]Sometimes ShowWindow never calls OnShowWindow and main App hangs

I have a multi-threaded application with several supporting DLLs and several popup dialogs.我有一个带有多个支持 DLL 和几个弹出对话框的多线程应用程序。 My Main App loads all DLLs on startup, which creates all popups, but they are kept hidden until needed.我的主应用程序在启动时加载所有 DLL,这会创建所有弹出窗口,但在需要时它们会一直隐藏。

When the user presses a button in the main app, a particular popup is shown (from the DLL) by calling ShowWindow( SW_SHOW ) (modeless)当用户在主应用程序中按下一个按钮时,通过调用 ShowWindow( SW_SHOW ) (无模式)显示一个特定的弹出窗口(来自 DLL)

Sometimes (1-in-10 times?) the popup simply fails to show and the Main App hangs.有时(十分之一?)弹出窗口根本无法显示并且主应用程序挂起。 OnShowWindow of the Popup dialog is never called.弹出对话框的 OnShowWindow 永远不会被调用。 I have tried calling ShowWindowASync instead, and it still fails to show the popup sometimes, but this call doesn't lock the Main App.我曾尝试调用 ShowWindowASync,但有时仍无法显示弹出窗口,但此调用不会锁定主应用程序。

This problem only affects popups within a single DLL.此问题仅影响单个 DLL 内的弹出窗口。

If the popup shows the first time ShowWindow is called, it can be closed and re-opened indefinitely throughout the lifetime of the Main App.如果弹出窗口显示第一次调用 ShowWindow 时,它可以在主应用程序的整个生命周期内无限期地关闭和重新打开。 If (using ShowWindowASync), the popup fails to show, it will never show during the lifetime of the Main App.如果(使用 ShowWindowASync)弹出窗口无法显示,则在主应用程序的生命周期内将永远不会显示。 I can re-run the application (without rebuilding anything) and there is a hit-or-miss chance that it will work or fail.我可以重新运行该应用程序(无需重建任何东西),它可能会工作或失败。 I haven't been able to identify any predictive conditions or properties.我无法识别任何预测条件或属性。

I have used tools to renumber all of my resource elements so that there are no conflicts throughout the solution.我已使用工具对所有资源元素重新编号,以便在整个解决方案中不存在冲突。

UPDATE:更新:

I used Winspector to get some information about the dialog when it does and does not work.我使用 Winspector 来获取有关对话框何时起作用和不起作用的一些信息。

When the dialog works (shows properly), Winspector reports that my dialog has valid position (10,96, 1015, 514), style attributes that match the resource template, ID of 0 (not sure what ID means), and the "Owner EXE" is "MyApp.exe" - I can see many messages passing in and out of the dialog, including WM_SHOWWINDOW.当对话框工作(正确显示)时,Winspector 报告我的对话框具有有效的 position(10,96,1015,514),与资源模板匹配的样式属性,ID 为 0(不确定 ID 的含义)和“所有者EXE”是“MyApp.exe”——我可以看到许多消息传入和传出对话框,包括 WM_SHOWWINDOW。

When the dialog fails (does not get a show window message), Winspector reports position (-1512, 190, -517, 634), style attributes that do not match the resource template, ID 509290824, and owner EXE is "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" - I also do not see ANY messages in the message viewer within Winspector when the dialog fails to show.对话框失败时(没有得到显示 window 消息),Winspector 报告 position (-1512, 190, -517, 634),样式属性与资源模板不匹配,ID 509290824,所有者 EXE 为“C:\ Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" - 当对话框无法显示时,我在 Winspector 的消息查看器中也看不到任何消息。

Clearly, the dialog is not getting created correctly.显然,对话框没有正确创建。 CDialog::Create never fails for me. CDialog::Create 对我来说永远不会失败。 Additionally, I experience this problem in release (not using Visual Studio) so it's not a VS-specific problem.此外,我在发布时遇到了这个问题(不使用 Visual Studio),所以这不是 VS 特定的问题。

The dialog was getting created from a thread that was not executing a message pump.该对话框是从未执行消息泵的线程创建的。 This was the root problem.这是根本问题。 I had tried to initialize all dialogs (ie call "Create") from an "init" thread, and then use them later on in the winproc/GUI thread.我曾尝试从“init”线程初始化所有对话框(即调用“Create”),然后稍后在 winproc/GUI 线程中使用它们。 Can't do this apparently.显然不能这样做。

A pointer to the dialog was then retrieved into the winproc/GUI (which has a message pump), but by that time, the dialog was already "corrupt" and no longer responding to winproc properly然后将指向对话框的指针检索到 winproc/GUI(具有消息泵)中,但到那时,对话框已经“损坏”并且不再正确响应 winproc

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

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