枚举display device

// #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <tchar.h> #include <conio.h> void CheckDisplay(); int main(int argc, char *argv[]) { CheckDisplay(); _getch(); return 0; } void CheckDisplay() { BOOL FoundSecondaryDisp = FALSE; DWORD DispNum = 0; DISPLAY_DEVICE DisplayDevice; LONG Result; int i = 0; DEVMODE defaultMode; // initialize DisplayDevice ZeroMemory(&DisplayDevice, sizeof(DisplayDevice)); DisplayDevice.cb = sizeof(DisplayDevice); // get all display devices while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) { ZeroMemory(&defaultMode, sizeof(DEVMODE)); defaultMode.dmSize = sizeof(DEVMODE); if ( !EnumDisplaySettings((LPCWSTR)DisplayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &defaultMode) ) OutputDebugString((LPCWSTR)"Store default failed/n"); if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) && !(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) { DEVMODE DevMode; ZeroMemory(&DevMode, sizeof(DevMode)); DevMode.dmSize = sizeof(DevMode); DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); //The code below shows how to re-attach the secondary displays to the desktop ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL); ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL); } // Reinit DisplayDevice just to be extra clean ZeroMemory(&DisplayDevice, sizeof(DisplayDevice)); DisplayDevice.cb = sizeof(DisplayDevice); DispNum++; } // end while for all display devices printf("Display Device Number is %d/n",DispNum); }; 

 

 

枚举display device 及 change display setting 的调用举例,供参考。

你可能感兴趣的:(null)