📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Wzd.h"
#include "WzdPrjct.h"
#include "WzdTlBar.h"
#include "WzdDFWnd.h"
#include "MainFrm.h"
#include <afxpriv.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_WM_CLOSE()
ON_COMMAND(ID_OPTIONS_PREFERENCES, OnOptionsPreferences)
ON_WM_PALETTECHANGED()
ON_WM_QUERYNEWPALETTE()
//}}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()
{
}
CMainFrame::~CMainFrame()
{
while (!m_ToolBarList.IsEmpty())
{
delete m_ToolBarList.RemoveHead();
}
}
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=(CWzdToolBar*)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;
}
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::OnClose()
{
// save all custom toolbars
SaveToolbars();
// save state of all control bars
SaveBarState("Control Bar States");
CMDIFrameWnd::OnClose();
}
void CMainFrame::OnOptionsPreferences()
{
CPropertySheet sheet(_T("Preferences"),this);
m_pToolBarPage=new CToolBarPage;
sheet.AddPage(m_pToolBarPage);
sheet.DoModal();
delete m_pToolBarPage;
}
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);
}
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;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -