微軟有提供WinAPI可以設定顯卡的解析度,不過這樣的效果不像一般安裝完VGA Driver後,再重開機會自動保持調整設定,簡單說就是短暫的調整解析度而已,不過這對在Winpe下操作已經足夠了。
可參考以下列舉顯卡設定的程式碼,有興趣的可以參考看看。
BOOL GetCurrentDisplayResolution() { DEVMODE CurrentDpr; DEVMODE Systendpr; int i; //初始化設定 ZeroMemory(&CurrentDpr, sizeof(CurrentDpr)); CurrentDpr.dmSize = sizeof(CurrentDpr); //列舉系統當前解析度 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &CurrentDpr)) { printf("ERROR : EnumDisplaySettings failed : %d\n", GetLastError()); return FALSE; } printf(" Current | Width\t| Height| Bits | Frequency | Status\n"); printf("==================================================================\n"); //列舉系統所有支援的解析度與比對解析度 for(i = 0 ; EnumDisplaySettings(NULL, i, &Systendpr) ; i++) { //Check current resolution if((CurrentDpr.dmPelsWidth == Systendpr.dmPelsWidth) && (CurrentDpr.dmPelsHeight == Systendpr.dmPelsHeight) && (CurrentDpr.dmBitsPerPel == Systendpr.dmBitsPerPel) && (CurrentDpr.dmDisplayFrequency == Systendpr.dmDisplayFrequency)) printf(" * |"); else printf(" |"); printf ( " %d\t| %d\t| %d\t| %d\t|", Systendpr.dmPelsWidth, // X size Systendpr.dmPelsHeight, // Y size Systendpr.dmBitsPerPel, // Bpp Systendpr.dmDisplayFrequency ); // Frequency //確認解析度的狀態 switch (ChangeDisplaySettings ( &Systendpr, CDS_TEST )) { case DISP_CHANGE_SUCCESSFUL: // Success printf ( " OK\n" ); break; case DISP_CHANGE_FAILED: // Failure printf ( " Failed\n" ); break; case DISP_CHANGE_BADMODE: // Bad mode printf ( " Bad mode\n" ); break; case DISP_CHANGE_BADFLAGS: // The flags are bad printf ( " Bad flags\n" ); break; case DISP_CHANGE_RESTART: // Restart is required printf ( " Restart required\n" ); break; } } return TRUE; }
以下為設定解析度的程式碼。
BOOL CChangeDisplaySettings::SetDisplayResolution() { DEVMODE dm; //列舉目前的解析度 if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) { 修改解析度 dm.dmPelsWidth = 1920; // X size dm.dmPelsHeight = 1080; // Y size dm.dmBitsPerPel = 32; // Bpp dm.dmDisplayFrequency = 60; // Frequency dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; //Set flag //改變解析度 if (ChangeDisplaySettings(&dm, 0) != DISP_CHANGE_SUCCESSFUL) { printf("ERROR : Set display resolution failed. GetLastError = %d\n", GetLastError()); return FALSE; } printf("Set display resolution successfully\n"); } else { printf("ERROR : Enumerate display resolution failed. GetLastError = %d\n", GetLastError()); return FALSE; } return TRUE; }
沒有留言:
張貼留言