WIn32 SwitchToThisWindow、ShowWindow 和 SetActiveWindow
我有一个 VB 6 MDI 应用程序。它响应已弃用的 SwitchToThisWindow 函数,但不响应 ShowWindow 和 SetActiveWindow 函数。我知道 ShowWindow 和 SetActiveWindow 已正确声明,因为我可以将它们与任何其他应用程序一起使用。
编辑:我的目标不是使用这些函数,将焦点从我的应用程序切换到 VB 6 应用程序很简单。因此,如果您有任何替代方法,我会洗耳恭听。
I have a VB 6 MDI application. It responds to the deprecated SwitchToThisWindow function, but not the ShowWindow and SetActiveWindow functions. I know ShowWindow and SetActiveWindow are declared correctly because I can use them with any other application.
EDIT: My goal isn't to use these functions, it is simple to switch the focus from my application to the VB 6 application. So if you have any alternative methods I'm all ears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
SetActiveWindow
仅适用于附加到当前线程的窗口,因此您不能使用它来激活另一个应用程序。您可以使用 将另一个应用程序的窗口置于前台
SetForegroundWindow
。仅当您的应用程序当前位于前台时,这才有效,但从您的问题来看,情况似乎确实如此。SetActiveWindow
will only work with windows that are attached to the current thread, so you can't use it to activate another application.You can bring a window from another application to the foreground with
SetForegroundWindow
. This will only work if your application is currently in the foreground, but from your question it seems like this is the case.激活父级后,您必须发送 WM_MDIACTIVATE消息来激活特定的MDI子窗口。掌握 MDI 子窗口句柄应该具有挑战性。
After activating the parent, you would have to send the WM_MDIACTIVATE message to activate a particular MDI child window. Getting your hands on the MDI child window handles ought to be challenging.
您可以使用
IsIconic(hWnd)
检测窗口是否最小化,然后发送ShowWindow(hWnd, SW_RESTORE)
恢复最小化窗口。最后使用SetForegroundWindow(hWnd)
将窗口置于最前面。这里有一些由 Karl Peterson 编写的优秀的 VB6,它可以为您完成这一切。
You can detect whether a window is minimized by using
IsIconic(hWnd)
, and then sendShowWindow(hWnd, SW_RESTORE)
to restore the minimized window. Finally useSetForegroundWindow(hWnd)
to bring the window to the front.Here's some excellent VB6 by Karl Peterson that does it all for you.
您可以使用我的答案中的一些代码: 将焦点切换到另一个应用程序的正确方法(在.NET中),只需将设置活动窗口声明更改为设置前景窗口函数,您也可以尝试为 ShowWindow 函数使用不同的枚举。
Visual Basic 6 定义
Visual Basic .NET 定义
C# 定义
如果您的目标不是使用 user32.dll 导入,那么您就完蛋了,因为您的应用程序无法访问目标应用程序,为了使其成为焦点,您将需要使用窗口。
或者您可以使用某种进程间通信系统(关键词:.net 远程处理)并将焦点代码片段编码到目标应用程序中,然后从您的应用程序将焦点消息发送到您的第二个应用程序
You can use some of the code from my answer here: Correct way (in .NET) to switch the focus to another application, just change the set active window declaration to the set foreground window function, you can also try using different enums for the ShowWindow function.
Visual Basic 6 definition
Visual Basic .NET definition
C# definition
If your goal isnt to use the user32.dll imports, then your pretty much screwed, because as your application has no access to the target application in order to bring it into focus you will need to use windows.
ALTERNATIVELY you can use some sort of inter process communication system (key words: .net remoting) and code the focus snippet into the target applciation, and then from your application just send the focus message to your second app