给MFC应用程序加上全屏幕的功能

很多的播放器都有快捷键控制窗口以全屏幕的方式显示。给应用程序加上全屏幕的功能,并不需要很多的代码,比如给一个基于对话框的应用程序加上全屏功能只需要以下少量代码就可以工作了。

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 控制全屏和退出全屏的开关函数
void CFullScreenDlg::FullScreenView(void)
{
    RECT rectDesktop;
    WINDOWPLACEMENT wpNew;
  
    if (!IsFullScreen())
    {
        // We'll need these to restore the original state.
        GetWindowPlacement (&m_wpPrev);
  
        //Adjust RECT to new size of window
        ::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
        ::AdjustWindowRectEx(&rectDesktop, GetStyle(), FALSE, GetExStyle());
  
        // Remember this for OnGetMinMaxInfo()
        m_rcFullScreenRect = rectDesktop;
  
        wpNew = m_wpPrev;
        wpNew.showCmd =  SW_SHOWNORMAL;
        wpNew.rcNormalPosition = rectDesktop;
  
        m_bFullScreen=true;
    }
    else
    {
        // 退出全屏幕时恢复到原来的窗口状态
        m_bFullScreen=false;
        wpNew = m_wpPrev;
    }
  
    SetWindowPlacement ( &wpNew );
}
  
void CFullScreenDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
    // TODO: Add your message handler code here and/or call default
    if (IsFullScreen())
    {
        lpMMI->ptMaxSize.y = m_rcFullScreenRect.Height();
        lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
        lpMMI->ptMaxSize.x = m_rcFullScreenRect.Width();
        lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
    }
    CDialog::OnGetMinMaxInfo(lpMMI);
}
  
bool CFullScreenDlg::IsFullScreen(void)
{
    // 记录窗口当前是否处于全屏状态
    return m_bFullScreen;
}
 

猜你喜欢

转载自blog.csdn.net/smartgps2008/article/details/7646275