08.07.06

Switching to fullscreen in OpenGL (MS windows)

Posted in OpenGL at 9:51 pm by Wim V

Switching between windowed mode and fullscreen is usually done by creating a new window just to change the window style. There is however an easier way to change the style without creating a new window.

//Remove the window decoration.
LONG dwStyle = GetWindowLong(hWnd, GWL_STYLE) ^ WS_OVERLAPPEDWINDOW;

//Add back the window decoration.
LONG dwStyle = GetWindowLong(hWnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW;

//Set the selected style.
SetWindowLong(hWnd, GWL_STYLE, dwStyle);

//Redraw your window.
SetWindowPos(hWnd, HWND_TOP, x, y, width, height, SWP_FRAMECHANGED);