MFC Feature Pack applications have wrong size when restored to maximized in secondary monitor

StackOverflow https://stackoverflow.com/questions/10582068

  •  08-06-2021
  •  | 
  •  

Pregunta

I've noticed that applications developed using MFC Feature Pack (VS2008), when restored from minimized to maximized in the secondary monitor, are sized as if they were in the primary monitor, leaving space for the Windows taskbar.

I've found this behaviour on my own programs, but also in the MFC Feature Pack samples, so I guess it's some bug in the MFC Feature Pack classes.

So, for example, I build the Visual Studio sample, run it, move it to the secondary monitor, maximize it there, minimize it, restore it, and I get this:

Check the gap under the window on the secondary monitor

Is there any known workaround for this? Has it been solved for more recent versions of MFC?

UPDATE:

It seems to happen only if the secondary monitor is on the right of the main one, but not if it's on the left.

¿Fue útil?

Solución

Answering my own question, for future reference:

After further research, I've found it seems to be a bug and has already been reported to Microsoft:

This caused by the fact that CFrameImpl::OnGetMinMaxInfo uses the window rectangle to determine which monitor should be used to determine the maximized size. When the window is minimized the top-left point of the rectangle returned by GetWindowRect is (-32000, -32000). When this rectangle is used to determine the monitor the left-most monitor is returned.

It says "Resolved - It will not be fixed", so I've looked for a workaround and found this seems to work:

void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
    CMDIFrameWndEx::OnSize(nType, cx, cy);

    if (nType == SIZE_MAXIMIZED)
    {
        CRect rectWindow;
        GetWindowRect(&rectWindow);

        CRect rect(0, 0, 0, 0);

        MONITORINFO mi;
        mi.cbSize = sizeof(MONITORINFO);

        if (GetMonitorInfo(MonitorFromWindow(this->m_hWnd, MONITOR_DEFAULTTONEAREST), &mi))
        {
            rect = mi.rcWork;
        }
        else
        {
            ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
        }

        MoveWindow(rect);
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top