Jump to content
  • Advertisement
Sign in to follow this  

Changing resolution on Windows

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thanks for the reply.

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 this post

Link to post
Share on other sites
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;

long Res = ChangeDisplaySettings(&device_mode, CDS_FULLSCREEN);

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,


Share this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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.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 );


AdjustWindowRectEx( &windowRect, style, FALSE, exstyle );

hWnd = CreateWindowEx( exstyle, classTitle, title, style, x, y, ... ); // etc
SetupOpenGL( ... ); /* 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 this post

Link to post
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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
After the call to ChangeDisplaySettings, I do the following:

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> ;)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!