Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function retrieves a handle to the screen that has the largest area of intersection with the bounding rectangle of a specified window.

Syntax

HMONITOR MonitorFromWindow(
  HWND 
hwnd,
  DWORD 
dwFlags
);

Parameters

hwnd

[in] Handle to the window of interest.

dwFlags

[in] DWORDthat determines the return value of the function when the window does not intersect any of the screens. The following table shows a list of possible return values.

Value Description

MONITOR_DEFAULTTONEAREST

The return value is a handle to the screen that is nearest to the window.

MONITOR_DEFAULTTONULL

The return value is NULL.

MONITOR_DEFAULTTOPRIMARY

The return value is a handle to the primary screen.

Return Value

If the window intersects one or more screen rectangles, the return value is an HMONITORhandle to the screen that has the largest area of intersection with the window. If the window does not intersect a screen, the return value depends on the value of dwFlags.

Remarks

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

Requirements

Header windows.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also