我们可以通过API用编程的方式切屏,用到的API:ChangeDisplaySettingsEx
旋转90度代码如下:
DEVMODE devmode = {0};
devmode.dmSize = sizeof(DEVMODE);
devmode.dmDisplayOrientation = DMDO_90; //可变 DMDO_0 DMDO_180 DMDO_270
devmode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &devmode, NULL, 0, NULL);
取得当前模式的代码如下:
DEVMODE devmode = {0};
devmode.dmSize = sizeof(DEVMODE);
devmode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &devmode, 0, CDS_TEST, NULL);
如果你想阻止屏幕的自动切换,就可以在用如下代码完成:
case WM_SIZE:
case WM_SETTINGCHANGE:
{
DEVMODE devmode = {0};
devmode.dmSize = sizeof(DEVMODE);
devmode.dmDisplayOrientation = DMDO_90; //可变 DMDO_0 DMDO_180 DMDO_270
devmode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &devmode, NULL, 0, NULL);
}
break;