首先,我是C#的新手,所以这可能是非常简单的事情,我只是在Google/SO中找不到答案。
我有一个试图使用FindWindowEx的类,然而,Visual Studio不允许我使用'null‘参数,我不确定为什么。
到目前为止,这个类有这样的代码:
[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‘错误:“参数#:无法从'null’转换为'IntPtr'”(‘null’实际上有<和>括起来,尽管它没有和它们一起显示)
Windows开发人员中心说我应该能够像现在这样使用它,它在这里:https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx
就像我说的,这可能是非常简单的事情,我只是在C#上没有足够的经验来解决它。
发布于 2018-01-20 16:33:37
字符串返回类型为IntPtr,而您正在尝试将其赋给FindWindow。
尝尝这个。
IntPtr wnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", null);
https://stackoverflow.com/questions/48358420
复制相似问题