The MFC Professional Stingray Software

MFC FAQ SNEAK PEEK #2
Our exclusive preview of Scot Wingo's upcoming additions

Q. I want to implement a 'Full screen' mode for one of my windows, how do I do it?

A. Try this . . .


void CFrame::OnViewFullScreen()
{
    if (m_bBlownUpMode)
    {
        if (!m_rNonBlownUpRect.IsRectEmpty())
        {
            m_bBlownUpMode = FALSE;
            SetWindowPos(NULL,
                m_rNonBlownUpRect.left,
                m_rNonBlownUpRect.top,
                m_rNonBlownUpRect.Width(),
                m_rNonBlownUpRect.Height(),
                SWP_NOZORDER);
        }
    }
    else
    {
        m_bBlownUpMode = TRUE;

        GetWindowRect(&m_rNonBlownUpRect);

        int x=0, y=0, cx, cy;
        GetBlownUpPosition(&x, &y);
        GetBlownUpSize(&cx, &cy);

        SetWindowPos(NULL, x, y, cx, cy, SWP_NOZORDER);
    }
}

void CFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
    CFrameWnd::OnGetMinMaxInfo(lpMMI);

    lpMMI->ptMinTrackSize=CPoint(MIN_FRAME_WIDTH, 320);
    int cx, cy;
    GetBlownUpSize(&cx, &cy);
    lpMMI->ptMaxTrackSize=CPoint(cx, cy);
}

void CFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
    if (m_bBlownUpMode)
        return ;

    CFrameWnd::OnNcLButtonDown(nHitTest, point);
}

void CFrame::GetBlownUpPosition(int *px, int* py)
{
    *px=0, *py=0;

    *px-=GetSystemMetrics(SM_CXFIXEDFRAME);
    *px-=GetSystemMetrics(SM_CXEDGE);

    *py-=GetSystemMetrics(SM_CYFIXEDFRAME);
    *py-=GetSystemMetrics(SM_CYCAPTION);
    *py-=GetSystemMetrics(SM_CYEDGE);
    *py-=GetSystemMetrics(SM_CYMENU);
}

void CFrame::GetBlownUpSize(int *pcx, int* pcy)
{
    int x, y;
    GetBlownUpPosition(&x, &y);

    *pcx=GetSystemMetrics(SM_CXSCREEN);
    *pcy=GetSystemMetrics(SM_CYSCREEN);

    *pcx+=-x*2;

    *pcy+=-y;
    *pcy+=GetSystemMetrics(SM_CYEDGE);
    *pcy+=GetSystemMetrics(SM_CYFIXEDFRAME);
}

-- Dicky Singh



This tip is provided for instructional purposes, and is released to the public domain. No claim of ownership is made. Use it at your own risk. No warranties are expressed or implied. The resulting program may not be fully functional. No animals were harmed in the making of this tip.


Comments? Speak up!

| Past FAQ Tips | Latest FAQ Document | Home |