Пример #1
0
        private void HighlightedWindow(IntPtr hwnd)
        {
            wm = new HighlightedWindow()
            {
                Width           = 0,
                Height          = 0,
                Left            = int.MaxValue,
                Top             = int.MaxValue,
                Background      = Brushes.Transparent,// new SolidColorBrush(Color.FromArgb(0xa2, 0x12, 0x0a, 0xd0)),
                BorderBrush     = System.Windows.Media.Brushes.Red,
                BorderThickness = new Thickness(2),
            };
            wm.Show();

            WinUser.Rect rect;
            WinUser.GetWindowRect(hwnd, out rect);
            int width  = rect.Right - rect.Left;
            int height = rect.Bottom - rect.Top;

            wm.Left   = rect.Left;
            wm.Top    = rect.Top;
            wm.Width  = rect.Right - rect.Left;
            wm.Height = rect.Bottom - rect.Top;
            if (WinUser.IsMaximize(hwnd))
            {
                wm.Left   = 0;
                wm.Top    = 0;
                wm.Width  = rect.Right + rect.Left;
                wm.Height = rect.Bottom + rect.Top;
            }

            Thread.Sleep(200);
            wm.Close();
        }
Пример #2
0
        private void search_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (isSearching)
            {
                var p = GlobalMouse.Position;
                last_p = p;
                IntPtr _hwnd = WinUser.WindowFromPoint(new MS.Interop.WinUser.POINT()
                {
                    x = (int)p.X, y = (int)p.Y
                });
                if (GetControlText(_hwnd).Contains("SVG Code"))
                {
                    int t = 1;
                }
                if (WinUser.GetAncestor(_hwnd, 1) != DesktopHandle)
                {
                    var next = NextWindow(_hwnd);
                    while (next != IntPtr.Zero && WinUser.IsWindowVisible(next))
                    {
                        WinUser.Rect _rect;
                        WinUser.GetWindowRect(next, out _rect);
                        if (p.X >= _rect.Left && p.X <= _rect.Right && p.Y >= _rect.Top && p.Y <= _rect.Bottom)
                        {
                            _hwnd = next;
                        }
                        next = NextWindow(next);
                    }
                }

                WinUser.Rect rect;
                WinUser.GetWindowRect(_hwnd, out rect);
                int width  = rect.Right - rect.Left;
                int height = rect.Bottom - rect.Top;

                int x_rel = (int)(p.X - rect.Left);
                int y_rel = (int)(p.Y - rect.Top);

                if (last_hwnd == _hwnd || _hwnd == wmHandle || _hwnd == cpHandle)
                {
                    return;
                }
                last_hwnd   = _hwnd;
                status.Text = string.Format("({0}, {1})-({2}, {3}) {4}x{5}",
                                            rect.Left, rect.Top, rect.Right, rect.Bottom,
                                            rect.Right - rect.Left, rect.Bottom - rect.Top);

                wm.Left   = rect.Left;
                wm.Top    = rect.Top;
                wm.Width  = rect.Right - rect.Left;
                wm.Height = rect.Bottom - rect.Top;
                if (WinUser.IsMaximize(_hwnd))
                {
                    wm.Left   = 0;
                    wm.Top    = 0;
                    wm.Width  = rect.Right + rect.Left;
                    wm.Height = rect.Bottom + rect.Top;
                }

                string str_hwnd = Convert.ToString(_hwnd.ToInt32(), 16).ToUpper();
                while (str_hwnd.Length < 8)
                {
                    str_hwnd = "0" + str_hwnd;
                }
                this.hwndText.Text = str_hwnd;
            }
        }