📄 mainfrm.cpp
字号:
//--------------------------------------
// Load general toolbar/menu parameters:
//--------------------------------------
CBCGToolBar::LoadParameters (strControlBarRegEntry);
//----------------------------------------
// Allow user-defined toolbars operations:
//----------------------------------------
InitUserToobars (strControlBarRegEntry, uiFirstUserToolBarId, uiLastUserToolBarId);
//------------------------
// Load standard toolbars:
//------------------------
m_wndToolBar.LoadState (strControlBarRegEntry);
m_wndMenuBar.LoadState (strControlBarRegEntry);
//-------------------------------------
// Load control bar states and context:
//-------------------------------------
CDockState dockState;
dockState.LoadState (CONTROL_BARS);
if (IsDockStateValid (dockState))
{
SetDockState (dockState);
}
return 0;
}
void CMainFrame::OnClose()
{
theApp.SaveLastDocs ();
if (m_bFullScreen)
FullScreenOff ();
WINDOWPLACEMENT status;
status.length = sizeof (WINDOWPLACEMENT);
GetWindowPlacement (&status);
CReg reg;
if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD_MULTI, KEY_WRITE))
{
VERIFY (reg.SaveNumber (_T ("ShowFlags"), status.flags));
VERIFY (reg.SaveNumber (_T ("ShowCmd"), status.showCmd));
VERIFY (reg.SaveNumber (_T ("Left"), status.rcNormalPosition.left));
VERIFY (reg.SaveNumber (_T ("Top"), status.rcNormalPosition.top));
VERIFY (reg.SaveNumber (_T ("Right"), status.rcNormalPosition.right));
VERIFY (reg.SaveNumber (_T ("Bottom"), status.rcNormalPosition.bottom));
}
// SaveBarState(theApp.m_pszProfileName);
CString strControlBarRegEntry = REGISTRY_ROOT;
strControlBarRegEntry += CONTROL_BARS;
//--------------------------------------
// Save general toolbar/menu parameters:
//--------------------------------------
CBCGToolBar::SaveParameters (strControlBarRegEntry);
CDockState dockState;
GetDockState (dockState);
dockState.SaveState (CONTROL_BARS);
//------------------------
// Save standard toolbars:
//------------------------
m_wndToolBar.SaveState (strControlBarRegEntry);
m_wndMenuBar.SaveState (strControlBarRegEntry);
//----------------------------
// Save user defined toolbars:
//----------------------------
SaveUserToolbars ();
//------------------
// Save user images:
//------------------
m_UserImages.Save ();
theApp.SaveCustomState ();
CBCGMDIFrameWnd::OnClose();
}
void CMainFrame::OnViewCustomize()
{
//------------------------------------
// Create a customize toolbars dialog:
//------------------------------------
CBCGToolbarCustomize* pDlgCust = new CBCGToolbarCustomize (this, TRUE /* Automatic menus scaning */);
pDlgCust->EnableUserDefinedToolbars ();
pDlgCust->Create ();
}
void CMainFrame::OnViewFullScreen()
{
if (m_bFullScreen)
FullScreenOff ();
else
FullScreenOn ();
}
void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck (m_bFullScreen);
}
void CMainFrame::OnFileCloseAll()
{
if (theApp.SaveAllModified ())
theApp.CloseAllDocuments (FALSE);
}
void CMainFrame::OnCloseWindow()
{
MDIGetActive ()->DestroyWindow ();
}
void CMainFrame::OnUpdateCloseWindow(CCmdUI* pCmdUI)
{
pCmdUI->Enable (MDIGetActive () != NULL);
}
void CMainFrame::OnNextWindow()
{
MDINext ();
}
void CMainFrame::OnUpdateNextWindow(CCmdUI* pCmdUI)
{
pCmdUI->Enable (MDIGetCount () > 1);
}
void CMainFrame::OnPrevWindow()
{
MDIPrev ();
}
void CMainFrame::OnUpdatePrevWindow(CCmdUI* pCmdUI)
{
pCmdUI->Enable (MDIGetCount () > 1);
}
//Alarm flashing until the window became focus
void CMainFrame::FlashUntilFocus ()
{
m_bGotFocus = FALSE;
BOOL bInvert = FALSE;
while (!m_bGotFocus)
{
FlashWindow (bInvert);
bInvert= !bInvert;
Sleep (500);
if (GetFocus() == this)
break;
}
FlashWindow(FALSE);
}
void CMainFrame::OnSetFocus (CWnd* pOldWnd)
{
CBCGMDIFrameWnd::OnSetFocus (pOldWnd);
m_bGotFocus = TRUE;
}
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp)
{
/*CPoint point (LOWORD (lp), HIWORD(lp));
CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CBCGPopupMenu* pPopupMenu = new CBCGPopupMenu;
pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());*/
CPoint point (LOWORD (lp), HIWORD(lp));
CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
//---------------------------------------------------------------
// Replace toolbar dummy items to the user-defined toolbar names:
//---------------------------------------------------------------
for (int i = 0; i < (int) pPopup->GetMenuItemCount ();)
{
UINT uiCmd = pPopup->GetMenuItemID (i);
if (uiCmd >= ID_VIEW_USER_TOOLBAR1 && uiCmd < ID_VIEW_USER_TOOLBAR1 + iMaxUserToolbars)
{
//-------------------------------------------------------------------
// "User toolbar" item. First check that toolbar number 'x' is exist:
//-------------------------------------------------------------------
CBCGToolBar* pToolBar = GetUserBarByIndex (uiCmd - ID_VIEW_USER_TOOLBAR1);
if (pToolBar != NULL)
{
//-----------------------------------------------------------
// Modify the current menu item text to the toolbar title and
// move next:
//-----------------------------------------------------------
CString strToolbarName;
pToolBar->GetWindowText (strToolbarName);
pPopup->ModifyMenu (i ++, MF_BYPOSITION | MF_STRING, uiCmd, strToolbarName);
}
else
{
pPopup->DeleteMenu (i, MF_BYPOSITION);
}
}
else // Not "user toolbar" item, move next
{
i ++;
}
}
CBCGPopupMenu* pPopupMenu = new CBCGPopupMenu;
pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());
return 0;
}
void CMainFrame::OnToolsViewUserToolbar (UINT uiId)
{
CBCGToolBar* pUserToolBar = GetUserBarByIndex (uiId - ID_VIEW_USER_TOOLBAR1);
if (pUserToolBar == NULL)
{
ASSERT (FALSE);
return;
}
ShowControlBar (pUserToolBar, !(pUserToolBar->GetStyle () & WS_VISIBLE), FALSE);
RecalcLayout ();
}
void CMainFrame::OnUpdateToolsViewUserToolbar (CCmdUI* pCmdUI)
{
CBCGToolBar* pUserToolBar = GetUserBarByIndex (pCmdUI->m_nID - ID_VIEW_USER_TOOLBAR1);
if (pUserToolBar == NULL)
{
pCmdUI->Enable (FALSE);
return;
}
pCmdUI->Enable ();
pCmdUI->SetCheck (pUserToolBar->GetStyle () & WS_VISIBLE);
}
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;
CBCGToolbarCustomize* pDlg = (CBCGToolbarCustomize*) lp;
ASSERT_VALID (pDlg);
// TODO: show help about page number iPageNum
return 0;
}
extern EDITPADC_CLASS LPCTSTR pszCodeNames[];
extern EDITPADC_CLASS int nCodeNames;
void CMainFrame::OnEncoding(UINT nID)
{
ASSERT_VALID (this);
ASSERT (nID >= ID_ENCODING_1);
ASSERT (nID < (UINT) (ID_ENCODING_1 + nCodeNames + 1));
CCrystalTextBuffer::m_nDefaultEncoding = nID - ID_ENCODING_1 - 1;
}
void CMainFrame::OnUpdateEncoding(CCmdUI* pCmdUI)
{
CMenu *pMenu = pCmdUI->m_pMenu ? pCmdUI->m_pMenu->GetSubMenu (0) : NULL;
if (!pMenu)
return;
for (int iEnc = 0; iEnc < 16; iEnc++)
pMenu->DeleteMenu (pCmdUI->m_nID + iEnc, MF_BYCOMMAND);
TCHAR buf[40];
LPCTSTR *pszCodeName = pszCodeNames;
iEnc = 0;
_stprintf (buf, _T("&%d %s"), iEnc++ % 10, _T ("No recoding"));
pMenu->InsertMenu (pCmdUI->m_nIndex++, MF_STRING|MF_BYPOSITION|((DWORD) CCrystalTextBuffer::m_nDefaultEncoding == pCmdUI->m_nID - ID_ENCODING_1 - 1 ? MF_CHECKED : 0), pCmdUI->m_nID, buf);
pCmdUI->m_nID++;
do
{
_stprintf (buf, _T("&%d %s"), iEnc++ % 10, *pszCodeName++);
pMenu->InsertMenu (pCmdUI->m_nIndex++, MF_STRING|MF_BYPOSITION|((DWORD) CCrystalTextBuffer::m_nDefaultEncoding == pCmdUI->m_nID - ID_ENCODING_1 - 1 ? MF_CHECKED : 0), pCmdUI->m_nID, buf);
pCmdUI->m_nID++;
}
while (*pszCodeName);
pCmdUI->m_nIndex--;
pCmdUI->m_nIndexMax = pMenu->GetMenuItemCount();
pCmdUI->m_bEnableChanged = TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame2
IMPLEMENT_DYNAMIC (CMainFrame2, CMDIFrameWnd)
BEGIN_MESSAGE_MAP (CMainFrame2, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame2)
ON_WM_CREATE ()
ON_WM_CLOSE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_VIEW_FULL_SCREEN, OnViewFullScreen)
ON_UPDATE_COMMAND_UI(ID_VIEW_FULL_SCREEN, OnUpdateViewFullScreen)
ON_COMMAND(ID_FILE_CLOSE_ALL, OnFileCloseAll)
ON_COMMAND(ID_WINDOW_CLOSE, OnCloseWindow)
ON_COMMAND(ID_WINDOW_NEXT, OnNextWindow)
ON_COMMAND(ID_WINDOW_PREV, OnPrevWindow)
ON_UPDATE_COMMAND_UI(ID_WINDOW_CLOSE, OnUpdateCloseWindow)
ON_UPDATE_COMMAND_UI(ID_WINDOW_NEXT, OnUpdateNextWindow)
ON_UPDATE_COMMAND_UI(ID_WINDOW_PREV, OnUpdatePrevWindow)
ON_COMMAND_EX_RANGE(ID_ENCODING_FIRST, ID_ENCODING_LAST, OnEncoding)
ON_UPDATE_COMMAND_UI(ID_ENCODING_FIRST, OnUpdateEncoding)
//}}AFX_MSG_MAP
// Global help commands
ON_COMMAND (ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND (ID_HELP, CMDIFrameWnd::OnHelp)
ON_COMMAND (ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
ON_COMMAND (ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
END_MESSAGE_MAP ()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame2 construction/destruction
CMainFrame2::CMainFrame2 ()
{
m_bFullScreen = false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -