C#:FindWindowEx 未按预期工作
C#: FindWindowEx not working as anticipated
好的,首先我是 C# 的新手,所以这可能真的很简单,我一直没有找到答案 Google/SO。
我有一个 class,我正在尝试使用 FindWindowEx,但是,Visual Studio 不允许我使用 'null' 参数,我不确定为什么。
到目前为止 class 有这个代码:
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr handleParent, IntPtr handleChild, string className, string WindowName);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public void SomeWindow()
{
String someHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", NULL);
}
正如所写,它告诉我 'NULL' 在当前上下文中不存在。我也试过写成:
FindWindowEx(null, null, "SomeWindowClass", null)
这会在前两个 'null' 下给出错误,说 "Argument #: Cannot convert from 'null' to 'IntPtr'"('null' 实际上有 < 和 > 包围它,尽管 SO 没有显示它们)
Windows 开发中心说我应该可以按原样使用它,尽管它在这里:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx
正如我所说,这可能非常简单,我只是没有足够的 C# 经验来弄明白。
FindWindow return 类型是 IntPtr,而您正试图将其分配给字符串。
试试这个。
IntPtr wnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", null);
好的,首先我是 C# 的新手,所以这可能真的很简单,我一直没有找到答案 Google/SO。
我有一个 class,我正在尝试使用 FindWindowEx,但是,Visual Studio 不允许我使用 'null' 参数,我不确定为什么。
到目前为止 class 有这个代码:
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr handleParent, IntPtr handleChild, string className, string WindowName);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public void SomeWindow()
{
String someHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", NULL);
}
正如所写,它告诉我 'NULL' 在当前上下文中不存在。我也试过写成:
FindWindowEx(null, null, "SomeWindowClass", null)
这会在前两个 'null' 下给出错误,说 "Argument #: Cannot convert from 'null' to 'IntPtr'"('null' 实际上有 < 和 > 包围它,尽管 SO 没有显示它们)
Windows 开发中心说我应该可以按原样使用它,尽管它在这里: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx
正如我所说,这可能非常简单,我只是没有足够的 C# 经验来弄明白。
FindWindow return 类型是 IntPtr,而您正试图将其分配给字符串。
试试这个。
IntPtr wnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", null);