I have a window handle and am trying to call GetGUIThreadInfo by passing in the window's process id. I am always getting an error "Parameter incorrect" on the call to GetGUIThreadInfo and I can figure out why. Has anyone got this to work?
[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
}