📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "tools.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_CUSTOMIZE, OnCustomize)
ON_NOTIFY(TBN_QUERYINSERT,AFX_IDW_TOOLBAR,NotifyQI)
ON_NOTIFY(TBN_QUERYDELETE,AFX_IDW_TOOLBAR,NotifyQI)
ON_NOTIFY(TBN_GETBUTTONINFO,AFX_IDW_TOOLBAR,NotifyInfo)
ON_NOTIFY(TBN_RESET,AFX_IDW_TOOLBAR,NotifyReset)
ON_NOTIFY(TBN_TOOLBARCHANGE,AFX_IDW_TOOLBAR,NotifyChange)
//}}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()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Setting CCS_ADJUSTABLE here doesn't seem to work
if (!m_wndToolBar.Create(this,WS_CHILD | WS_VISIBLE |
CBRS_TOP| CCS_ADJUSTABLE|CCS_ADJUSTABLE) ||
!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: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC ) ;
// 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);
// Make adjustable
::SetWindowLong(m_wndToolBar.GetToolBarCtrl().m_hWnd,GWL_STYLE,
m_wndToolBar.GetToolBarCtrl().GetStyle()|CCS_ADJUSTABLE);
// Restore saved state of toolbar
RestoreTBState();
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
// Handle QueryInsert and Delete as always true
void CMainFrame::NotifyQI(NMHDR *hdr,LRESULT *res)
{
*res=(LRESULT)TRUE;
}
void CMainFrame::NotifyChange(NMHDR *hdr,LRESULT *res)
{
SaveTBState(); // save all changes
}
void CMainFrame::NotifyReset(NMHDR *hdr,LRESULT *res)
{
m_wndToolBar.LoadToolBar(IDR_MAINFRAME); // put old toolbar up
RecalcLayout();
}
void CMainFrame::NotifyInfo(NMHDR *hdr, LRESULT *res)
{
// The intent here is for you to supply info on all buttons even if they
// don't appear in the bar right now
// That's great, but hard to do for MFC since the buttons are locked up
// in a resource.
// My answer: just load whatever buttons are there, if you want more, reset
// the bar and start over
TBNOTIFY *nfy=(TBNOTIFY *)hdr;
int n=nfy->iItem;
*res=(n<=m_wndToolBar.GetCount());
if (*res) m_wndToolBar.GetToolBarCtrl().GetButton(n,&nfy->tbButton);
//MFC Tool bars don't usually have text so no need to put it in
}
// Restore TB from registry
void CMainFrame::RestoreTBState()
{
CWinApp *app=AfxGetApp();
int n=app->GetProfileInt("Toolbar","Count",0);
if (n==0) return;
m_wndToolBar.SetButtons(NULL,n);
int i;
for (i=0;i<n;i++)
{
int cmd,style,image;
CString tag,root="TBTN%s%d";
tag.Format(root,"CMD",i);
cmd=app->GetProfileInt("Toolbar",tag,0);
tag.Format(root,"STY",i);
style=app->GetProfileInt("Toolbar",tag,0);
tag.Format(root,"IMG",i);
image=app->GetProfileInt("Toolbar",tag,0);
m_wndToolBar.SetButtonInfo(i,cmd,style,image);
}
RecalcLayout();
}
// Save TB to registry
void CMainFrame::SaveTBState()
{
CWinApp *app=AfxGetApp();
int n=m_wndToolBar.GetToolBarCtrl().GetButtonCount();
app->WriteProfileInt("Toolbar","Count",n);
int i;
for (i=0;i<n;i++)
{
unsigned int cmd,style;
int image;
CString tag,root="TBTN%s%d";
m_wndToolBar.GetButtonInfo(i,cmd,style,image);
tag.Format(root,"CMD",i);
app->WriteProfileInt("Toolbar",tag,cmd);
tag.Format(root,"STY",i);
app->WriteProfileInt("Toolbar",tag,style);
tag.Format(root,"IMG",i);
app->WriteProfileInt("Toolbar",tag,image);
}
}
// Bring up customize dialog
void CMainFrame::OnCustomize()
{
m_wndToolBar.GetToolBarCtrl().Customize();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -