Thread: Problem Going to Fullscreen

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

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

  2. #2
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    When declaring the main window, put in the WS_MAXIMISE property, that should do it, or are you looking for something different? That's what I would try if I was you


  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You also need to fill the size of the DEVMODE structure.
    Code:
    dmSettings.dmSize=sizeof(dmSettings);
    Also, check the return value of ChangeDisplaySettings(), and make sure it equals DISP_CHANGE_SUCCESSFUL.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    Neither of those seemed to work. When I run it I still get the "Display Mode Not Compatible" message which means result != DISP_CHANGE_SUCCESSFUL. Anything else you can think of?

  5. #5
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    ChangeToFullScreen probably doesn't like the values you're passing as width and height.

    To go to full screen, usually you have to choose a common display setting, such as 640x480 or 800x600. Then your window's dimensions should also be 640x480 or 800x600 to fill the screen.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    That was it. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM