GetDesktopWindow()
returns only the primary desktop. I've also tried EnumDisplayMonitors()
, but that doesn't return the desktop handle.
You can do this using the functions that are available, as follows:
Method 1 (less accurate for windows overlapping a monitor boundary)
EnumWindows()
) MonitorFromWindow()
to ignore the ones that
Method 2 (more accurate)
GetMonitorInfo()
function) EnumWindows()
) GetWindowRect()
for XP, otherwise DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS)
) to see if it intersects ( IntersectRect()
) with the monitor rectangle. You can use EnumWindows
function and then check that window belongs to the specific monitor:
BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam) noexcept
{
auto const h_monitor{::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL)};
if(h_monitor == g_h_target_minitor)
{
// Do something...
}
return TRUE;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.