GetPhysicalMonitorsFromHMONITOR 函式 (physicalmonitorenumerationapi.h)

擷取與 HMONITOR 監視器句柄相關聯的實體監視器。

語法

_BOOL GetPhysicalMonitorsFromHMONITOR(
  [in]  HMONITOR           hMonitor,
  [in]  DWORD              dwPhysicalMonitorArraySize,
  [out] LPPHYSICAL_MONITOR pPhysicalMonitorArray
);

參數

[in] hMonitor

監視句柄。 監視句柄是由數個多個顯示監視器函式傳回,包括 EnumDisplayMonitorsMonitorFromWindow,這些函式是圖形裝置介面的一部分, (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
程式庫 Dxva2.lib
Dll Dxva2.dll

另請參閱

監視組態函式