📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "FullScreen.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullScreen)
ON_UPDATE_COMMAND_UI(ID_VIEW_FULLSCREEN, OnUpdateViewFullScreen)
ON_WM_GETMINMAXINFO()
ON_COMMAND(ID_VIEW_BACK_TO_NORMAL, OnViewBackToNormal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bFullScreen = FALSE;
m_bWasZoomed = FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create standard toolbar\n");
return -1; // fail to create
}
if (!m_wndTBdemo.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP, IDR_DEMO_TOOLBAR) ||
!m_wndTBdemo.LoadToolBar(IDR_DEMO_TOOLBAR))
{
TRACE0("Failed to create demo toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// Mainframe docking
EnableDocking(CBRS_ALIGN_ANY);
// Standard toolbar docking
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// Demo toolbar docking
m_wndTBdemo.SetBarStyle(m_wndTBdemo.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndTBdemo.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndTBdemo, AFX_IDW_DOCKBAR_LEFT);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CMDIFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnViewFullScreen()
{
// 1 - Read the various system metrics
int cyCaption = ::GetSystemMetrics( SM_CYCAPTION );
int cxFrame = ::GetSystemMetrics( SM_CXFRAME );
int cyFrame = ::GetSystemMetrics( SM_CYFRAME );
int cxScreen = ::GetSystemMetrics( SM_CXSCREEN );
int cyScreen = ::GetSystemMetrics( SM_CYSCREEN );
int cyMenu = ::GetSystemMetrics( SM_CYMENU );
// 2 - Toggle the current full-screen mode
m_bFullScreen = !m_bFullScreen;
// 3 - Go into full-screen mode or back into normal
// Note: The following code works together with the
// OnGetMinMaxInfo() function
if( m_bFullScreen )
{
// 4 - Go from normal into full-screen mode
m_bWasZoomed = IsZoomed(); // Store current state
if( m_bWasZoomed )
{
// Go from maximized to full-screen mode
// using SetWindowPos()
SetWindowPos( NULL,
-cxFrame, -( cyFrame + cyCaption + cyMenu ),
cxScreen + 2 * cxFrame,
cyScreen + 2 * cyFrame + cyCaption + cyMenu,
SWP_NOZORDER );
}
else
{
// Go from normal to full-screen mode
// using ShowWindow()
ShowWindow( SW_SHOWMAXIMIZED );
}
}
else
{
// 5 - Restore the window to previous state
// (can be either "normal" or "maximized")
if( m_bWasZoomed )
{
// Restore to maximized state
// using SetWindowPos()
SetWindowPos( NULL,
-cxFrame, -cyFrame,
cxScreen + 2 * cxFrame,
cyScreen + 2 * cyFrame,
SWP_NOZORDER );
}
else
{
// Restore to normal state
// using ShowWindow()
ShowWindow( SW_RESTORE );
}
}
}
void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck( m_bFullScreen );
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// 1 - Read the various system metrics
int cyCaption = ::GetSystemMetrics( SM_CYCAPTION );
int cxFrame = ::GetSystemMetrics( SM_CXFRAME );
int cyFrame = ::GetSystemMetrics( SM_CYFRAME );
int cxScreen = ::GetSystemMetrics( SM_CXSCREEN );
int cyScreen = ::GetSystemMetrics( SM_CYSCREEN );
int cyMenu = ::GetSystemMetrics( SM_CYMENU );
// 2 - Let the default window proc fill
// the MINMAXINFO structure
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
if( m_bFullScreen )
{
// 3 - Full-screen MinMaxInfo
lpMMI->ptMaxPosition.y = -( cyFrame + cyCaption + cyMenu );
lpMMI->ptMaxSize.y = lpMMI->ptMaxTrackSize.y =
cyScreen + 2 * cyFrame + cyCaption + cyMenu;
}
else
{
// 4 - Normal MinMaxInfo
lpMMI->ptMaxPosition.y = -cyFrame;
lpMMI->ptMaxSize.y = lpMMI->ptMaxTrackSize.y = cyScreen + 2 * cyFrame;
}
lpMMI->ptMaxPosition.x = -cxFrame;
lpMMI->ptMaxSize.x = lpMMI->ptMaxTrackSize.x = cxScreen + 2 * cxFrame;
}
void CMainFrame::OnViewBackToNormal()
{
if( m_bFullScreen ) // Only if already in full-screen
{
// Toggle view back to normal mode
OnViewFullScreen();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -