Jump to content
  • Advertisement
Sign in to follow this  

ChangeDisplaySettings Problems

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

I was reading the article on wrapping windows (http://www.gamedev.net/reference/articles/article1810.asp ), and thought that might be a good exercise to try. And i sort of got it working, till the point where i wanted the wrapper to change resolutions. Code Follows, I would appreciate if someone can point out the mistake i am making here. becuase i've tried that code before with out using class and namespace, and it should work but it doesn't. So i must be making a mistake somewhere.
#include <windows.h>
namespace Core
	class clsTest
		DEVMODE dmDispSet;
		DEVMODE dmOriDispSet;

		bool ChangeResolution (int w, int h, int b)
			EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dmOriDispSet );
			SecureZeroMemory(&dmDispSet, sizeof(DEVMODE));
			dmDispSet.dmPelsHeight = h;
			dmDispSet.dmPelsWidth = w;
			dmDispSet.dmBitsPerPel = b;
			dmDispSet.dmDisplayFrequency = dmOriDispSet.dmDisplayFrequency;

			if (ChangeDisplaySettings(&dmDispSet, CDS_TEST) == DISP_CHANGE_SUCCESSFUL)
				ChangeDisplaySettings(&dmDispSet, 0);
				return true;
			return false;

		void ResetResolution()
			ChangeDisplaySettings( &dmOriDispSet, 0 );
		void DoRes()
			ChangeResolution(800, 600, 32);

		void UndoRes()

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
using namespace Core;

int WINAPI WinMain(HINSTANCE hInstance, 
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, 
				   int nShowCmd)
	MSG uMsg;
	HWND g_hWnd;

	clsTest test;

	memset(&uMsg, 0, sizeof(uMsg));

	winClass.lpszClassName = "Framework";
	winClass.cbSize = sizeof(WNDCLASSEX);
	winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	winClass.lpfnWndProc = WindowProc;
	winClass.hInstance = hInstance;
	winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winClass.lpszMenuName = NULL;
	winClass.cbClsExtra = 0;
	winClass.cbWndExtra = 0;

	if (!RegisterClassEx(&winClass))
		return E_FAIL;


	g_hWnd = CreateWindowEx(NULL,
							"Framework Res change test", 
							0, 0, 800, 600,
							NULL, NULL, hInstance, 

	if (g_hWnd == NULL)
		return E_FAIL;

	ShowWindow (g_hWnd, nShowCmd);
	UpdateWindow (g_hWnd);

	while (uMsg.message != WM_QUIT)
		if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))


	//ChangeResolution(1280, 1024, 32);

	return 0;

Oh, just in case its important, I am using Visual C++ Express with Platform SDK

Share this post

Link to post
Share on other sites
Actually i did check the return value and it always returns DISP_CHANGE_SUCCESSFUL
but it doesn't change the Resolution.

I am thinking it might because of the Dualview i have set up. and for some reason it doesn't like it. although it should return DISP_CHANGE_BADDUALVIEW in which case, and it doesn't do that either.

I tried it with Dual View disabled, and it still doesn't work.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!