こんにちは、次のコード フラグメントを使用して、Windows 7 システムのディスプレイ アダプターの数を取得しています。モニターに接続されている NVidia GT 120 と、GPU プロセッサとして機能している NVidia Quadro 4000 があります。
どちらのディスプレイ アダプターにも複数の出力ポートがあるため、次のコードを使用すると、実際には GT120 用に 2 つ、Quadro 4000 用に 2 つの Display_Device インスタンスを取得します。重複インスタンスを削除する基準として DisplayDevice 構造のレジストリ キーです)。
誰かがこの問題に対するより良い、または公式の解決策を持っていましたか?
FARPROC EnumDisplayDevices;
HINSTANCE hInstUser32;
DISPLAY_DEVICE DispDev;
char szSaveDeviceName[32];
BOOL bRet = TRUE;
hInstUser32 = LoadLibrary("User32.DLL");
if (!hInstUser32) return FALSE;
// Get the address of the EnumDisplayDevices function
EnumDisplayDevices = (FARPROC)GetProcAddress(hInstUser32,"EnumDisplayDevicesA");
if (!EnumDisplayDevices) {
FreeLibrary(hInstUser32);
return FALSE;
}
ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE);
// After the first call to EnumDisplayDevices,
// DispDev.DeviceString is the adapter name
while (EnumDisplayDevices(NULL, nDeviceIndex++, &DispDev, 0)) {
//getdevice
}
FreeLibrary(hInstUser32);
return bRet;