IDisplayInformationStaticsInterop::GetForMonitor method (windows.graphics.display.interop.h)

Retrieves a DisplayInformation object for the specified monitor. GetForMonitor always allocates and returns a new DisplayInformation.

Syntax

HRESULT GetForMonitor(
  HMONITOR monitor,
  REFIID   riid,
  void     **displayInfo
);

Parameters

monitor

Type: [in]\ HMONITOR

The monitor's handle.

riid

Type: [in]\ REFIID

The GUID of the DisplayInformation class.

displayInfo

Type: [iid_is][retval][out] void**

A pointer to a memory block that receives a pointer to the returned DisplayInformation object.

Return value

Type: HRESULT

If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Considerations:

  • Window movements are not tracked, since there is no window.
  • Any scale factor returned by the DisplayInformation is the current scale factor for the entire monitor. DPI virtualization acts in the same way as for GetScaleFactorForMonitor, which is the underlying API used to read scale in this case.
  • If you wish to register for events, then the current thread must have a Windows.System.DispatcherQueue running, in order to receive events. That DispatcherQueue will be snapped upon the call to GetForMonitor. If there is no DispatcherQueue, then an exception (at the application binary interface level, a HRESULT) is returned in the event handler registration methods.
  • The current thread can be MTA or STA.

You're responsible for: caching the created DisplayInformation for as long as the argument of monitor is relevant; de-registering event handlers; and dropping the last reference in order to destroy the DisplayInformation instance.

Examples

See the code example in IDisplayInformationStaticsInterop::GetForWindow.

Requirements

Requirement Value
Minimum supported client Windows 11 Build 22621
Header windows.graphics.display.interop.h