Exemplo n.º 1
0
        public static unsafe IntPtr MonitorFromRectOrWindow(RECT windowRect, IntPtr hwnd)
        {
            var monitorFromWindow = PInvoke.MonitorFromWindow(new(hwnd), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);

            if (windowRect.IsEmpty())
            {
                return(monitorFromWindow);
            }

            var monitorFromRect = PInvoke.MonitorFromRect(&windowRect, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);

            return(monitorFromRect);
        }
Exemplo n.º 2
0
        public static Rectangle GetWindowRec(IntPtr hWnd)
        {
            RECT rec = new RECT();

            GetWindowRect(hWnd, ref rec);
            Rectangle rectangle = new Rectangle();

            if (rec.IsEmpty())
            {
                return(rectangle);
            }
            rectangle = new Rectangle(rec.Left, rec.Top, rec.Right - rec.Left, rec.Bottom - rec.Top);
            return(rectangle);
        }
Exemplo n.º 3
0
        private bool windowFound(IntPtr hwnd, int lParam)
        {
            StringBuilder sb = new StringBuilder(100);

            User32.GetWindowText(hwnd, sb, sb.Capacity);
            string title = sb.ToString();

            // don't consider our own windows
            if (title == "ThumbWindows")
            {
                return(true);
            }

            WS   winStyle   = (WS)User32.GetWindowLongA(hwnd, User32.GWL_STYLE);
            WSEX winStyleEx = (WSEX)User32.GetWindowLongA(hwnd, User32.GWL_EXSTYLE);

            RECT sourceRect = new RECT();


            User32.GetWindowRect(hwnd, ref sourceRect);

            WinSbS win = new WinSbS(hwnd);

            win.SourceRect = sourceRect;
            win.Title      = title;
            win.WinStyle   = winStyle;
            win.WinStyleEx = winStyleEx;

            int cloaked = 0;

            DwmApi.DwmGetWindowAttribute(hwnd, DwmApi.DwmWindowAttribute.DWMWA_CLOAKED, out cloaked, sizeof(int));

            if (cloaked == 0 &&
                !sourceRect.IsEmpty() &&
                (winStyle & WS.WS_VISIBLE) == WS.WS_VISIBLE &&
                (winStyle & WS.WS_ICONIC) == 0 &&
                (winStyle & WS.WS_DISABLED) == 0)
            {
                this.windowsToDisplay.Add(win);
            }
            else
            {
                this.windowsRejected.Add(win);
            }

            return(true); //continue enumeration
        }