示例#1
0
        private static IntPtr GetFocusedHandle()
        {
            var info = new GuiThreadInfo();

            info.cbSize = Marshal.SizeOf(info);
            if (!GetGUIThreadInfo(0, ref info))
            {
                throw new Win32Exception();
            }
            return(info.hwndFocus);
        }
示例#2
0
    static IntPtr GetFocusedHandle()
    {
        var info = new GuiThreadInfo();

        info.cbSize = Marshal.SizeOf(info);
        if (!GetGUIThreadInfo(0, ref info))
        {
            return(IntPtr.Zero);
        }
        return(info.hwndFocus);
    }
示例#3
0
        public static GuiThreadInfo?GetGUIThreadInfo(uint idThread)
        {
            var info = new GuiThreadInfo();

            info.cbSize = Marshal.SizeOf(info);
            if (!GetGUIThreadInfo(0, ref info))
            {
                return(null);
            }

            return(info);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 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;
 }
示例#10
0
 public static extern bool GetGUIThreadInfo(uint hTreadID, ref GuiThreadInfo lpgui);
示例#11
0
 private static extern bool GetGUIThreadInfo(uint _idThread, ref GuiThreadInfo _threadInfo);