Process.GetCurrentProcess()。MainWindowHandle返回零 [英] Process.GetCurrentProcess().MainWindowHandle returns zero

查看:1610
本文介绍了Process.GetCurrentProcess()。MainWindowHandle返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的C#应用​​程序的主要形式的窗口句柄(HWND)(应用程序只有1个表格)。

I'm trying to get the window handle (HWND) of the main form of my C# application (the application has only 1 form).

在互联网上的节目,我可以使用一些解决方案:

Some solutions on the internet show that I can use:

Process.GetCurrentProcess().MainWindowHandle

让我的应用程序的当前进程的窗口句柄。但是,此值始终为零,什么错吗?

to get the window handle of current process of my application. But this value is always zero, anything wrong?

推荐答案

MSDN说:

主窗口是打开由当前具有焦点(顶层表单)过程中的窗口。您必须使用Refresh方法刷新Process对象获取当前主窗口的句柄,如果它已经改变了。

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.

一个过程具有与其关联仅当过程具有图形界面的主窗口。如果相关联的进程不具有一个主窗口中,MainWindowHandle值为零。值也对于已经被隐藏,也就是工艺,不在任务栏可见过程为零。这对于显示为在通知区域中的图标,在最右侧的任务栏的处理的情况。

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.

请参阅<一href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx

这篇关于Process.GetCurrentProcess()。MainWindowHandle返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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