# Changing resolution on Windows

## Recommended Posts

Fluffy-Bunny    120
When using win32, is it possible to switch from windowed to fullscreen mode without having to destroy and recreate the window?

##### Share on other sites
xeddiex    238
Here's one way (scroll to the bottom). Altough it does it during window creation, you could use the same technique using ShowWindow during runtime.

- xeddiex

##### Share on other sites
Fluffy-Bunny    120

What the poster, MrDoomMaster, suggests is a way to make the window cover the desktop, without changing the resolution.

What I want is a bit different so I'll be more specific. I want to switch between supported resolutions, regardless of whether in windowed or fullscreen mode, without the need to recreate the rendering context and reload all my textures.

Is that possible and how?

EDIT: For example, to switch from windowed 800x600 to fullscreen 1024x768, from windowed 800x600 to windowed 1024x768, and so on.

##### Share on other sites
__ODIN__    479
Here's one path:

bool	Win32Application::SetResolution(unsigned int Width, unsigned int Height, unsigned int Depth){	DEVMODE device_mode;	memset(&device_mode, 0, sizeof(DEVMODE));	device_mode.dmSize = sizeof(DEVMODE);	device_mode.dmPelsWidth  = Width;	device_mode.dmPelsHeight = Height;	device_mode.dmBitsPerPel = Depth;	device_mode.dmFields     = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;	long Res = ChangeDisplaySettings(&device_mode, CDS_FULLSCREEN);	return Res == DISP_CHANGE_SUCCESSFUL;}

This one would be okay to call from Windowed mode. If you're explicity running fullscreen (DX), then you'll need to do a Device Reset instead.

Good luck,

Allan

##### Share on other sites
Fluffy-Bunny    120
Ok, I've been using a very similar code segment in the initialisation function and I did try to isolate it in the same way. Moreover, it did change the resolution of the desktop but my window was unaffected (e.g. the window had same dimensions as before, upper left corner was at the same coordinates, etc.)

##### Share on other sites
Fluffy-Bunny    120
The following is an excerpt from the initialisation function. I have removed all error checking and renamed variables where appropriate to make it more readable.

wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;wc.lpfnWndProc = (WNDPROC) WndProc;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hInstance = hInstance;wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );wc.hCursor = LoadCursor( NULL, IDC_ARROW );wc.hbrBackground = NULL;wc.lpszMenuName = NULL;wc.lpszClassName = title;RegisterClass( &wc );style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;exstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;AdjustWindowRectEx( &windowRect, style, FALSE, exstyle );hWnd = CreateWindowEx( exstyle, classTitle, title, style, x, y, ... ); // etcSetupOpenGL( ... ); /* here I pass a ptr to a struct */ShowWindow( hWnd, SW_SHOW );SetForegroundWindow( hWnd );SetFocus( hWnd );

If I use ODIN's code as is, I get the problem I described above. The desktop's resolution changes, but my window is unaffected.

This is not the only API where I've encountered this problem. GLUT's game mode will destroy the current window (and OGL rendering context) and create a new one with the specified resolution, thus forcing me to reload all my textures.

Any help will be appreciated.

##### Share on other sites
Guest Anonymous Poster
ChangeDisplaySettings only affects the display, not the windows being displayed. use MoveWindow or SetWindowPos to change the location/extents of a window after calling ChangeDisplaySettings. and as long as the pixel format does not change there should be no need to change the rendering context.

##### Share on other sites
Fluffy-Bunny    120
Thanks AP.

MoveWindow/SetWindowPos work fine but the window's title bar and the desktop's taskbar are visible. How can I remove them?

Is there a function to set the window's style once it's been created?

##### Share on other sites
Endurion    5407
Yes, use SetWindowLong with GWL_style and GWL_EXstyle to set both styles. For stability sakes get the old value with GetWindowLong, modify the style to your needs and set the new value.

If you're modifying the border or caption styles, make sure to call SetWindowPos with SWP_FRAMECHANGED set after modifying the styles.

##### Share on other sites
Fluffy-Bunny    120
After the call to ChangeDisplaySettings, I do the following:

SetWindowLong( hWnd, GWL_style, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
SetWindowLong( hWnd, GWL_EXstyle, WS_EX_APPWINDOW );
SetWindowPos( hWnd, HWND_TOP, 0, 0, width, height, SWP_SHOWWINDOW );

Results are identical to those of my previous implementation, only this time the rendering context remains intact. I'll keep in mind the bit about pixel format that AP told us about.

danke und fröhliche Ostern <Babel> ;)