利用windows API更改显示器的分辨率和更改双屏的显示模式

//更改显示屏的分辨率(windows8)
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));  
dmScreenSettings.dmSize = sizeof(dmScreenSettings); 
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings); 
dmScreenSettings.dmPelsWidth = 1024; 
dmScreenSettings.dmPelsHeight = 768; 
ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
system("pause");


//上述方法在windows7上不太适用,针对以上做以下更改

//设置屏幕的分辨率
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));  
dmScreenSettings.dmSize = sizeof(dmScreenSettings); 
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT|DM_BITSPERPEL;
dmScreenSettings.dmPelsWidth = 1440; 
dmScreenSettings.dmPelsHeight = 900;  
long result = ChangeDisplaySettings(&dmScreenSettings,0);
if (result == DISP_CHANGE_SUCCESSFUL)
{
MessageBox(NULL,TEXT("分辨率修改成功!"),TEXT("提示"),MB_ICONEXCLAMATION|MB_OK);
ChangeDisplaySettings(&dmScreenSettings,CDS_UPDATEREGISTRY);
}
else
{
MessageBox(NULL,TEXT("分辨率修改失败"),TEXT("提示"),MB_ICONEXCLAMATION|MB_OK);
ChangeDisplaySettings(NULL,0);
}


//更改屏幕多屏幕的显示模式 
system ("DisplaySwitch.exe /clone");  //屏幕复制
system ("DisplaySwitch.exe /extend"); //屏幕扩展
system ("DisplaySwitch.exe /internal");//仅电脑屏幕
system ("DisplaySwitch.exe /external"); //仅第二屏幕




你可能感兴趣的:(利用windows API更改显示器的分辨率和更改双屏的显示模式)