Restoring a window after waiting for a process to exit in VB6

拥有回忆 提交于 2019-12-22 11:11:41

问题


I am using VB6 in win7 64bit OS. This application is migrated from xp..

Me.WindowState = vbMinimized
WaitForProcess Shell(launchapp, vbNormalFocus)
Me.WindowState = vbNormal

Before launching the launchapp, my code minimizes the main application and will launch an exe. Once the exe is closed by the user, my main application has to come back from minimized state to normal. This works fine in xp, but in win 7 my main app which is minimized just flashes and goes back to minimized state again.

Any ideas?

Thanks.


回答1:


Windows 7 will not allow apps to grab the focus using SetForegroundWindow, as explained in the documentation. See the remarks.

One workaround is to temporarily AttachThreadInput to the thread that does have the focus, give yourself the focus, and then detach again. Karl E Peterson provides a drop-in module to do this here with accompanying magazine article.

Disclaimer: Windows guru Raymond Chen points out that this workaround can cause your program to stop responding in some circumstances. However I've never encountered these bugs myself. YMMV.




回答2:


We are using Win32 API function SetForegroundWindow to solve similar problems (some windows, esp out-of-process ones, will remain behind our main application window on W7).

Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

This is API declaration, search google for usage. Some info here: VBA interaction with Internet Explorer. If you need to control windows in different process, you need another API - AllowSetForegroundWindow - too.



来源:https://stackoverflow.com/questions/12576821/restoring-a-window-after-waiting-for-a-process-to-exit-in-vb6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!