예제 #1
0
 public PositionedWindow(WindowRectangle rectangle, IntPtr windowHandle, string title,
                         User32.WINDOWPLACEMENT placement, bool isVisible)
 {
     Rectangle    = rectangle;
     WindowHandle = windowHandle;
     Title        = title;
     Placement    = placement;
     IsVisible    = isVisible;
 }
예제 #2
0
        private void SaveCurrentUILayout()
        {
            SettingsManager.SaveCurrentUILayout(DockPanelControl);

            User32.WINDOWPLACEMENT posInfo = default;
            if (User32.GetWindowPlacement(Handle, ref posInfo))
            {
                SettingsManager.LoadSettings();
                SettingsManager.Current.DisplaySettings.LastPosition = posInfo.NormalPosition;
                SettingsManager.Current.DisplaySettings.IsMaximized  = posInfo.ShowCmd.HasFlag(User32.ShowWindowCommands.Maximize);
                SettingsManager.SaveSettings();
            }
        }
예제 #3
0
        /// <summary>
        /// Capture window image
        /// </summary>
        public void ScreenshotWindow()
        {
            //int hWnd = User32.GetForegroundWindow();
            int hWnd = User32.FindWindow(null, "Fallout Online");

            if (hWnd == 0)
            {
                int error = GetLastError();

                AddLog("ERROR finding window: " + error);
                return;
            }
            User32.RECT bounds = new User32.RECT();
            User32.GetClientRect((IntPtr)hWnd, ref bounds);
            int width  = bounds.right - bounds.left;
            int height = bounds.bottom - bounds.top;

            User32.WINDOWPLACEMENT wp = new User32.WINDOWPLACEMENT();
            User32.GetWindowPlacement((IntPtr)hWnd, ref wp);
            int x;
            int y;

            if (wp.showCmd == (int)User32.WindowState.SW_SHOWMAXIMIZED)
            {
                x = wp.ptMaxPosition.X;
                y = wp.ptMaxPosition.Y;
            }
            else
            {
                x = wp.rcNormalPosition.X;
                y = wp.rcNormalPosition.Y;
            }

            if ((x + width) > Screen.PrimaryScreen.WorkingArea.Width)
            {
                width = width - ((x + width) - Screen.PrimaryScreen.WorkingArea.Width);
            }

            if ((y + height) > Screen.PrimaryScreen.WorkingArea.Height)
            {
                height = height - ((y + height) - Screen.PrimaryScreen.WorkingArea.Height);
            }

            fo_width  = width;
            fo_height = height;
            fo_x      = x + 2;  // h4x
            fo_y      = y + 20; // h4x

            fo_hwnd = hWnd;
        }
예제 #4
0
        private void SaveTerminalState(TerminalWindow terminalWindow)
        {
            var placement = new User32.WINDOWPLACEMENT();

            if (User32.GetWindowPlacement(process.MainWindowHandle, ref placement))
            {
                if (placement.showCmd == User32.SW_SHOWMINIMIZED)
                {
                    return;
                }
            }
            config.Width      = terminalWindow.Width;
            config.Height     = terminalWindow.Height;
            config.OffsetLeft = terminalWindow.Left;
        }
예제 #5
0
        private void DoEyeShot()
        {
            int hWnd = User32.GetForegroundWindow();

            if (hWnd == 0)
            {
                int error = GetLastError();

                AddLog("ERROR finding window: " + error);
                return;
            }
            User32.RECT bounds = new User32.RECT();
            User32.GetClientRect((IntPtr)hWnd, ref bounds);
            int width  = bounds.right - bounds.left;
            int height = bounds.bottom - bounds.top;

            User32.WINDOWPLACEMENT wp = new User32.WINDOWPLACEMENT();
            User32.GetWindowPlacement((IntPtr)hWnd, ref wp);
            int x;
            int y;

            if (wp.showCmd == (int)User32.WindowState.SW_SHOWMAXIMIZED)
            {
                x = wp.ptMaxPosition.X;
                y = wp.ptMaxPosition.Y;
            }
            else
            {
                x = wp.rcNormalPosition.X;
                y = wp.rcNormalPosition.Y;
            }

            /*
             * if ((x + width) > Screen.PrimaryScreen.WorkingArea.Width)
             *  width = width - ((x + width) - Screen.PrimaryScreen.WorkingArea.Width);
             *
             * if ((y + height) > Screen.PrimaryScreen.WorkingArea.Height)
             *  height = height - ((y + height) - Screen.PrimaryScreen.WorkingArea.Height);
             */

            Point curPos = Cursor.Position;

            DelayedLeftClick(curPos.X, curPos.Y, 25, false);
            DelayedLeftClick(x + 120, y + 136, 25, false);

            Cursor.Position = curPos;
        }
