1

so am trying to make my window class full screen, but it's not working , it just flickers black then it does not become full screen here is the source code :-

void InitEngine::Init(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd, DesktopScreenInfo * ScreenInfo, LPSTR WindowName)
{
    mWindoClass = new WNDCLASSEX();
    ZeroMemory(mWindoClass,sizeof(WNDCLASSEX));
    if(ScreenInfo) mScreenInfo = ScreenInfo;
    else mScreenInfo = &DesktopScreen::GetScreenInfo();

    mWindoClass->cbSize        = sizeof(WNDCLASSEX);// window size
    mWindoClass->style         = CS_HREDRAW | CS_VREDRAW; // so it draw when Horizontal or Vertical change
    mWindoClass->lpfnWndProc   = WindowProc;
    mWindoClass->hInstance     = hInstance;
    mWindoClass->hCursor       = LoadCursor(NULL, IDC_ARROW); //load normal cursor
    mWindoClass->hbrBackground = (HBRUSH)COLOR_WINDOW;
    mWindoClass->lpszClassName = "PoPEngineClass";

    DEVMODE screen;
    memset(&screen,0,sizeof(screen));
    screen.dmSize = sizeof(screen);
    screen.dmPelsWidth = mScreenInfo->Width;
    screen.dmPelsHeight = mScreenInfo->Height;
    screen.dmBitsPerPel = mScreenInfo->ScreenDepth;
    screen.dmDisplayFrequency = mScreenInfo->FrameRate;
    screen.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
    ChangeDisplaySettings(&screen, CDS_FULLSCREEN);

    RegisterClassEx(mWindoClass);

    WindowHandel = CreateWindowEx(NULL , mWindoClass->lpszClassName , WindowName , WS_POPUP, 0 , 0, mScreenInfo->Width, mScreenInfo->Height, NULL, NULL, hInstance, NULL);
    ShowWindow(WindowHandel, nShowCmd);
    UpdateWindow(WindowHandel);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
Abanoub
  • 3,623
  • 16
  • 66
  • 104
  • What does ChangeDisplaySettings return? It has return codes which indicate if it was successful. Secondly have you got a simple WM_PAINT responder that paints the screen an obvious colour? – Anya Shenanigans Sep 09 '12 at 11:18

1 Answers1

0

ChangeDisplaySettings does not actually make a window full-screen - despite the perhaps misleading name of the flag. To make a window go full screen, you basically have to do a bunch of work yourself:

  • remember the old position
  • change the window style to remove the borders and titlebar
  • get the screen size, set the window's new position to cover the screen
  • and put it on top of other windows (the latter two you can do with the SetWindowPos call.)

There's a couple of answers to this same question elsewhere on SO -- but there's problems with them. Instead recommend reading Raymond Chen's blog entry on this: How do I cover the taskbar with a fullscreen window? - the difference between what he's doing any my list above is that he's creating a new window without vs modifying an existing one; which is actually a neater approach as it means you don't need to deal with remembering/restoring the old position.

ChangedisplaySetting's CDS_FULLSCREEN flag has a different meaning: the call is for changing display mode settings, not making a window fullscreen; but the flag is telling windows that the mode change is temporary, so should't be saved. For example, if an app that plays back video at a specific resolution is going full screen, it might want to change the actual screen resolution to match the video, but just so long as it is full screen. Or a OpenGL game or similar might use this to ensure it is running full-screen with a specific resolution. So it really means "change the display settings to these, but I'm doing this just because I'm going fullscreen, so don't make the change permanent'. Raymond Chan writes a bit more about this flag on his blog here. If you don't care about the screen resolution settings, and you just want your window taking up all of the screen area, then you don't need this call.

BrendanMcK
  • 14,252
  • 45
  • 54