Problem Going to Fullscreen
I tried implementing GameTutorials' method of going to fullscreen mode in my program and it doesn't work. Here is the code. Can someone please tell me how to fix it?
Code:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR iCmdLine, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc;
wc.hInstance = hInstance;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.style = CS_DBLCLKS;
wc.cbSize = sizeof (WNDCLASSEX);
wc.hIcon = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,0,0,LR_DEFAULTSIZE);
wc.hIconSm = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,0,0,LR_DEFAULTSIZE);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
if (!RegisterClassEx (&wc))
{
MessageBox(0,"Failed To Register Windows Class.","Error", MB_OK | MB_ICONERROR);
return 0;
}
ChangeToFullScreen(SCREEN_WIDTH, SCREEN_HEIGHT);
hWnd = CreateWindowEx (
0, szClassName, szTitle, WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
50, 50, 907, 687, NULL, NULL, hInstance, NULL);
ShowWindow (hWnd, iCmdShow);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
ChangeToFullScreen() Function:
Code:
void ChangeToFullScreen(int width, int height)
{
DEVMODE dmSettings;
memset(&dmSettings,0,sizeof(dmSettings));
if(!EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dmSettings))
{
MessageBox(NULL, "Could Not Enum Settings.", "Error", MB_OK | MB_ICONERROR);
return;
}
dmSettings.dmPelsWidth = width;
dmSettings.dmPelsHeight = height;
dmSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
int result = ChangeDisplaySettings(&dmSettings,CDS_FULLSCREEN);
if(result != DISP_CHANGE_SUCCESSFUL)
{
MessageBox(NULL, "Display Mode Not Compatible", "Error", MB_OK | MB_ICONERROR);
PostQuitMessage(0);
}
}