检索与 HMONITOR 监视器句柄关联的物理监视器。
语法
_BOOL GetPhysicalMonitorsFromHMONITOR(
  [in]  HMONITOR           hMonitor,
  [in]  DWORD              dwPhysicalMonitorArraySize,
  [out] LPPHYSICAL_MONITOR pPhysicalMonitorArray
);
参数
[in] hMonitor
监视器句柄。 监视器句柄由多个多显示器监视器函数返回,包括 EnumDisplayMonitors 和 MonitorFromWindow,它们是图形设备接口 (GDI) 的一部分。
[in] dwPhysicalMonitorArraySize
pPhysicalMonitorArray 中的元素数。 若要获取所需的数组大小,请调用 GetNumberOfPhysicalMonitorsFromHMONITOR。
[out] pPhysicalMonitorArray
指向PHYSICAL_MONITOR结构的数组 的 指针。 调用方必须分配数组。
返回值
如果函数成功,则返回值为 TRUE。 如果函数失败,则返回值为 FALSE。 要获得更多的错误信息,请调用 GetLastError。
注解
单个 HMONITOR 句柄可以与多个物理监视器相关联。 此函数返回每个物理监视器的句柄和文本说明。
使用完监视器句柄后,通过将 pPhysicalMonitorArray 数组传递给 DestroyPhysicalMonitors 函数来关闭它们。
示例
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);
    }
}
要求
| 要求 | 值 | 
|---|---|
| 最低受支持的客户端 | Windows Vista [仅限桌面应用] | 
| 最低受支持的服务器 | Windows Server 2008 [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | physicalmonitorenumerationapi.h | 
| Library | Dxva2.lib | 
| DLL | Dxva2.dll |