MonitorFromWindow

[This is preliminary documentation and subject to change.]

The MonitorFromWindow function obtains a handle to the display monitor that has the largest area of intersection with the bounding rectangle of a specified window.

HMONITOR MonitorFromWindow(
  HWND hwnd,       // handle to a window 
  DWORD dwFlags    // flags if no monitor intersects the window 
);
 

Parameters

hwnd
Handle to the window of interest.
dwFlags
A set of flags that determine the function's return value if the window does not intersect any display monitor.

This parameter can be one of the following values.
Value Meaning
MONITOR_DEFAULTTONEAREST Return a handle to the display monitor that is nearest to the window.
MONITOR_DEFAULTTONULL Return NULL.
MONITOR_DEFAULTTOPRIMARY Return a handle to the primary display monitor.

Return Values

If the window intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display monitor that has the largest area of intersection with the window.

If the window does not intersect a display monitor, the return value depends on the value of dwFlags.

Remarks

If the window is currently minimized, MonitorFromWindow uses the rectangle of the window before it was minimized.

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Requires Windows 98.
  Windows CE: Unsupported.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.

See Also

Multiple Display Monitors Overview, Multiple Display Monitors Functions, MonitorFromPoint, MonitorFromRect