Exemplo n.º 1
0
        public static void ForceForegroundWindow(IntPtr hWnd)
        {
            uint windowThreadProcessId = ProgramThread.GetWindowThreadProcessId(ProgramThread.GetForegroundWindow(), IntPtr.Zero);

            uint currentThreadId = ProgramThread.GetCurrentThreadId();

            if (windowThreadProcessId != currentThreadId)
            {
                ProgramThread.AttachThreadInput(windowThreadProcessId, currentThreadId, true);
                ProgramThread.BringWindowToTop(hWnd);
                ProgramThread.ShowWindow(hWnd, ProgramThread.ShowWindowCommands.Show);
                ProgramThread.AttachThreadInput(windowThreadProcessId, currentThreadId, false);
            }
            else
            {
                ProgramThread.BringWindowToTop(hWnd);
                ProgramThread.ShowWindow(hWnd, ProgramThread.ShowWindowCommands.Show);
            }
        }
Exemplo n.º 2
0
        public static bool WindowHasMouseOver(Process process)
        {
            IntPtr mainWindowHandle = process.MainWindowHandle;
            bool   result;

            if (mainWindowHandle == IntPtr.Zero || process.HasExited)
            {
                result = false;
            }
            else if (ProgramThread.GetForegroundWindow() != mainWindowHandle)
            {
                result = false;
            }
            else
            {
                ProgramThread.WINDOWPLACEMENT wINDOWPLACEMENT = default(ProgramThread.WINDOWPLACEMENT);
                if (!ProgramThread.GetWindowPlacement(mainWindowHandle, ref wINDOWPLACEMENT))
                {
                    result = false;
                }
                else if (wINDOWPLACEMENT.showCmd != ProgramThread.ShowWindowCommands.Normal)
                {
                    result = false;
                }
                else
                {
                    ProgramThread.RECT rECT = default(ProgramThread.RECT);
                    if (!ProgramThread.GetWindowRect(mainWindowHandle, out rECT))
                    {
                        result = false;
                    }
                    else
                    {
                        ProgramThread.MousePoint mousePoint;
                        ProgramThread.GetCursorPos(out mousePoint);
                        Point position = new Point(mousePoint.X, mousePoint.Y);
                        result = rECT.Contains(position);
                    }
                }
            }
            return(result);
        }