public bool GiveWindowFocus(IntPtr hwnd)
        {
            IntPtr activeHandle = GetForegroundWindow();

            if (activeHandle == hwnd)
            {
                return(false);
            }

            //get the hWnd of the process
            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(hwnd, ref placement);

            // Check if window is minimized
            if (placement.showCmd == 2)
            {
                //the window is hidden so we restore it
                ShowWindow(hwnd, ShowWindowEnum.Restore);
            }

            //set user's focus to the window
            SetForegroundWindow(hwnd);

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the window placement.
        /// </summary>
        private static Windowplacement GetPlacement(IntPtr hwnd)
        {
            Windowplacement placement = new Windowplacement();

            placement.length = Marshal.SizeOf(placement);
            GetWindowPlacement(hwnd, ref placement);
            return(placement);
        }
Esempio n. 3
0
        internal static Windowplacement GetWindowPlacement(IntPtr hwnd)
        {
            var lpwndpl = new Windowplacement();

            if (User32.GetWindowPlacement(hwnd, lpwndpl))
            {
                return(lpwndpl);
            }
            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
Esempio n. 4
0
        private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            if (hwnd == IntPtr.Zero)
            {
                return;
            }

            EventTypeEnum evtType = EventTypeEnum.Unknown;

            switch (eventType)
            {
            case EVENT_SYSTEM_MINIMIZEEND:     //for some reasons this triggers on maximize???
                //  evtType = EventTypeEnum.Minimizeed;
                break;

            case EVENT_SYSTEM_FOREGROUND:
                evtType = EventTypeEnum.Foreground;
                break;

            case EVENT_OBJECT_LOCATIONCHANGE:
                Windowplacement placement = new Windowplacement();
                placement.length = Marshal.SizeOf(placement);
                GetWindowPlacement(hwnd, ref placement);

                switch (placement.showCmd)
                {
                case 7:         //SW_SHOWMINNOACTIVE
                case 4:         //SW_SHOWNOACTIVATE
                case (int)SW_SHOWMINIMIZED:
                    evtType = EventTypeEnum.Minimizeed;
                    break;

                case 1:         //SW_SHOWNORMAL
                case 5:         //SW_SHOW
                case 8:         //SW_SHOWNA
                case (int)SW_SHOWMAXIMIZED:
                    evtType = EventTypeEnum.Maximizeed;
                    break;
                }

                break;
            }

            if (evtType == EventTypeEnum.Unknown)
            {
                return;
            }

            var windowName = GetWindowTitle(hwnd);

            GetWindowThreadProcessId(hwnd, out var processId);
            ActiveWindowChangedEvent?.Invoke(this, new ActiveWindowChangedEventArgs(processId, windowName, evtType));
        }
Esempio n. 5
0
 private void btnSwitch_Click(object sender, EventArgs e)
 {
     if (minecraftHandle != IntPtr.Zero)
     {
         Windowplacement placement = new Windowplacement();
         GetWindowPlacement(minecraftHandle, ref placement);
         if (placement.showCmd == 2)
         {
             ShowWindow(minecraftHandle, ShowWindowEnum.Restore);
         }
         SetForegroundWindow(minecraftHandle);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Checks whether a given window is currently minimized
        /// </summary>
        /// <param name="wdwIntPtr">The window-Handler</param>
        /// <returns>true if the givven window is minimized</returns>
        public static bool IsMinimized(IntPtr wdwIntPtr)
        {
            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(wdwIntPtr, ref placement);

            // Check if window is minimized
            if (placement.showCmd == 2)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        static void BringWindowToFront()
        {
            IntPtr wdwIntPtr = FindWindow(null, "ED-GO Event Client");

            //get the hWnd of the process
            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(wdwIntPtr, ref placement);

            // Check if window is minimized
            if (placement.showCmd == 2)
            {
                //the window is hidden so we restore it
                ShowWindow(wdwIntPtr, ShowWindowEnum.Restore);
            }
        }
Esempio n. 8
0
        internal static void BringToFront(int pid)
        {
            Process process = Process.GetProcessById(pid);

            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(process.MainWindowHandle, ref placement);

            // Check if window is minimized
            if (placement.showCmd == 2)
            {
                // Restore hidden window
                ShowWindow(process.MainWindowHandle, ShowWindowEnum.Restore);
            }

            SetForegroundWindow(process.MainWindowHandle);
        }
Esempio n. 9
0
        public void TestBringToFront()
        {
            Process p = Process.Start(new ProcessStartInfo
            {
                FileName    = "cmd.exe",
                WindowStyle = ProcessWindowStyle.Minimized
            });

            Program.BringToFront(p.Id);

            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(p.MainWindowHandle, ref placement);

            Assert.AreNotEqual(ShowWindowEnum.ShowMinimized, placement.showCmd);

            p.Kill();
        }
Esempio n. 10
0
        static private void BringWindowToFront(IntPtr wdwIntPtr)
        {
            // IntPtr wdwIntPtr = FindWindow(null, "Put_your_window_title_here");

            //get the hWnd of the process
            Windowplacement placement = new Windowplacement();

            GetWindowPlacement(wdwIntPtr, ref placement);

            // Check if window is minimized
            if (placement.showCmd == 2)
            {
                //the window is hidden so we restore it
                ShowWindow(wdwIntPtr, ShowWindowEnum.Restore);
            }

            //set user's focus to the window
            SetForegroundWindow(wdwIntPtr);
        }
Esempio n. 11
0
 static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
 private void UpdateClipRegion(IntPtr hWnd, Windowplacement placement, ClipRegionChangeType changeType,
                               RECT currentBounds)
 {
     UpdateClipRegionCore(hWnd, placement.showCmd, changeType, currentBounds.ToInt32Rect());
     _lastWindowPlacement = placement.showCmd;
 }
Esempio n. 13
0
 public static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
Esempio n. 14
0
        public static List <TaskWindow> GetProcesses(bool getAll = false)
        {
            ignoredProcesses = Properties.Settings.Default.ignoredProcesses.Split(',');
            TaskWindows.Clear();

            Process[] procs = Process.GetProcesses();
            foreach (Process proc in procs)
            {
                IntPtr          hWnd;
                Windowplacement placement = new Windowplacement();

                if (getAll)
                {
                    if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
                    {
                        GetWindowPlacement(proc.MainWindowHandle, ref placement);
                        GetWindowRect(hWnd, out var rct);

                        //ShowCmd = Windowstate
                        // 1 = Normal, 2 = Minimized, 3 = Maximized
                        int width  = rct.Right - rct.Left + 1;
                        int height = rct.Bottom - rct.Top + 1;

                        if (width > 1 && height > 1)
                        {
                            TaskWindows.Add(new TaskWindow(false, proc.ProcessName, proc.MainModule.FileName,
                                                           placement.Flags, placement.ShowCmd, rct.Left, rct.Top, height, width, GetAppIcon(hWnd)));
                            // X Y H W
                            //debugging
                            var s = Screen.FromHandle(hWnd).DeviceName;
                            Console.WriteLine("---------------------------------------");
                            Console.WriteLine("{0}  | {1}", proc.ProcessName, hWnd);
                            Console.WriteLine("{0}", placement.ShowCmd.ToString());
                            Console.WriteLine("---------------------------------------");
                        }
                    }
                }
                else
                {
                    //Ignore Processes that are listed in ignoredProcesses
                    if (Array.IndexOf(ignoredProcesses, proc.ProcessName) == -1)
                    {
                        if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
                        {
                            GetWindowPlacement(proc.MainWindowHandle, ref placement);
                            GetWindowRect(hWnd, out var rct);

                            //ShowCmd = Windowstate
                            // 1 = Normal, 2 = Minimized, 3 = Maximized
                            int width  = rct.Right - rct.Left + 1;
                            int height = rct.Bottom - rct.Top + 1;

                            if (width > 1 && height > 1)
                            {
                                TaskWindows.Add(new TaskWindow(false, proc.ProcessName, proc.MainModule.FileName,
                                                               placement.Flags, placement.ShowCmd, rct.Left, rct.Top, height, width, GetAppIcon(hWnd)));
                                // X Y H W
                                //debugging
                                var s = Screen.FromHandle(hWnd).DeviceName;
                                Console.WriteLine("---------------------------------------");
                                Console.WriteLine("{0}  | {1}", proc.ProcessName, hWnd);
                                Console.WriteLine("{0}", placement.ShowCmd.ToString());
                                Console.WriteLine("---------------------------------------");
                            }
                        }
                    }
                }
            }
            return(TaskWindows);
        }
Esempio n. 15
0
 internal static extern bool GetWindowPlacement(IntPtr hwnd, Windowplacement lpwndpl);
Esempio n. 16
0
 public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref Windowplacement lpwndpl);