WIn32 SwitchToThisWindow、ShowWindow 和 SetActiveWindow

发布于 2024-08-22 14:54:45 字数 227 浏览 13 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤寂小茶 2024-08-29 14:54:45

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.

好倦 2024-08-29 14:54:45

激活父级后,您必须发送 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.

自找没趣 2024-08-29 14:54:45

您可以使用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 send ShowWindow(hWnd, SW_RESTORE) to restore the minimized window. Finally use SetForegroundWindow(hWnd) to bring the window to the front.

Here's some excellent VB6 by Karl Peterson that does it all for you.

梦魇绽荼蘼 2024-08-29 14:54:45

您可以使用我的答案中的一些代码: 将焦点切换到另一个应用程序的正确方法(在.NET中),只需将设置活动窗口声明更改为设置前景窗口函数,您也可以尝试为 ShowWindow 函数使用不同的枚举。

Visual Basic 6 定义

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

Visual Basic .NET 定义

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

C# 定义

[DllImport("user32.dll")] public static extern int SetForegroundWindow(int hwnd)  

如果您的目标不是使用 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

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

Visual Basic .NET definition

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

C# definition

[DllImport("user32.dll")] public static extern int SetForegroundWindow(int hwnd)  

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文