📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "shToolBar.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
//菜单命令函数消息映射
ON_COMMAND(ID_VIEW_MYTOOLBAR, OnViewMytoolbar)
//菜单检查状态更新函数消息映射
ON_UPDATE_COMMAND_UI(ID_VIEW_MYTOOLBAR, OnUpdateViewMytoolbar)
//}}AFX_MSG_MAP
//增加扩展命令和更新消息映射,利用现成MFC函数更新菜单
ON_UPDATE_COMMAND_UI(ID_VIEW_MYTOOLBAR1, CFrameWnd::OnUpdateControlBarMenu)
ON_COMMAND_EX(ID_VIEW_MYTOOLBAR1, CFrameWnd::OnBarCheck)
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()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create 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
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
/////////////////////创建用户工具条/////////////////////////
if (!m_myToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_myToolBar.LoadToolBar(IDR_MYTOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_myToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_myToolBar);
/////////////////////创建用户工具条/////////////////////////
/////////////////////创建用户工具条1/////////////////////////
if (!m_myToolBar1.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
CRect(0,0,0,0),ID_VIEW_MYTOOLBAR1) ||
!m_myToolBar1.LoadToolBar(IDR_MYTOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_myToolBar1.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_myToolBar1);
/////////////////////创建用户工具条1/////////////////////////
DockControlBarTopOf(&m_myToolBar1, &m_myToolBar); //将用户工具1置于用户工具条下面
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnViewMytoolbar()
{
//查询用户工具条当前的可见性
BOOL bVisible=m_myToolBar.GetStyle()&WS_VISIBLE;
//根据用户工具条的可见性显示或隐藏工具条
int nShow=bVisible? SW_HIDE: SW_SHOWNORMAL;
m_myToolBar.ShowWindow(nShow);
//重新显示被调整的客户区和工具条
RecalcLayout();
}
void CMainFrame::OnUpdateViewMytoolbar(CCmdUI* pCmdUI)
{
//查询用户工具条当前的可见性
BOOL bVisible=m_myToolBar.GetStyle()&WS_VISIBLE;
//根据用户工具条的可见性设置菜单项检查状态
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::DockControlBarLeftOf(CToolBar*Bar,CToolBar*LeftOf)
{// 设 置 工 具 条 并 列 停 靠 在 同 一 条 边 上
CRect rect; // 矩 形 区 域 定 义
DWORD dw;
UINT n=0;
RecalcLayout(); // 重 新 显 示
LeftOf->GetWindowRect( &rect);
rect.OffsetRect(1,0); // 设 置 偏 移 值 以 停 靠 在 同 一 边 上 面
dw=LeftOf ->GetBarStyle();
n=(dw &CBRS_ALIGN_TOP)?AFX_IDW_DOCKBAR_TOP:n;
n=(dw &CBRS_ALIGN_BOTTOM &&n==0)?AFX_IDW_DOCKBAR_BOTTOM:n;
n=(dw &CBRS_ALIGN_LEFT &&n==0)?AFX_IDW_DOCKBAR_LEFT:n;
n=(dw &CBRS_ALIGN_RIGHT &&n==0)?AFX_IDW_DOCKBAR_RIGHT:n;
DockControlBar(Bar,n, &rect);
}
void CMainFrame::DockControlBarTopOf(CToolBar*Bar,CToolBar*TopOf)
{// 设 置 工 具 条 并 列 停 靠 在 同 一 条 边 上
CRect rect; // 矩 形 区 域 定 义
DWORD dw;
UINT n=0;
RecalcLayout(); // 重 新 显 示
TopOf->GetWindowRect( &rect);
rect.OffsetRect(0,1); // 设 置 偏 移 值 以 停 靠 在 同 一 边 右 面
dw=TopOf ->GetBarStyle();
n=(dw &CBRS_ALIGN_TOP)?AFX_IDW_DOCKBAR_TOP:n;
n=(dw &CBRS_ALIGN_BOTTOM &&n==0)?AFX_IDW_DOCKBAR_BOTTOM:n;
n=(dw &CBRS_ALIGN_LEFT &&n==0)?AFX_IDW_DOCKBAR_LEFT:n;
n=(dw &CBRS_ALIGN_RIGHT &&n==0)?AFX_IDW_DOCKBAR_RIGHT:n;
DockControlBar(Bar,n, &rect);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -