在 C# 中获取窗口句柄
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1402848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the handle of window in C#
提问by Joel Barsotti
I'm trying to do some P/Invoke stuff and need the handle of the current window.
我正在尝试做一些 P/Invoke 的事情并且需要当前窗口的句柄。
I found Getting the handle of window in C#
But it appears that only works in WPF. Is there a winForms equivalent?
但它似乎只适用于 WPF。是否有一个 winForms 等价物?
采纳答案by dtb
An
IntPtr
that contains the window handle (HWND) of the control.
一个
IntPtr
包含该控件的窗口句柄(HWND)。
回答by ZokiManas
Try this in your form:
在您的表单中尝试此操作:
IntPtr myHandle = this.Handle;
IntPtr myHandle = this.Handle;
It will return the handle of the form.
它将返回表单的句柄。