2
我有一个窗口句柄,并试图通过传入窗口的进程ID来调用GetGUIThreadInfo。我在GetGUIThreadInfo调用中总是收到错误“参数不正确”,我可以找出原因。有没有人得到这个工作?如何在c中调用GetGUIThreadInfo#
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetGUIThreadInfo(unit hTreadID, ref GUITHREADINFO lpgui);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(unit hwnd, out uint lpdwProcessId);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int iLeft;
public int iTop;
public int iRight;
public int iBottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct GUITHREADINFO
{
public int cbSize;
public int flags;
public IntPtr hwndActive;
public IntPtr hwndFocus;
public IntPtr hwndCapture;
public IntPtr hwndMenuOwner;
public IntPtr hwndMoveSize;
public IntPtr hwndCaret;
public RECT rectCaret;
}
public static bool GetInfo(unit hwnd, out GUITHREADINFO lpgui)
{
uint lpdwProcessId;
GetWindowThreadProcessId(hwnd, out lpdwProcessId);
lpgui = new GUITHREADINFO();
lpgui.cbSize = Marshal.SizeOf(lpgui);
return GetGUIThreadInfo(lpdwProcessId, ref lpgui); //<!- error here, returns false
}
感谢发现!现在事实证明,GetGUIThreadInfo不会为不同的进程中的窗口返回任何内容。嗯... – Jeremy 2010-06-18 21:57:57