Share via


Monitor GetPhysicalMonitorsFromHMONITOR Function 

 
Monitor Configuration API
Previous Next

GetPhysicalMonitorsFromHMONITOR Function

Retrieves the physical monitors associated with an HMONITOR monitor handle.

Syntax

  BOOL GetPhysicalMonitorsFromHMONITOR(
  HMONITOR
    hMonitor,

    DWORD
    dwPhysicalMonitorArraySize,

    LPPHYSICAL_MONITOR
    pPhysicalMonitorArray

  );

Parameters

hMonitor

[in]  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

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

pPhysicalMonitorArray

[out]  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.

Example Code

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

Client: Requires Windows Vista.

Header: Include PhysicalMonitorEnumerationAPI.h.

Library: Use dxva2.lib.

See Also

Previous Next