Get monitor index from its handle HMONITOR

I'm interested in getting the monitor index (1-based, to match Windows numbering) given the monitor handle.

Case of use: given a window's rect I want to know the monitor it belongs to. I can get the point using MonitorFromRect:

// RECT rect
const HMONITOR hMonitor = MonitorFromRect(rect, MONITOR_DEFAULTTONEAREST);

How can I get the monitor index?

PS: not sure if duplicate, but I've been looking around with no luck.

#c++ #windows

3 Likes4.70 GEEK