Sign in to follow this  

ChangeDisplaySettings Problems

This topic is 4336 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
	{
	protected:
		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;
			dmDispSet.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;

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

		void ResetResolution()
		{
			ChangeDisplaySettings( &dmOriDispSet, 0 );
		};
	public:
		void DoRes()
		{
			ChangeResolution(800, 600, 32);
		};

		void UndoRes()
		{
			ResetResolution();
		};
	};
}

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;
	WNDCLASSEX winClass;

	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;

	test.DoRes();

	g_hWnd = CreateWindowEx(NULL,
							"Framework", 
							"Framework Res change test", 
							WS_POPUP | WS_VISIBLE, 
							0, 0, 800, 600,
							NULL, NULL, hInstance, 
							NULL);

	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))
		{
			TranslateMessage(&uMsg);
			DispatchMessage(&uMsg);
		}

	}

	test.UndoRes();
	//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

This topic is 4336 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this