GetPhysicalMonitorsFromHMONITOR function (physicalmonitorenumerationapi.h)
Retrieves the physical monitors associated with an HMONITOR monitor handle.
Syntax
_BOOL GetPhysicalMonitorsFromHMONITOR(
[in] HMONITOR hMonitor,
[in] DWORD dwPhysicalMonitorArraySize,
[out] LPPHYSICAL_MONITOR pPhysicalMonitorArray
);
Parameters
[in] 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).
[in] dwPhysicalMonitorArraySize
Number of elements in pPhysicalMonitorArray. To get the required size of the array, call GetNumberOfPhysicalMonitorsFromHMONITOR.
[out] 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
Requirement | Value |
---|---|
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 |