📄 readme.wzd
字号:
/////////////////////////////////////////////////////////////////////
// Modify Stdafx.h
/////////////////////////////////////////////////////////////////////
TlBarPg.cpp -- a property page clas that allows toolbars to be created
TlBarPg.h "on-the-fly". Refer to the example on the CD for an
example dialog template for this property page.
WzdDFWnd.cpp -- a MiniFrameWnd which destroys itself when its close
WzdDFWnd.h is pressed (the normal action is to hide itself)
WzdTlBar.cpp -- a toolbar class that when destroyed, deletes itself from the
WzdTlBar.h list of custom toolbars which is maintained by the Mainframe
class
WzdPrjct.h -- a project-wide include file containing the keys for saving
custom toolbar configurations to the system registry
/////////////////////////////////////////////////////////////////////
// Modify the Mainframe Class.
/////////////////////////////////////////////////////////////////////
// 1) add the following variable and function declarations to your MainFrm.h
// Operations
public:
void LoadToolBars();
void SaveToolBars();
CList<CToolBar*,CToolBar*> *GetToolBarList(){return &m_ToolBarList;};
private:
CToolBarPage *m_pToolBarPage;
int LoadToolbars();
void SaveToolbars();
CList<CToolBar*,CToolBar*> m_ToolBarList;
// 2) delete all custom toolbar class objects in CMainFrame's destructor:
CMainFrame::~CMainFrame()
{
while (!m_ToolBarList.IsEmpty())
{
delete m_ToolBarList.RemoveHead();
}
}
// 3) create any custom toolbars saved in the system registry as follows
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create and load custom toolbars
EnableDocking(CBRS_ALIGN_ANY);
m_pFloatingFrameClass = RUNTIME_CLASS(CWzdMiniDockFrameWnd);
if (!LoadToolbars())
{
// if none, load standard toolbar(s)
CToolBar *pToolBar=(CToolBar*)new CWzdToolBar;
if (!pToolBar->Create(this) ||
!pToolBar->LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_ToolBarList.AddTail( pToolBar );
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
pToolBar->SetBarStyle(pToolBar->GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
pToolBar->EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(pToolBar);
}
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
}
// reload all bar states
LoadBarState("Control Bar States");
return 0;
}
// 4) save any custom toolbars to the system registry when application terminates
void CMainFrame::OnClose()
{
// save all custom toolbars
SaveToolbars();
// save state of all control bars
SaveBarState("Control Bar States");
CMDIFrameWnd::OnClose();
}
// 5) load custom toolbar helper function
int CMainFrame::LoadToolbars()
{
int nNumToolBars=AfxGetApp()->GetProfileInt(TOOLBAR_SUMMARY_KEY,TOOLBAR_NUM_KEY,0);
if (nNumToolBars)
{
int idc=IDC_CUSTOM_TOOLBARS;
for (int i=0;i<nNumToolBars;i++)
{
// create empty toolbar
CToolBar *pToolBar = (CToolBar*)new CWzdToolBar;
m_ToolBarList.AddTail( pToolBar );
pToolBar->Create( this, WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS, idc++);
SIZE sizeButton, sizeImage;
sizeImage.cx = BUTTON_WIDTH;
sizeImage.cy = BUTTON_HEIGHT;
sizeButton.cx = sizeImage.cx + BUTTON_XSPACING;
sizeButton.cy = sizeImage.cy + BUTTON_YSPACING;
pToolBar->SetSizes(sizeButton, sizeImage);
pToolBar->EnableDocking(CBRS_ALIGN_ANY | CBRS_FLOAT_MULTI);
// add all possible tool button bitmaps to this empty toolbar
// after first finding out how many buttons are in this bitmap
BITMAP bm;
CBitmap bitmap;
bitmap.LoadBitmap(IDR_MAINFRAME);
bitmap.GetObject( sizeof(BITMAP), &bm );
pToolBar->GetToolBarCtrl().AddBitmap(bm.bmWidth/BUTTON_WIDTH,IDR_MAINFRAME);
// create key for this toolbar
CString key;
key.Format(TOOLBAR_KEY,i);
// get number of buttons in this toolbar
int nNumButtons=AfxGetApp()->GetProfileInt(key,NUM_OF_BUTTONS_KEY,0);
// get button info and insert buttons into created toolbar
UINT k;
TBBUTTON *ptbbutton;
AfxGetApp()->GetProfileBinary(key,BUTTON_INFO_KEY,(BYTE **)&ptbbutton,&k);
for (int j=0;j<nNumButtons;j++)
{
pToolBar->GetToolBarCtrl().InsertButton(j,ptbbutton+j);
}
delete []ptbbutton;
}
}
return(nNumToolBars);
}
// 6) save custom toolbar helper function
void CMainFrame::SaveToolbars()
{
int nNumToolBars=m_ToolBarList.GetCount();
AfxGetApp()->WriteProfileInt(TOOLBAR_SUMMARY_KEY,TOOLBAR_NUM_KEY,nNumToolBars);
if (nNumToolBars)
{
int i=0;
int idc=IDC_CUSTOM_TOOLBARS;
for (POSITION pos=m_ToolBarList.GetHeadPosition();pos;i++)
{
CToolBar *pToolBar=m_ToolBarList.GetNext(pos);
// create key for this toolbar
CString key;
key.Format(TOOLBAR_KEY,i);
// give toolbar a unique, sequential ID for SaveBarState/LoadBarState
pToolBar->SetDlgCtrlID(idc++);
// write number of buttons in this toolbar
int nButtonCount=pToolBar->GetToolBarCtrl().GetButtonCount();
AfxGetApp()->WriteProfileInt(key,NUM_OF_BUTTONS_KEY,nButtonCount);
// write info on each button
TBBUTTON *ptbbutton=new TBBUTTON[nButtonCount];
for (int j=0;j<nButtonCount;j++)
{
pToolBar->GetToolBarCtrl().GetButton(j,ptbbutton+j);
}
AfxGetApp()->WriteProfileBinary(key,BUTTON_INFO_KEY,(BYTE*)ptbbutton,nButtonCount*sizeof(TBBUTTON));
delete []ptbbutton;
}
}
}
// 7) add new toolbar property page to applications preferences:
void CMainFrame::OnOptionsPreferences()
{
CPropertySheet sheet(_T("Preferences"),this);
m_pToolBarPage=new CToolBarPage;
sheet.AddPage(m_pToolBarPage);
sheet.DoModal();
delete m_pToolBarPage;
}
// 8) in the Application Class, make sure to specify a key
// (otherwise, preferences will be saved to an .ini file in the
// system directory rather then the system registry)
SetRegistryKey(COMPANY_KEY);
/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -