private static IntPtr GetFocusedHandle() { var info = new GuiThreadInfo(); info.cbSize = Marshal.SizeOf(info); if (!GetGUIThreadInfo(0, ref info)) { throw new Win32Exception(); } return(info.hwndFocus); }
static IntPtr GetFocusedHandle() { var info = new GuiThreadInfo(); info.cbSize = Marshal.SizeOf(info); if (!GetGUIThreadInfo(0, ref info)) { return(IntPtr.Zero); } return(info.hwndFocus); }
public static GuiThreadInfo?GetGUIThreadInfo(uint idThread) { var info = new GuiThreadInfo(); info.cbSize = Marshal.SizeOf(info); if (!GetGUIThreadInfo(0, ref info)) { return(null); } return(info); }
private static IntPtr GetFocusedHandle() { var info = new GuiThreadInfo(); info.cbSize = Marshal.SizeOf(info); if (!GetGUIThreadInfo(0, ref info)) { throw new InvalidOperationException("Failed to get thread info"); } return(info.hwndFocus); }
private static IntPtr GetMainThreadActiveWindow(IntPtr activeWindowHandle) { var windowThreadProcessId = NativeMethods.NativeMethods.GetWindowThreadProcessId(activeWindowHandle, out _); var threadInfo = new GuiThreadInfo { CbSize = Marshal.SizeOf(typeof(GuiThreadInfo)) }; if (windowThreadProcessId != 0U && NativeMethods.NativeMethods.GetGUIThreadInfo(windowThreadProcessId, out threadInfo)) { return(threadInfo.HwndActive); } return(IntPtr.Zero); }
private IntPtr GetFocusWindow() { IntPtr hWnd = GetForegroundWindow(); IntPtr handle; if (hWnd == this.Handle) { handle = this.ActiveControl.Handle; } else { uint threadId = GetWindowThreadProcessId(hWnd, IntPtr.Zero); GuiThreadInfo gti = new GuiThreadInfo(); gti.cbSize = Marshal.SizeOf(gti); bool GUIinfo = GetGUIThreadInfo(threadId, ref gti); handle = gti.hwndFocus; } return(handle); }
internal static extern bool GetGUIThreadInfo(uint idThread, ref GuiThreadInfo lpgui);
private static extern uint GetGUIThreadInfo(int threadId, ref GuiThreadInfo info);
private static IntPtr GetPrimaryWindowHandle() { IntPtr primaryWindow = IntPtr.Zero; GuiThreadInfo info = new GuiThreadInfo(); info.cbSize = Marshal.SizeOf(info); // Find the current active window. if (GetGUIThreadInfo(0, ref info) != 0 && info.hwndActive != IntPtr.Zero) { int processId; // Find the process for that window. GetWindowThreadProcessId(info.hwndActive, out processId); // Make sure the current active window belongs to our process. if (processId == Process.GetCurrentProcess().Id) { primaryWindow = info.hwndActive; } } return primaryWindow; }
public static extern bool GetGUIThreadInfo(uint hTreadID, ref GuiThreadInfo lpgui);
private static extern bool GetGUIThreadInfo(uint _idThread, ref GuiThreadInfo _threadInfo);