I modified an OpenGL program I made so I could toggle fullscreen.
It seems to go into fullscreen just fine, but when I try to toggle back, it remains fullscreen and it just shows the titlebar. How can I get it to convert back?
Code:
HWND CreateMyWindow(LPSTR strWindowName, int width, int height, HINSTANCE hInstance, bool fullscreen)
{
HWND hWnd;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT rWindow;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WinProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW + 1);
wc.lpszClassName = "Chip8";
RegisterClass(&wc);
g_hInstance = hInstance;
rWindow.left = 0;
rWindow.right = width;
rWindow.top = 0;
rWindow.bottom = height+15;
if(fullscreen) {
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = 16;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
}
if(fullscreen) {
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
ShowCursor(FALSE);
}
else {
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU;
}
AdjustWindowRectEx(&rWindow, dwStyle, FALSE, dwExStyle);
hWnd = CreateWindowEx(dwExStyle, "Chip8", strWindowName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top, NULL, NULL, hInstance, NULL);
if(!hWnd) return NULL;
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
SetFocus(hWnd);
return hWnd;
}