首先,我是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" ####################################################################到' IntPtr'" (' null'实际上有<和>围绕着它,虽然SO不会与它们一起显示)
Windows开发人员中心说我应该可以使用它,因为我在这里: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx
就像我说它可能非常简单,我只是没有足够的C#经验来解决它。
答案 0 :(得分:1)
FindWindow返回类型是IntPtr,而您尝试将其分配给字符串。
试试这个。
IntPtr wnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", null);