我有一个 800x600 的窗口,这是我用于切换全屏模式的代码:
void Window::SetFullscreen(bool value)
{
if(_fullscreen == value)
{
return;
}
_fullscreen = value;
if(_fullscreen)
{
SetWindowLongPtr(_window, GWL_STYLE, WS_POPUP);
SetWindowPos(_window, HWND_TOP, 0, 0, _width, _height, SWP_SHOWWINDOW);
EnumDisplaySettings(null, 0, &_devmode);
_devmode.dmSize = sizeof(_devmode);
_devmode.dmPelsWidth = _width;
_devmode.dmPelsHeight = _height;
_devmode.dmBitsPerPel = 32;
_devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&_devmode, CDS_FULLSCREEN);
}
else
{
cout<<"---"<<endl;
ChangeDisplaySettings(null, 0);
cout<<"---"<<endl;
SetWindowLongPtr(_window, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowPos(_window, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
}
}
每次我从全屏模式转到窗口模式时,ChangeDisplaySettings(null, 0); 将我的窗口大小调整为 1366x768 (wtf ??!?!),这是我的默认屏幕分辨率。我怎样才能防止这种情况?(之后将窗口大小调整回 800x600 是不可接受的选择)