예제 #6
0
        private void DoOperation(IntPtr win)
        {
            while (true)
            {
                //topLevelWin是本进程(?)内的顶层窗口
                //rootWindow可能会跨进程
                var topLevelWin = Native.GetTopLevelWindow(win);
                var rootWin     = Native.GetAncestor(topLevelWin, Native.GetAncestorFlags.GetRoot);

                if (rootWin == IntPtr.Zero)
                {
                    return;
                }

                Debug.WriteLine(string.Format("win     : {0:X}", win.ToInt64()));
                Debug.WriteLine(string.Format("root    : {0:X}", rootWin.ToInt64()));
                Debug.WriteLine(string.Format("topLevel: {0:X}", topLevelWin.ToInt64()));

                var rootWinExStyle   = User32.GetWindowLong(rootWin, User32.GWL.GWL_EXSTYLE);
                var rootWinStyle     = User32.GetWindowLong(rootWin, User32.GWL.GWL_STYLE);
                var topLevelWinstyle = User32.GetWindowLong(topLevelWin, User32.GWL.GWL_STYLE);

                switch (ChangeWindowStateTo)
                {
                case WindowOperation.MAXIMIZE_RESTORE:
                    IntPtr winToControl;
                    if ((long)User32.WS.WS_MAXIMIZEBOX == (topLevelWinstyle & (long)User32.WS.WS_MAXIMIZEBOX))
                    {
                        winToControl = topLevelWin;
                    }
                    else if (topLevelWin != rootWin && (long)User32.WS.WS_MAXIMIZEBOX == (rootWinStyle & (long)User32.WS.WS_MAXIMIZEBOX))
                    {
                        winToControl = rootWin;
                    }
                    else     //如果窗口都不响应, 考虑回滚为处理活动窗口
                    {
                        var fgWin = Native.GetForegroundWindow();
                        if (fgWin == win)
                        {
                            return;
                        }

                        win = fgWin;
                        continue;
                    }

                    var wp = new User32.WINDOWPLACEMENT();
                    wp.length = Marshal.SizeOf(typeof(User32.WINDOWPLACEMENT));

                    if (!User32.GetWindowPlacement(rootWin, ref wp))
                    {
                        return;
                    }

                    if (wp.showCmd == (int)ShowWindowCommands.MAXIMIZED)
                    {
                        User32.ShowWindowAsync(winToControl, (int)ShowWindowCommands.NORMAL);
                    }
                    else
                    {
                        User32.ShowWindowAsync(winToControl, (int)ShowWindowCommands.MAXIMIZED);
                    }
                    goto end;

                case WindowOperation.MINIMIZE:
                    if ((long)User32.WS.WS_MINIMIZEBOX == (rootWinStyle & (long)User32.WS.WS_MINIMIZEBOX))
                    {
                        User32.PostMessage(rootWin, User32.WM.WM_SYSCOMMAND, (int)User32.SysCommands.SC_MINIMIZE, 0);
                    }
                    else if (topLevelWin != rootWin && (long)User32.WS.WS_MINIMIZEBOX == (topLevelWinstyle & (long)User32.WS.WS_MINIMIZEBOX))
                    {
                        User32.PostMessage(topLevelWin, User32.WM.WM_SYSCOMMAND, (int)User32.SysCommands.SC_MINIMIZE, 0);
                    }
                    goto end;

                case WindowOperation.CLOSE:
                    User32.PostMessage(rootWin, User32.WM.WM_SYSCOMMAND, (int)User32.SysCommands.SC_CLOSE, 0);
                    goto end;

                case WindowOperation.TOP_MOST:

                    if ((rootWinExStyle & (int)User32.WS_EX.WS_EX_TOPMOST) != 0)
                    {
                        User32.SetWindowPos(rootWin, new IntPtr(-2), 0, 0, 0, 0, User32.SWP.SWP_NOMOVE | User32.SWP.SWP_NOSIZE);
                    }
                    else
                    {
                        User32.SetWindowPos(rootWin, new IntPtr(-1), 0, 0, 0, 0, User32.SWP.SWP_NOMOVE | User32.SWP.SWP_NOSIZE);
                    }

                    goto end;
                }
                break;
            }

            end : GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        }