我如何从启动它的进程中激活一个正在运行的进程的窗口? [英] How do I activate the window of one running process from the process which started it?

查看:224
本文介绍了我如何从启动它的进程中激活一个正在运行的进程的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始了一个过程:

I have started a process:

dim myproc as new process
'' Some setup code for calling a third-party application
myproc.start



在程序的后面,我需要将myproc的主窗口设置为最顶层的活动窗口.

有什么建议?我无法修改第三方应用程序.

根据一个建议,我尝试了:



Later in the program, I need to make the main window of myproc the topmost, active window.

Any suggestions? I cannot modify the third-party application.

Per one suggestion, I tried:

'' Activate and bring to the top an existing window.
Dim winPtr As IntPtr

winPtr = myproc.MainWindowHandle
WinAPI.SendMessage(winPtr, WinAPI.WndMsg.WM_SETFOCUS, CType(1, IntPtr), CType(0, IntPtr))



但这不起作用.



but this did not work.

推荐答案

您需要获取其他应用程序窗口的句柄,并向该窗口发送WM_FOCUS 消息.

如果您自己启动了该应用程序,则可以通过操纵用于启动该应用程序的Process对象来获取窗口句柄.
You need to get the handle to the other applications window, and send that window a WM_FOCUS message.

If you launched the app yourself, you could get the window handle by way of manipulating the Process object you used to launch the application.


该过程变量必须定义如下:

The process variable must be defined as follows:

Private Shared WithEvents myProcess As Process = Nothing



然后,您可以捕获Exited事件.效果很好.



Then you can catch the Exited event. This works beautifully.


这篇关于我如何从启动它的进程中激活一个正在运行的进程的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