📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "BCGCBDotNetExample.h"
#include "MainFrm.h"
#include "BCGPTabbedControlBar.h"
#include "BCGPMiniFrameWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
const int iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_OUTPUT, OnViewOutput)
ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateViewOutput)
ON_COMMAND(ID_WINDOW_MANAGER, OnWindowManager)
ON_COMMAND(ID_HELP_KEYBOARDMAP, OnHelpKeyboardmap)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_VIEW_CLASS, OnViewClass)
ON_UPDATE_COMMAND_UI(ID_VIEW_CLASS, OnUpdateViewClass)
ON_COMMAND(ID_VIEW_RESOURCE, OnViewResource)
ON_UPDATE_COMMAND_UI(ID_VIEW_RESOURCE, OnUpdateViewResource)
ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
ON_COMMAND(ID_TOOLS_CONNECT_TO_DATABASE, OnToolsConnectToDatabase)
ON_COMMAND(ID_TOOLS_DEBUG_PROCESSES, OnToolsDebugProcesses)
ON_WM_CLOSE()
ON_UPDATE_COMMAND_UI(ID_VIEW_FULLSCREEN, OnUpdateViewFullScreen)
ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullScreen)
ON_WM_GETMINMAXINFO()
ON_WM_ACTIVATE()
//}}AFX_MSG_MAP
ON_COMMAND(ID_VIEW_CUSTOMIZE, OnViewCustomize)
ON_REGISTERED_MESSAGE(BCGM_RESETTOOLBAR, OnToolbarReset)
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_REGISTERED_MESSAGE(BCGM_CREATETOOLBAR, OnToolbarCreateNew)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
IDS_CARET_POS,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
CBCGPPopupMenu::SetForceShadow (TRUE);
m_bFullScreen = false;
m_pwndFullScreenBar = NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManagerXP));
CBCGPToolbarComboBoxButton::SetFlatMode ();
//--------------------------
// Load toolbar user images:
//--------------------------
CBCGPToolBar::EnableQuickCustomization ();
// TODO: Define your own basic commands. Be sure, that each pulldown
// menu have at least one basic command.
CList<UINT, UINT> lstBasicCoomads;
lstBasicCoomads.AddTail (ID_FILE_NEW);
lstBasicCoomads.AddTail (ID_FILE_OPEN);
lstBasicCoomads.AddTail (ID_FILE_SAVE);
lstBasicCoomads.AddTail (ID_FILE_PRINT);
lstBasicCoomads.AddTail (ID_APP_EXIT);
lstBasicCoomads.AddTail (ID_EDIT_CUT);
lstBasicCoomads.AddTail (ID_EDIT_PASTE);
lstBasicCoomads.AddTail (ID_EDIT_UNDO);
lstBasicCoomads.AddTail (ID_APP_ABOUT);
lstBasicCoomads.AddTail (ID_VIEW_TOOLBAR);
lstBasicCoomads.AddTail (ID_VIEW_CUSTOMIZE);
lstBasicCoomads.AddTail (ID_VIEW_TOOLBARS);
lstBasicCoomads.AddTail (ID_DUMMY_COMPILE);
lstBasicCoomads.AddTail (ID_DUMMY_BUILD);
lstBasicCoomads.AddTail (ID_DUMMY_GO);
lstBasicCoomads.AddTail (ID_DUMMY_EXECUTE);
lstBasicCoomads.AddTail (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION);
lstBasicCoomads.AddTail (ID_VIEW_CB_CAPTION);
lstBasicCoomads.AddTail (ID_TOOLS_MACRO);
lstBasicCoomads.AddTail (ID_WINDOW_TILE_HORZ);
CBCGPToolBar::SetBasicCommands (lstBasicCoomads);
//-----------------
// Create menu bar:
//-----------------
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 | CBRS_TOOLTIPS | CBRS_FLYBY);
//--------------------------------------------
// Menu will not take the focus on activation:
//--------------------------------------------
CBCGPPopupMenu::SetForceMenuFocus (FALSE);
//---------------------
// Create main toolbar:
//---------------------
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
}
CString strMainToolbarTitle;
strMainToolbarTitle.LoadString (IDS_MAIN_TOOLBAR);
m_wndToolBar.SetWindowText (strMainToolbarTitle);
//--------------------------------------------------------------
// Load menu items images (not placed on the standard toolbars):
//--------------------------------------------------------------
CBCGPToolBar::AddToolBarForImageCollection (IDR_MENU_IMAGES);
//-------------------
// Create status bar:
//-------------------
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
}
m_wndStatusBar.SetPaneStyle (0, SBPS_STRETCH);
//--------------------------------
// Create docking control windows:
//--------------------------------
if (!CreateDockingBars ())
{
return -1;
}
m_wndToolBar.EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndClassView.EnableDocking(CBRS_ALIGN_ANY);
m_wndResourceView.EnableDocking(CBRS_ALIGN_ANY);
m_wndResourceView2.EnableDocking(CBRS_ALIGN_ANY);
m_wndOutputView.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
EnableAutoHideBars(CBRS_ALIGN_ANY);
DockControlBar(&m_wndMenuBar);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndClassView);
CBCGPDockingControlBar* pTabbedBar = NULL;
m_wndResourceView.AttachToTabWnd (&m_wndClassView, DM_SHOW, TRUE, &pTabbedBar);
m_wndResourceView2.AttachToTabWnd (pTabbedBar, DM_SHOW, TRUE, &pTabbedBar);
DockControlBar(&m_wndOutputView);
//----------------------------------------
// Allow user-defined toolbars operations:
//----------------------------------------
InitUserToobars (NULL,
uiFirstUserToolBarId,
uiLastUserToolBarId);
//------------------------
// Enable windows manager:
//------------------------
EnableWindowsDialog (ID_WINDOW_MANAGER, _T("Windows..."), TRUE);
return 0;
}
BOOL CMainFrame::SetDefaultFont(CFont& Font, CWnd* pWnd /* = NULL */)
{
if (pWnd == NULL)
{
pWnd = this;
}
LOGFONT logFont;
HFONT hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
CDC* pDC = pWnd->GetDC();
CFont* pFont = pDC->SelectObject(CFont::FromHandle(hFont));
pDC->SelectObject(pFont);
::DeleteObject(hFont);
pFont->GetLogFont(&logFont);
CString sFontName = _T("MS Sans Serif");
CopyMemory(logFont.lfFaceName,(LPCTSTR)sFontName,(sFontName.GetLength() + 1) * sizeof(TCHAR));
logFont.lfHeight = 8;
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_NORMAL;
logFont.lfItalic = 0;
logFont.lfUnderline = 0;
logFont.lfStrikeOut = 0;
if (!Font.CreateFontIndirect(&logFont))
{
return FALSE;
}
pWnd->SetFont(&Font);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 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::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_SELECT_SKINS);
pDlgCust->EnableUserDefinedToolbars ();
//-----------------
// Setup combboxes:
//-----------------
// pDlgCust->ReplaceButton (ID_EDIT_FIND, CFindComboButton ());
CBCGPToolbarComboBoxButton comboButtonConfig (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION,
CImageHash::GetImageOfCommand (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, FALSE),
CBS_DROPDOWNLIST);
comboButtonConfig.AddItem (_T("Win32 Debug"));
comboButtonConfig.AddItem (_T("Win32 Release"));
comboButtonConfig.SelectItem (0);
pDlgCust->ReplaceButton (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, comboButtonConfig);
//-----------------------------------
// Add dropdown resources button:
//-----------------------------------
// pDlgCust->AddButton (_T("Build"), CBCGPDropDownToolbarButton (_T("Add Resource"), &m_wndToolbarResource));
//-------------------------
// Setup undo/redo buttons:
//-------------------------
// pDlgCust->ReplaceButton (ID_EDIT_UNDO, CUndoButton (ID_EDIT_UNDO, "&Undo"));
// pDlgCust->ReplaceButton (ID_EDIT_REDO, CUndoButton (ID_EDIT_REDO, "&Redo"));
pDlgCust->Create ();
}
void CMainFrame::OnToolsViewUserToolbar (UINT uiId)
{
CBCGPToolBar* pUserToolBar = GetUserBarByIndex (uiId - ID_VIEW_USER_TOOLBAR1);
if (pUserToolBar == NULL)
{
ASSERT (FALSE);
return;
}
ShowControlBar (pUserToolBar, !pUserToolBar->IsVisible (), FALSE, FALSE);
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(!IsFullScreen ());
pCmdUI->SetCheck (pUserToolBar->IsVisible ());
}
afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
{
UINT uiToolBarId = (UINT) wp;
switch (uiToolBarId)
{
case IDR_MAINFRAME:
{
// ASSERT (m_wndToolbarResource.GetSafeHwnd () != NULL);
//-----------------------------------
// Replace dropdown resources button:
//-----------------------------------
// m_wndToolBar.ReplaceButton (ID_DUMMY_INSERT_RESOURCE,
// CBCGPDropDownToolbarButton (_T("Add Resource"), &m_wndToolbarResource));
//--------------------------------------
// Replace "Find..." button by combobox:
//--------------------------------------
// m_wndToolBar.ReplaceButton (ID_EDIT_FIND, CFindComboButton ());
//-------------------------------------
// Replace "Undo" button by menubutton:
//-------------------------------------
// m_wndToolBar.ReplaceButton (ID_EDIT_UNDO, CUndoButton (ID_EDIT_UNDO, "&Undo"));
// m_wndToolBar.ReplaceButton (ID_EDIT_REDO, CUndoButton (ID_EDIT_REDO, "&Redo"));
}
break;
case IDR_BUILD:
{
//-----------------------------------------------
// Replace "Confoguration..." button by combobox:
//-----------------------------------------------
CBCGPToolbarComboBoxButton comboButton (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION,
CImageHash::GetImageOfCommand (ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, FALSE),
CBS_DROPDOWNLIST);
comboButton.AddItem (_T("Win32 Debug"));
comboButton.AddItem (_T("Win32 Release"));
comboButton.SelectItem (0);
}
break;
}
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)
{
CBCGPMDIFrameWnd::OnShowPopupMenu (pMenuPopup);
if (pMenuPopup == NULL)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -