📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SelectToolbarOptions.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_SHAPES_TOOLBAR, OnViewShapesToolbar)
ON_UPDATE_COMMAND_UI(ID_VIEW_SHAPES_TOOLBAR, OnUpdateViewShapesToolbar)
ON_COMMAND(ID_CREATE_STANDARD_TOOLBAR, OnCreateStandardToolbar)
ON_COMMAND(ID_CREATE_SHAPES_TOOLBAR, OnCreateShapesToolbar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
///////////////////////////////////////////////////////////
// EkIsBarVisible
BOOL EkIsBarVisible( CControlBar* pBar )
{
ASSERT_VALID( pBar );
return ( ( pBar->GetStyle() & WS_VISIBLE ) != 0 );
}
///////////////////////////////////////////////////////////
// EkDockBarNextTo
void EkDockBarNextTo( CControlBar* pNewBar,
CControlBar* pDockedBar,
UINT nDockBarID = AFX_IDW_DOCKBAR_TOP )
{
ASSERT_VALID( pDockedBar );
ASSERT_VALID( pNewBar );
// 1 - Find the frame where we will dock
CFrameWnd* pFrame = pDockedBar->GetDockingFrame();
// 2 - Force MFC to compute the positions
// of the docked control bar(s)
pFrame->RecalcLayout();
// 3 - Compute rectangle of already "docked" bar
CRect rect;
pDockedBar->GetWindowRect( &rect );
// 4 - Offset the rectangle slightly to the bottom right
// so that the new bar will dock either to the right or
// to the bottom of the existing bar (depending on the
// side where this last bar is already docked)
rect.OffsetRect(1,1);
// 5 - Dock new bar to specified position
pFrame->DockControlBar( pNewBar, nDockBarID, &rect );
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_pToolBar = m_pTBshapes = NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Mainframe docking
EnableDocking(CBRS_ALIGN_ANY);
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
}
// 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::OnViewShapesToolbar()
{
ShowControlBar( m_pTBshapes, !EkIsBarVisible( m_pTBshapes ), FALSE );
}
void CMainFrame::OnUpdateViewShapesToolbar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck( EkIsBarVisible( m_pTBshapes ) );
}
/////////////////////////////////////////////////////////////////////////////
BOOL CMainFrame::CreateToolBarWithOptions( CToolBar* pBar,
UINT nIDBar,
UINT nIDResource,
CDemoDlg* pDlg,
LPCTSTR lpszName )
{
ASSERT_VALID( pBar );
pDlg->m_strName = lpszName;
pDlg->DoModal();
// 1 - Create toolbar
{
DWORD dwStyle = WS_CHILD | WS_VISIBLE;
dwStyle |= ( pDlg->m_bCreateTop ? CBRS_TOP : 0 );
dwStyle |= ( pDlg->m_bCreateBottom ? CBRS_BOTTOM : 0 );
dwStyle |= ( pDlg->m_bCreateFloating ? CBRS_FLOATING : 0 );
if( !pBar->Create(this, dwStyle, nIDBar ) ||
!pBar->LoadToolBar( nIDResource ) )
{
TRACE1( "Failed to create '%s' toolbar\n", lpszName );
return FALSE; // fail to create
}
}
// 2 - Set additional toolbar style
pBar->SetBarStyle( pBar->GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY |
( pDlg->m_bSizeDynamic ? CBRS_SIZE_DYNAMIC : 0 ) );
// 3 - Enable toolbar docking
if( pDlg->m_bEnableDocking )
{
DWORD dwStyle = 0;
dwStyle |= ( pDlg->m_bEnableTop ? CBRS_ALIGN_TOP : 0 );
dwStyle |= ( pDlg->m_bEnableBottom ? CBRS_ALIGN_BOTTOM : 0 );
dwStyle |= ( pDlg->m_bEnableLeft ? CBRS_ALIGN_LEFT : 0 );
dwStyle |= ( pDlg->m_bEnableRight ? CBRS_ALIGN_RIGHT : 0 );
dwStyle |= ( pDlg->m_bEnableAny ? CBRS_ALIGN_ANY : 0 );
dwStyle |= ( pDlg->m_bEnableFloatMulti ? CBRS_FLOAT_MULTI : 0 );
pBar->EnableDocking( dwStyle );
}
// 4 - Dock toolbar
if( pDlg->m_bDockControlBar )
{
DWORD dwStyle = 0;
dwStyle |= ( pDlg->m_bDockbarTop ? AFX_IDW_DOCKBAR_TOP : 0 );
dwStyle |= ( pDlg->m_bDockbarBottom ? AFX_IDW_DOCKBAR_BOTTOM : 0 );
dwStyle |= ( pDlg->m_bDockbarLeft ? AFX_IDW_DOCKBAR_LEFT : 0 );
dwStyle |= ( pDlg->m_bDockbarRight ? AFX_IDW_DOCKBAR_RIGHT : 0 );
DockControlBar( pBar, dwStyle );
}
// 5 - Float toolbar
if( pDlg->m_bFloatControlBar )
{
DWORD dwStyle = 0;
dwStyle |= ( pDlg->m_bFloatTop ? CBRS_ALIGN_TOP : 0 );
dwStyle |= ( pDlg->m_bFloatBottom ? CBRS_ALIGN_BOTTOM : 0 );
dwStyle |= ( pDlg->m_bFloatLeft ? CBRS_ALIGN_LEFT : 0 );
dwStyle |= ( pDlg->m_bFloatRight ? CBRS_ALIGN_RIGHT : 0 );
CRect rect;
GetWindowRect( &rect );
CPoint point( rect.left + 100, rect.top + 100 );
FloatControlBar( pBar, point, dwStyle );
}
return TRUE;
}
void CMainFrame::OnCreateStandardToolbar()
{
delete m_pToolBar; // safe with NULL pointer
m_pToolBar = new CToolBar;
RecalcLayout();
if( !CreateToolBarWithOptions( m_pToolBar,
AFX_IDW_TOOLBAR,
IDR_MAINFRAME,
&m_dlgStandard,
_T( "Standard Toolbar" ) ) )
{
return;
}
RecalcLayout();
}
void CMainFrame::OnCreateShapesToolbar()
{
delete m_pTBshapes; // safe with NULL pointer
m_pTBshapes = new CToolBar;
RecalcLayout();
if( !CreateToolBarWithOptions( m_pTBshapes,
IDR_SHAPES,
IDR_SHAPES,
&m_dlgShapes,
_T( "Shapes Toolbar" ) ) )
{
return;
}
m_pTBshapes->SetWindowText( CString( LPCSTR( IDR_SHAPES ) ) );
RecalcLayout();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -