示例#1
0
 public void HideWindow_Click()
 {
     if (!IsHasProcessExits())
     {
         User32Window.ShowWindow(SelectWindow.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_HIDE);
     }
 }
 public void HideWindow(NativeWindowModel window)
 {
     if (!window.IsHasProcessExits())
     {
         User32Window.ShowWindow(window.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_HIDE);
     }
 }
示例#3
0
        private void MouseHook_OnMouseUp(object sender, Point p)
        {
            //Point GetMousePos = Mouse.GetPosition(App.Current.MainWindow);
            //Name = System.Windows.Forms.Cursor.Position.X + "," + System.Windows.Forms.Cursor.Position.Y;
            MouseHook.SystemParametersInfo((uint)MouseHook.SystemParametersDesktopInfo.SPI_SETCURSORS, 0, IntPtr.Zero, (uint)MouseHook.SystemParametersDesktopInfo.SPIF_SENDWININICHANGE);
            MouseHook.OnMouseUp -= MouseHook_OnMouseUp;
            //Name = Control.MousePosition.X + "," + Control.MousePosition.Y;
            var handle = MouseHook.WindowFromPoint(new POINT(Control.MousePosition.X, Control.MousePosition.Y));
            var title  = new StringBuilder(256);

            User32Window.GetWindowText(handle, title, title.Capacity);//得到窗口的标题
            var className = new StringBuilder(256);

            User32Window.GetClassName(handle, className, className.Capacity);//得得到窗口的句柄 类名
            //SelectWindow.Title = title.ToString();
            //SelectWindow.ClassName = className.ToString();
            User32Window.GetWindowThreadProcessId(handle, out int pid);
            //SelectWindow.Process = Process.GetProcessById(pid);
            SelectWindow = new HandleWindow
            {
                Title     = title.ToString(),
                ClassName = className.ToString(),
                Handle    = handle,
                Process   = Process.GetProcessById(pid)
            };
        }
        /// <summary>
        /// 设置窗口点击穿透
        /// </summary>
        /// <param name="window"></param>
        public void SetWindowPenetrate(IntPtr dest)
        {
            int style = User32Window.GetWindowLongA(dest, (int)WindowLongFlags.GWL_EXSTYLE);

            User32Window.SetWindowLong(dest, (int)WindowLongFlags.GWL_EXSTYLE, style | (int)UnmanagedMethods.WindowStyles.WS_EX_TRANSPARENT | (int)UnmanagedMethods.WindowStyles.WS_EX_LAYERED);
            User32Window.SetLayeredWindowAttributes(dest, 0, 255, 0x2);
            //User32Window.SetLayeredWindowAttributes(dest, 0, 100, 0);
        }
示例#5
0
 public void MaximizeWindow_Click()
 {
     if (!IsHasProcessExits())
     {
         //最大化启动的程序
         User32Window.ShowWindow(SelectWindow.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_MAXIMIZE);
     }
 }
 public void MaximizeWindow(NativeWindowModel window)
 {
     if (!window.IsHasProcessExits())
     {
         //最大化启动的程序
         User32Window.ShowWindow(window.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_MAXIMIZE);
     }
 }
 /// <summary>
 /// 将传入窗口设置为无边框窗口化
 /// </summary>
 /// <param name="window"></param>
 public void BorderlessWindow(NativeWindowModel window)
 {
     if (!window.IsHasProcessExits())
     {
         int p1 = User32Window.GetWindowLongA(window.Handle, (int)WindowLongFlags.GWL_STYLE);
         p1 &= ~13500416;
         User32Window.SetWindowLong(window.Handle, (int)WindowLongFlags.GWL_STYLE, p1);
     }
 }
 public void NormalWindow(NativeWindowModel window)
 {
     if (!window.IsHasProcessExits())
     {
         User32Window.ShowWindow(window.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_RESTORE);
         int p1 = User32Window.GetWindowLongA(window.Handle, (int)WindowLongFlags.GWL_STYLE);
         User32Window.SetWindowLong(window.Handle, (int)WindowLongFlags.GWL_STYLE, p1);
     }
 }
