gpt4 book ai didi

c# - Process.GetCurrentProcess().MainWindowHandle 返回零

转载 作者:可可西里 更新时间:2023-11-01 13:50:18 24 4
gpt4 key购买 nike

我正在尝试获取我的 C# 应用程序主窗体的窗口句柄 (HWND)(该应用程序只有 1 个窗体)。

互联网上的一些解决方案表明我可以使用:

Process.GetCurrentProcess().MainWindowHandle

获取我的应用程序当前进程的窗口句柄。但是这个值始终为零,有什么问题吗?

最佳答案

MSDN 说:

The main window is the window opened by the process that currently has the focus (the TopLevel form). You must use the Refresh method to refresh the Process object to get the current main window handle if it has changed.

A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, the MainWindowHandle value is zero. The value is also zero for processes that have been hidden, that is, processes that are not visible in the taskbar. This can be the case for processes that appear as icons in the notification area, at the far right of the taskbar.

参见 http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx

关于c# - Process.GetCurrentProcess().MainWindowHandle 返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20370631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com