How do I determine if a window is off-screen?

前端 未结 3 2058
予麋鹿
予麋鹿 2021-01-04 16:48

In Windows XP and above, given a window handle (HWND), how can I tell if the window position and size leaves the window irretrievably off screen? For example, if the title

3条回答
  •  隐瞒了意图╮
    2021-01-04 16:53

    You can use MonitorFromRect or MonitorFromPoint to check if window's top left point or bottom right point isn't contained within any display monitor (off screen).

    POINT p;
    p.x = x;
    p.y = y;
    HMONITOR hMon = MonitorFromPoint(p, MONITOR_DEFAULTTONULL);
    if (hMon == NULL) {
        // point is off screen
    }
    

提交回复
热议问题