C# 启动进程后获取窗口句柄

发布于 2024-08-04 06:05:51 字数 65 浏览 1 评论 0原文

有没有办法在使用 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 技术交流群。

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

发布评论

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

评论(4

请你别敷衍 2024-08-11 06:05:51

如果您要的是主窗口,Process.MainWindowHandle 将为您提供所需的内容。

If it's the main window you're after, Process.MainWindowHandle will give you what you need.

独闯女儿国 2024-08-11 06:05:51

启动应用程序时, Use

process.MainWindowHandle;

It 可能为 0,因此您可能需要循环并休眠,直到它被填满。

Use

process.MainWindowHandle;

It probably is 0 when launching the app, so you might want to loop and sleep until it is filled up.

帅哥哥的热头脑 2024-08-11 06:05:51

这不是最近的话题,但答案并不完整。

我同意 Process.MainWindowHandle 解决方案并等待该值,但不同意 Sleep。

如果您刚刚启动一个进程并想要使用其主窗口句柄,请考虑使用 WaitForInputIdle 方法来允许进程完成启动,确保主窗口句柄已创建。

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.

If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created.

Process.WaitForInputIdle

This overload applies only to processes with a user interface and, therefore, a message loop.

北方。的韩爷 2024-08-11 06:05:51

您还可以在流程中调用 Refresh() 以确保信息准确

You could also call Refresh() on the process to be sure the info in accurate

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