示例#9
0
 public void NormalWindow_Click()
 {
     if (!IsHasProcessExits())
     {
         User32Window.ShowWindow(SelectWindow.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_RESTORE);
         int p1 = User32.GetWindowLong(SelectWindow.Handle, (int)WindowLongFlags.GWL_STYLE);
         User32.SetWindowLong(SelectWindow.Handle, (int)WindowLongFlags.GWL_STYLE, (int)p1);
     }
 }
        /// <summary>
        /// 拖拽指针获取目标窗口
        /// </summary>
        /// <param name="action">目标窗口回调</param>
        public void GetMoveMouseDownWindow(Action <NativeWindowModel> action)
        {
            void MouseHook_OnMouseUp(object?sender, Point p)
            {
                //Point GetMousePos = Mouse.GetPosition(App.Current.MainWindow);
                //Name = System.Windows.Forms.Cursor.Position.X + "," + System.Windows.Forms.Cursor.Position.Y;
                MouseHook.SystemParametersInfo((uint)MouseHook.SystemParametersDesktopInfo.SPI_SETCURSORS, 0, IntPtr.Zero, (uint)MouseHook.SystemParametersDesktopInfo.SPIF_SENDWININICHANGE);
                MouseHook.OnMouseUp -= MouseHook_OnMouseUp;
                //Name = Control.MousePosition.X + "," + Control.MousePosition.Y;
                MouseHook.GetCursorPos(out var pointInt);
                var handle = MouseHook.WindowFromPoint(pointInt);
                var title  = new StringBuilder(256);

                User32Window.GetWindowText(handle, title, title.Capacity);//得到窗口的标题
                var className = new StringBuilder(256);

                User32Window.GetClassName(handle, className, className.Capacity);//得得到窗口的句柄 类名
                //SelectWindow.Title = title.ToString();
                //SelectWindow.ClassName = className.ToString();
                User32Window.GetWindowThreadProcessId(handle, out int pid);
                //SelectWindow.Process = Process.GetProcessById(pid);
                try
                {
                    var    process = Process.GetProcessById(pid);
                    string?path    = null;
                    if (process != null)
                    {
                        try
                        {
                            path = process.MainModule?.FileName;
                        }
                        catch // 32位进程无法访问64位进程
                        {
                            path = NativeMethods.QueryFullProcessImageName(process);
                        }
                    }
                    var window = new NativeWindowModel
                    {
                        Title     = title.ToString(),
                        ClassName = className.ToString(),
                        Handle    = handle,
                        Process   = process,
                        Path      = path,
                        Name      = process?.ProcessName,
                    };
                    action?.Invoke(window);
                }
                catch (Exception e)
                {
                    e.LogAndShowT(TAG);
                }
            }

            MouseHook.SetSystemCursor(MouseHook.LoadCursor(IntPtr.Zero, MouseHook.OCR_CROSS), MouseHook.OCR_NORMAL);
            MouseHook.OnMouseUp += MouseHook_OnMouseUp;
        }
示例#11
0
        /// <summary>
        /// Copy the current code to the clipboard
        /// </summary>
        public void CopyCodeToClipboard(string code = null, bool showError = false)
        {
            if (code == null)
            {
                code = this.CurrentCode;
            }

            bool clipRetry = false;

            do
            {
                bool failed = false;
                // check if the clipboard is locked
                IntPtr hWnd = User32Window.GetOpenClipboardWindow();
                if (hWnd != IntPtr.Zero)
                {
                    int len = User32Window.GetWindowTextLength(hWnd);
                    if (len == 0)
                    {
                        //WinAuthMain.LogException(new ApplicationException("Clipboard in use by another process"));
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder(len + 1);
                        User32Window.GetWindowText(hWnd, sb, sb.Capacity);
                        //WinAuthMain.LogException(new ApplicationException("Clipboard in use by '" + sb.ToString() + "'"));
                    }

                    failed = true;
                }
                else
                {
                    // Issue#170: can still get error copying even though it works, so just increase retries and ignore error
                    try
                    {
                        Clipboard.Clear();

                        // add delay for clip error
                        System.Threading.Thread.Sleep(100);
                        Clipboard.SetDataObject(code, true);
                    }
                    catch (ExternalException)
                    {
                    }
                }

                if (failed == true && showError == true)
                {
                    // only show an error the first time
                    //clipRetry = (MessageBox.Show(form, strings.ClipboardInUse,
                    //    WinAuthMain.APPLICATION_NAME,
                    //    MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes);
                }
            }while (clipRetry == true);
        }
        /// <summary>
        /// 设置缩略图到指定窗口句柄
        /// </summary>
        public IntPtr SetDesktopBackgroundToWindow(IntPtr dest, int width, int height)
        {
            //backgroundPath = null;
            //IntPtr wep = IntPtr.Zero;
            //User32Window.EnumWindows(((hwnd, e) =>
            //{
            //    IntPtr p = User32Window.FindWindowEx(hwnd,
            //          IntPtr.Zero,
            //          "SHELLDLL_DefView",
            //          null);
            //    if (p != IntPtr.Zero)
            //    {
            //        IntPtr workerw = User32Window.FindWindowEx(IntPtr.Zero,
            //            hwnd,
            //            "WorkerW",
            //            null);

            //        User32Window.EnumChildWindows(workerw, ((hwnd2, e2) =>
            //        {
            //            wep = hwnd2;
            //            return true;
            //        }), IntPtr.Zero);
            //    }
            //    return true;
            //}), IntPtr.Zero);

            //if (wep == IntPtr.Zero)
            //{
            //    IntPtr r = IntPtr.Zero;
            //    MouseHook.SystemParametersInfo((uint)MouseHook.SystemParametersDesktopInfo.SPI_GETDESKWALLPAPER, 300, r, (uint)MouseHook.SystemParamtersInfoFlags.None);

            //    backgroundPath = Marshal.PtrToStringAuto(r);  //默认桌面路径
            //    return;
            //}
            //User32Window.SetWindowPos(dest, HWND_BOTTOM, 0, 0, 0, 0,
            //    SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_SHOWWINDOW);

            IntPtr p = User32Window.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);

            ReleaseBackground(dest);

            var temp = DWMApi.DwmRegisterThumbnail(dest, p, out dest);

            if (temp == 0)
            {
                BackgroundUpdate(dest, width, height);
            }
            return(dest);
        }
