GetPhysicalMonitorsFromHMONITOR function

Retrieves the physical monitors associated with an HMONITOR monitor handle.

Syntax

_BOOL GetPhysicalMonitorsFromHMONITOR(
  HMONITOR           hMonitor,
  DWORD              dwPhysicalMonitorArraySize,
  LPPHYSICAL_MONITOR pPhysicalMonitorArray
);

Parameters

hMonitor

A monitor handle. Monitor handles are returned by several Multiple Display Monitor functions, including EnumDisplayMonitors and MonitorFromWindow, which are part of the graphics device interface (GDI).

dwPhysicalMonitorArraySize

Number of elements in pPhysicalMonitorArray. To get the required size of the array, call GetNumberOfPhysicalMonitorsFromHMONITOR.

pPhysicalMonitorArray

Pointer to an array of PHYSICAL_MONITOR structures. The caller must allocate the array.

Return Value

If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

Remarks

A single HMONITOR handle can be associated with more than one physical monitor. This function returns a handle and a text description for each physical monitor.

When you are done using the monitor handles, close them by passing the pPhysicalMonitorArray array to the DestroyPhysicalMonitors function.

Examples


HMONITOR hMonitor = NULL;
DWORD cPhysicalMonitors;
LPPHYSICAL_MONITOR pPhysicalMonitors = NULL;

// Get the monitor handle.
hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);

// Get the number of physical monitors.
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(
  hMonitor, 
  &cPhysicalMonitors
   );

if (bSuccess)
{
    // Allocate the array of PHYSICAL_MONITOR structures.
    pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(
        cPhysicalMonitors* sizeof(PHYSICAL_MONITOR));

    if (pPhysicalMonitors != NULL)
    {
        // Get the array.
        bSuccess = GetPhysicalMonitorsFromHMONITOR(
            hMonitor, cPhysicalMonitors, pPhysicalMonitors);

       // Use the monitor handles (not shown).

        // Close the monitor handles.
        bSuccess = DestroyPhysicalMonitors(
            cPhysicalMonitors, 
            pPhysicalMonitors);

        // Free the array.
        free(pPhysicalMonitors);
}

Requirements

   
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header physicalmonitorenumerationapi.h
Library Dxva2.lib
DLL Dxva2.dll

See Also

Monitor Configuration Functions