Archived

This topic is now archived and is closed to further replies.

problem with ChangeDisplaySettings

This topic is 5149 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

ChangeDisplaySettings works fine for any resolution less than my desktop''s, but once I match it or go higher the taskbar is still visible. I do make sure to pass the CDS_FULLSCREEN flag. What''s wrong with it?

Share this post


Link to post
Share on other sites
Hello Raloth,

Im hoping this is some help to you... I have used this code alot and it seems to work effeciently, at least for what im programming;

#include <windows.h>

void changeRes ( int width, int height, int bits ) {
DEVMODE dmScreenSettings;
memset( &dmScreenSettings, 0, sizeof(dmScreenSettings) );
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

if ( ChangeDisplaySettings(&dmScreenSettings, CDS_UPDATEREGISTRY|CDS_GLOBAL) != DISP_CHANGE_SUCCESSFUL ) {
MessageBox( NULL, "Could Not Change Resolution","Could Not Change...", MB_OK|MB_ICONEXCLAMATION );
ChangeDisplaySettings( NULL, 0 );
}
}

// How to use function, ex: Setting resolution to 1024x768 - 16bits
changeRes( 1024, 768, 16 );

// How to set res back to original settings
ChangeDisplaySettings( NULL, 0 );

Also, I use the flag(s) "CDS_UPDATEREGISTRY" and "CDS_GLOBAL" to make sure Windows updates the registry to the new res and so forth. You can learn more about these flags here: CDS Flags

I Hope this helps.

- [BDS]StackOverflow


BlueDev Studios

[edited by - BlueDev on November 6, 2003 8:46:34 PM]
	if(fullscreen) {
DEVMODE settings;
memset(&settings,0,sizeof(settings));
settings.dmSize = sizeof(settings);
settings.dmPelsWidth = width;
settings.dmPelsHeight = height;
settings.dmBitsPerPel = bitdepth;
settings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&settings,CDS_FULLSCREEN);
}
Notice the similarities . I looked all over the MSDN before posting this topic and found nothing...

[edited by - Raloth on November 6, 2003 8:47:58 PM]

Share this post


Link to post
Share on other sites
Yes,

All seems the same besides the main CDS line - ChangeDisplaySettings... The CDS_FULLSCREEN is mainly used for gaming and when background, taskbars, and the alike are not seen. If you are trying to switch the res for your desktop you'll have to set different flags besides CDS_FULLSCREEN, for instance CDS_GLOBAL and CDS_UPDATEREGISTRY.

Your line: ChangeDisplaySettings(&settings,CDS_FULLSCREEN);

Your (new) line: ChangeDisplaySettings(&settings, CDS_UPDATEREGISTRY|CDS_GLOBAL);

If I am not understanding quite what you mean please let me know.

- [BDS]StackOverflow

[edited by - BlueDev on November 6, 2003 8:50:38 PM]

Share this post


Link to post
Share on other sites
Edit: Ok, sometimes it has to do with how you are creating your window... Are you using NeHe's base code or your own, and if so what does it look like.

Example of NeHe's code:

	if (fullscreen)												// Are We Still In Fullscreen Mode?

{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style

dwStyle=WS_POPUP; // Windows Style

ShowCursor(FALSE); // Hide Mouse Pointer

}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style

dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style

}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size


// Create The Window

if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window

"OpenGL", // Class Name

title, // Window Title

dwStyle | // Defined Window Style

WS_CLIPSIBLINGS | // Required Window Style

WS_CLIPCHILDREN, // Required Window Style

0, 0, // Window Position

WindowRect.right-WindowRect.left, // Calculate Window Width

WindowRect.bottom-WindowRect.top, // Calculate Window Height

NULL, // No Parent Window

NULL, // No Menu

hInstance, // Instance

NULL))) // Dont Pass Anything To WM_CREATE

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

Full Tutorial can be found here: NeHe Lesson 1

Hope this helps.

- [BDS]StackOverflow

[edited by - BlueDev on November 6, 2003 9:03:39 PM]

Share this post


Link to post
Share on other sites
I was able to hack it in by adding WS_EX_TOPMOST but I would rather not do that. It really messes up alt+tab as well as other things. Doesn''t anyone know?

Share this post


Link to post
Share on other sites
Sorry about the formatting.....but I hope it helps any
I tested this out to see if I got the same problem but it works.
I use this in my game.

WINDOW_WIDTH = 1280;
WINDOW_HEIGHT = 1024;
BITS_PER_PIXEL = 32;

WNDCLASS g_WndCls;
memset(&g_WndCls,0,sizeof(WNDCLASS));
g_WndCls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
g_WndCls.hCursor = (HCURSOR)LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW));
g_WndCls.hInstance = hInstance;
g_WndCls.lpfnWndProc = TheWindowProc;
g_WndCls.lpszClassName = WINDOWCLASSNAME;
g_WndCls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
RegisterClass(&g_WndCls);

// try and go fullscreen
if(fullscreen)
{
g_hWnd = CreateWindow(g_WndCls.lpszClassName, "blah",
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP, 0, 0, 800, 600,
NULL, NULL, hInstance, NULL);

DEVMODE display_mode;
memset(&display_mode, 0, sizeof(display_mode));
display_mode.dmSize = sizeof(display_mode);
display_mode.dmBitsPerPel = BITS_PER_PIXEL;
display_mode.dmPelsHeight = WINDOW_HEIGHT;
display_mode.dmPelsWidth = WINDOW_WIDTH;
display_mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&display_mode, CDS_FULLSCREEN);

ShowCursor(false);
}

ShowWindow(g_hWnd, SW_SHOW);
UpdateWindow(g_hWnd);

Share this post


Link to post
Share on other sites
Still no luck . Every computer I try it on seems to behave differently. On some the taskbar doesn''t show and on some it does. Some the screen goes all funky when I go higher than the desktop''s resolution... The resolution doesn''t go back to the desktop''s when you alt+tab either. Is DirectX the only way to get it to behave properly or something?

Share this post


Link to post
Share on other sites