示例#13
0
 /// <summary>
 /// 窗口显示关闭
 /// </summary>
 public void ChangeWindowVisible()
 {
     App.Current.MainWindow = App.Current.MainWindow ?? WindowService.Current.GetMainWindow();
     if (IsVisible)
     {
         App.Current.MainWindow.Show();
         App.Current.MainWindow.WindowState = WindowState.Normal;
         this.Activate();
         User32Window.FlashWindow(new WindowInteropHelper(App.Current.MainWindow).Handle);
     }
     else
     {
         App.Current.MainWindow.WindowState = WindowState.Minimized;
         App.Current.MainWindow.Hide();
         //App.Current.MainWindow.Visibility = Visibility.Collapsed;
     }
 }
        public void ToWallerpaperWindow(NativeWindowModel window)
        {
            if (!window.IsHasProcessExits())
            {
                //最大化启动的程序
                User32Window.ShowWindow(window.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_RESTORE);
                IntPtr progman = User32Window.FindWindow("Progman", null);
                IntPtr result  = User32Window.SendMessage(progman, 0x052C, new IntPtr(0), IntPtr.Zero);
                IntPtr workerw = IntPtr.Zero;

                User32Window.EnumWindows(((tophandle, topparamhandle) =>
                {
                    IntPtr p = User32Window.FindWindowEx(tophandle,
                                                         IntPtr.Zero,
                                                         "SHELLDLL_DefView",
                                                         null);

                    if (p != IntPtr.Zero)
                    {
                        workerw = User32Window.FindWindowEx(IntPtr.Zero,
                                                            tophandle,
                                                            "WorkerW",
                                                            null);
                    }
                    return(true);
                }), IntPtr.Zero);
                SetParentWindow(window.Handle, workerw);


                int p1 = User32Window.GetWindowLongA(window.Handle, (int)WindowLongFlags.GWL_STYLE);
                p1 &= ~13500416;
                User32Window.SetWindowLong(window.Handle, (int)WindowLongFlags.GWL_STYLE, p1);

                //最大化启动的程序
                User32Window.ShowWindow(window.Handle, (short)User32Window.Cmd_SHOWWINDOWS.SW_MAXIMIZE);
                //User32Window.MoveWindow(window.Handle, 0, 0, Screen.AllScreens[0].WorkingArea.Width,
                //    Screen.AllScreens[0].WorkingArea.Height, false);

                User32Window.SetActiveWindow(window.Handle);
            }
        }
 public void SetParentWindow(IntPtr source, IntPtr dest)
 {
     User32Window.SetParent(source, dest);
     //User32Window.SetWindowLong(source, (int)WindowLongParam.GWL_HWNDPARENT, (int)dest);
 }
 /// <summary>
 /// 激活窗口并置顶
 /// </summary>
 /// <param name="window"></param>
 public void SetActiveWindow(NativeWindowModel window)
 {
     User32Window.SetActiveWindow(window.Handle);
     User32Window.SetForegroundWindow(window.Handle);
 }
示例#17
0
        public List<User32Window> get_windows()
        {
            var windows_list = new List<User32Window>();

              EnumDelegate enum_desktop_windows_callback = delegate(IntPtr hWnd, int lParam) {
            StringBuilder string_builder = new StringBuilder(255);
            User32Window win = new User32Window();

            win.hWnd = hWnd;
            GetWindowText(hWnd, string_builder, string_builder.Capacity + 1);
            win.text = string_builder.ToString();

            GetClassName(hWnd, string_builder, string_builder.Capacity + 1);
            win.type = string_builder.ToString();

            windows_list.Add(win);
            return true;
              };
              EnumDesktopWindows(IntPtr.Zero, enum_desktop_windows_callback, IntPtr.Zero);
              return windows_list;
        }