0
votes

I'm trying to make an MFC window (a CDialog) go fullscreen whenever the user attempts to maximize it. The window is being used as an OpenGL context. I'm attempting to do everything inside of the CDialog::OnSize callback. Here's the code that I'm using:

void MyCDialogSubclass::OnSize(UINT action, int width, int height) {
    CDialog::OnSize(action, width, height);

    switch (action) {
        case SIZE_MAXIMIZED:
            if (GetStyle() & WS_OVERLAPPEDWINDOW) {
                MONITORINFO screen;
                screen.cbSize = sizeof(screen);
                if (GetMonitorInfo(MonitorFromWindow(GetSafeHwnd(), MONITOR_DEFAULTTOPRIMARY), &screen)) {
                    ModifyStyle(WS_OVERLAPPEDWINDOW, 0, 0);
                    width = screen.rcMonitor.right - screen.rcMonitor.left;
                    height = screen.rcMonitor.bottom - screen.rcMonitor.top;
                    SetWindowPos(&wndTop, screen.rcMonitor.left, screen.rcMonitor.top, width, height, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
                }
            }
            break;
        case SIZE_MINIMIZED:
        case SIZE_RESTORED:
            if (!(GetStyle() & WS_OVERLAPPEDWINDOW)) {
                ModifyStyle(0, WS_OVERLAPPEDWINDOW, 0);
                SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
            }
            break;
    }

    if (wglMakeCurrent(my_hdc, my_hglrc))
        my_opengl_reshape_call(width, height);
    wglMakeCurrent(NULL, NULL);
}

If I comment out the ModifyStyle() calls, everything works fine, with the obvious proviso that the window style stays normal, so there's a standard window title bar across the top of the screen that I want to get rid of. If I keep the ModifyStyle() calls and comment out the SetWindowPos() calls, the title bar and everything else disappears, but the window has a black region along the top of the screen that is the exact height of the title bar—as though it is being reserved. If I don't comment out either of the pairs of calls, as shown in the code above, the screen flickers violently. I believe it's flickering back and forth between the black region being present and not being present, but it's difficult to tell. This flickering also appears to corrupt video memory, as I get persistent artifacts in window title bars (in different applications, no less) and, once, the login picture in the Start menu was replaced with one of my OpenGL textures.

The code that I'm using is adapted from the code that Stefan linked in an answer below, from The Old New Thing, which is working better than my original code. I'm assuming this problem isn't arising from my decision not to insert code to save the window placement (per The Old New Thing), because this happens before I ever try to restore the window.

1

1 Answers

1
votes

Don't maximize the window if you want it to be full screen. Use this approach instead.