📄 mainfrm.cpp
字号:
#include "..\project1\mainfrm.h"
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "IndexEditor.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CBCGPMDIFrameWnd)
const int iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;
BEGIN_MESSAGE_MAP(CMainFrame, CBCGPMDIFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_WINDOW_MANAGER, OnWindowManager)
ON_COMMAND(ID_VIEW_CUSTOMIZE, OnViewCustomize)
ON_REGISTERED_MESSAGE(BCGM_RESETTOOLBAR, OnToolbarReset)
ON_REGISTERED_MESSAGE(BCGM_TOOLBARMENU, OnToolbarContextMenu)
ON_COMMAND_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10, OnToolsViewUserToolbar)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10, OnUpdateToolsViewUserToolbar)
ON_REGISTERED_MESSAGE(BCGM_CUSTOMIZEHELP, OnHelpCustomizeToolbars)
ON_WM_DESTROY()
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 (CBCGPMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// enable Office 2003 look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2003));
//if (CBCGPToolBar::GetUserImages () == NULL)
//{
// // Load toolbar user images:
// if (!m_UserImages.Load (_T(".\\UserImages.bmp")))
// {
// TRACE(_T("Failed to load user images\n"));
// ASSERT (FALSE);
// }
// else
// {
// CBCGPToolBar::SetUserImages (&m_UserImages);
// }
//}
CBCGPToolBar::EnableQuickCustomization ();
EnableMDITabs (TRUE,TRUE,CBCGPTabWnd::LOCATION_TOP,TRUE);
// TODO: Define your own basic commands. Be sure, that each pulldown
// menu have at least one basic command.
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail (ID_VIEW_TOOLBARS);
lstBasicCommands.AddTail (ID_FILE_OPEN);
lstBasicCommands.AddTail (ID_FILE_SAVE);
lstBasicCommands.AddTail (ID_FILE_PRINT);
lstBasicCommands.AddTail (ID_APP_EXIT);
lstBasicCommands.AddTail (ID_EDIT_CUT);
lstBasicCommands.AddTail (ID_EDIT_PASTE);
lstBasicCommands.AddTail (ID_EDIT_UNDO);
lstBasicCommands.AddTail (ID_RECORD_NEXT);
lstBasicCommands.AddTail (ID_RECORD_LAST);
lstBasicCommands.AddTail (ID_APP_ABOUT);
lstBasicCommands.AddTail (ID_VIEW_TOOLBAR);
lstBasicCommands.AddTail (ID_VIEW_CUSTOMIZE);
lstBasicCommands.AddTail (ID_WINDOW_TILE_HORZ);
CBCGPToolBar::SetBasicCommands (lstBasicCommands);
if (!m_wndMenuBar.Create (this))
{
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() | CBRS_SIZE_DYNAMIC);
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
}
CString strMainToolbarTitle;
strMainToolbarTitle.LoadString (IDS_MAIN_TOOLBAR);
m_wndToolBar.SetWindowText (strMainToolbarTitle);
// TODO: Delete these three lines if you don't want the toolbar to be dockable
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndMenuBar);
DockControlBar(&m_wndToolBar);
m_wndToolBar.EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));
// Allow user-defined toolbars operations:
InitUserToobars (NULL,
uiFirstUserToolBarId,
uiLastUserToolBarId);
// Enable windows manager:
EnableWindowsDialog (ID_WINDOW_MANAGER, IDS_WINDOWS_MANAGER, TRUE);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CBCGPMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE | WS_SYSMENU;
return TRUE;
}
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CBCGPMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CBCGPMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
void CMainFrame::OnViewCustomize()
{
//------------------------------------
// Create a customize toolbars dialog:
//------------------------------------
CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (this,
TRUE /* Automatic menus scaning */,
BCGCUSTOMIZE_MENU_SHADOWS | BCGCUSTOMIZE_TEXT_LABELS |
BCGCUSTOMIZE_LOOK_2000 | BCGCUSTOMIZE_MENU_ANIMATIONS | BCGCUSTOMIZE_CONTEXT_HELP);
pDlgCust->EnableUserDefinedToolbars ();
pDlgCust->Create ();
}
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp)
{
CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp));
CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
SetupToolbarMenu (*pPopup, ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10);
CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu;
pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());
return 0;
}
void CMainFrame::OnToolsViewUserToolbar (UINT uiId)
{
CBCGPToolBar* pUserToolBar = GetUserBarByIndex (uiId - ID_VIEW_USER_TOOLBAR1);
if (pUserToolBar == NULL)
{
ASSERT (FALSE);
return;
}
ShowControlBar (pUserToolBar, !(pUserToolBar->IsVisible ()), FALSE, TRUE);
RecalcLayout ();
}
void CMainFrame::OnUpdateToolsViewUserToolbar (CCmdUI* pCmdUI)
{
CBCGPToolBar* pUserToolBar = GetUserBarByIndex (pCmdUI->m_nID - ID_VIEW_USER_TOOLBAR1);
if (pUserToolBar == NULL)
{
pCmdUI->Enable (FALSE);
return;
}
pCmdUI->Enable ();
pCmdUI->SetCheck (pUserToolBar->IsVisible ());
}
afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM /*wp*/,LPARAM)
{
// TODO: reset toolbar with id = (UINT) wp to its initial state:
//
// UINT uiToolBarId = (UINT) wp;
// if (uiToolBarId == IDR_MAINFRAME)
// {
// do something with m_wndToolBar
// }
return 0;
}
LRESULT CMainFrame::OnHelpCustomizeToolbars(WPARAM wp, LPARAM lp)
{
int iPageNum = (int) wp;
CBCGPToolbarCustomize* pDlg = (CBCGPToolbarCustomize*) lp;
ASSERT_VALID (pDlg);
// TODO: show help about page number iPageNum
return 0;
}
BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
//---------------------------------------------------------
// Replace ID_VIEW_TOOLBARS menu item to the toolbars list:
//---------------------------------------------------------
CBCGPMDIFrameWnd::OnShowPopupMenu (pMenuPopup);
if (pMenuPopup != NULL &&
pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
{
if (CBCGPToolBar::IsCustomizeMode ())
{
//----------------------------------------------------
// Don't show toolbars list in the cuztomization mode!
//----------------------------------------------------
return FALSE;
}
pMenuPopup->RemoveAllItems ();
CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
SetupToolbarMenu (*pPopup, ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10);
pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
}
return TRUE;
}
void CMainFrame::OnWindowManager()
{
ShowWindowsDialog ();
}
void CMainFrame::OnDestroy()
{
CBCGPMDIFrameWnd::OnDestroy();
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -