Beispiel #1
0
        //根据鼠标位置找寻窗体并绘制边框
        private void FoundAndDrawWindowRect()
        {
            Win32.LPPOINT pt = new Win32.LPPOINT();
            pt.X = MousePosition.X;
            pt.Y = MousePosition.Y;
            IntPtr hWnd = Win32.ChildWindowFromPointEx(Win32.GetDesktopWindow(), pt,
                                                       Win32.CWP_SKIPINVISIBL | Win32.CWP_SKIPDISABLED);

            if (hWnd != IntPtr.Zero)
            {
                IntPtr hTemp = hWnd;
                while (true)
                {
                    Win32.ScreenToClient(hTemp, out pt);
                    hTemp = Win32.ChildWindowFromPointEx(hWnd, pt, Win32.CWP_SKIPINVISIBL);
                    if (hTemp == IntPtr.Zero || hTemp == hWnd)
                    {
                        break;
                    }
                    hWnd = hTemp;
                    pt.X = MousePosition.X; pt.Y = MousePosition.Y; //坐标还原为屏幕坐标
                }
                Win32.LPRECT rect = new Win32.LPRECT();
                Win32.GetWindowRect(hWnd, out rect);
                imageProcessBox.SetSelectRect(new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top));
            }
        }
Beispiel #2
0
        //根据鼠标位置找寻窗体并绘制边框
        private void FoundAndDrawWindowRect()
        {
            Win32.LPPOINT pt     = new Win32.LPPOINT();
            Point         curPos = MousePosition;

            pt.X = curPos.X;
            pt.Y = curPos.Y;
            IntPtr hWnd = Win32.ChildWindowFromPointEx(Win32.GetDesktopWindow(), pt,
                                                       Win32.CWP_SKIPINVISIBL | Win32.CWP_SKIPDISABLED);

            if (hWnd != IntPtr.Zero)
            {
                IntPtr hTemp = hWnd;
                while (true)
                {
                    Win32.ScreenToClient(hTemp, out pt);
                    hTemp = Win32.ChildWindowFromPointEx(hWnd, pt, Win32.CWP_SKIPINVISIBL);
                    if (hTemp == IntPtr.Zero || hTemp == hWnd)
                    {
                        break;
                    }
                    hWnd = hTemp;
                    pt.X = curPos.X; pt.Y = curPos.Y; //坐标还原为屏幕坐标
                }
                Win32.LPRECT lprect = new Win32.LPRECT();
                Win32.GetWindowRect(hWnd, out lprect);
                Rectangle rect      = new Rectangle(lprect.Left, lprect.Top, lprect.Right - lprect.Left, lprect.Bottom - lprect.Top);
                Screen    curScreen = Screen.AllScreens.FirstOrDefault(s => s.Bounds.Contains(curPos));
                if (curScreen != null)
                {
                    Rectangle screenRect = curScreen.WorkingArea;
                    if (rect.Width > screenRect.Width || rect.Height > screenRect.Height)
                    {
                        int dW = rect.Width - screenRect.Width;
                        int dH = rect.Height - screenRect.Height;
                        int dX = screenRect.Left - rect.Left;
                        int dY = screenRect.Top - rect.Top;
                        if (dX * 2 == dW)
                        {
                            rect.X     += dX;
                            rect.Width -= dW;
                        }
                        if (dY * 2 == dH)
                        {
                            rect.Y      += dY;
                            rect.Height -= dH;
                        }
                    }
                }
                if (clipRect != Rectangle.Empty && clipRect.Contains(curPos))
                {
                    rect = clipRect;
                }
                imageProcessBox.SetSelectRect(rect);
            }
        }