C# 启动进程后获取窗口句柄
有没有办法在使用 Process.Start() 从 C# 应用程序启动窗口后获取窗口的窗口句柄 (IntPtr)?
Is there a way to get the window handle (IntPtr) for a window after its launched from a C# app with Process.Start()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您要的是主窗口,
Process.MainWindowHandle
将为您提供所需的内容。If it's the main window you're after,
Process.MainWindowHandle
will give you what you need.启动应用程序时, Use
It 可能为 0,因此您可能需要循环并休眠,直到它被填满。
Use
It probably is 0 when launching the app, so you might want to loop and sleep until it is filled up.
这不是最近的话题,但答案并不完整。
我同意 Process.MainWindowHandle 解决方案并等待该值,但不同意 Sleep。
Process.WaitForInputIdle
This is not a recent topic but the answers are incomplete.
I agree with the Process.MainWindowHandle solution and to wait for the value but not with Sleep.
Process.WaitForInputIdle
您还可以在流程中调用 Refresh() 以确保信息准确
You could also call Refresh() on the process to be sure the info in accurate