获取流程的主窗口 [英] Getting the main window of a process
本文介绍了获取流程的主窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
如何使用C#获取进程的主窗口?
谢谢.
Hello,
How can I get the main window of a process using C#?
Thanks.
推荐答案
您从Process类开始获取所需的Process实例.然后,您可以使用它的MainWindowHandle属性获取应用程序启动表单的句柄.
You start with the Process class to get the Process instance you''re looking for. Then you can use it''s MainWindowHandle property to get the handle to the apps startup form.
[添加到Dave的答案中.]
您不能将Process.MainWindowHandle
返回的句柄与Form.FromHandle
之类的方法一起使用,因为该句柄尚未与应用程序中的Control
对象关联.与该窗口的任何交互都必须通过P/Invoking API,例如SetWindowText
.
[Adding to Dave''s answer.]
You cannot use the handle returned fromProcess.MainWindowHandle
with methods likeForm.FromHandle
because the handle is not already associated with aControl
object in your application. Any interaction with that window will have to be through P/Invoking APIs likeSetWindowText
.
这篇关于获取流程的主窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文