📄 mainfrm.cpp
字号:
// 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()
{
if (g_pProject && g_pProject->IsModified ())
{
CString sText;
sText.Format (IDS_PROJECT_NOT_SAVED, GetName (g_pProject->sPath));
int nResult = AfxMessageBox (sText, MB_YESNOCANCEL|MB_ICONQUESTION);
if (nResult == IDYES)
{
if (!theApp.SaveProject ())
return;
}
else if (nResult != IDNO)
return;
}
theApp.SaveLastDocs ();
if (m_bFullScreen)
FullScreenOff ();
WINDOWPLACEMENT status;
status.length = sizeof (WINDOWPLACEMENT);
GetWindowPlacement (&status);
CReg reg;
if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD_IDE, 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);
}
void CMainFrame::OnExplorer()
{
m_wndWorkspaceBar.ToggleExplorer ();
}
void CMainFrame::OnUpdateExplorer(CCmdUI* pCmdUI)
{
if (m_wndWorkspaceBar.IsVisible ())
{
pCmdUI->Enable (TRUE);
pCmdUI->SetCheck (m_wndWorkspaceBar.IsExplorer ());
}
else
pCmdUI->Enable (FALSE);
}
void CMainFrame::OnProject()
{
m_wndWorkspaceBar.ToggleProject ();
}
void CMainFrame::OnUpdateProject(CCmdUI* pCmdUI)
{
if (m_wndWorkspaceBar.IsVisible ())
{
pCmdUI->Enable (TRUE);
pCmdUI->SetCheck (m_wndWorkspaceBar.IsProject ());
}
else
pCmdUI->Enable (FALSE);
}
//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;
}
LONG CMainFrame::
OnOpenHere (WPARAM wParam, LPARAM lParam)
{
if (FileExist((LPCTSTR) lParam))
{
theApp.OpenDocumentFile ((LPCTSTR) lParam);
}
return 0;
}
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;
}
void CMainFrame::OnProjectNew()
{
if (theApp.NewProject ())
m_wndWorkspaceBar.PopulateProject ();
}
void CMainFrame::OnUpdateProjectNew(CCmdUI* pCmdUI)
{
pCmdUI->Enable (TRUE);
}
void CMainFrame::OnProjectOpen()
{
if (g_pProject && g_pProject->IsModified ())
{
CString sText;
sText.Format (IDS_PROJECT_NOT_SAVED, GetName (g_pProject->sPath));
int nResult = AfxMessageBox (sText, MB_YESNOCANCEL|MB_ICONQUESTION);
if (nResult == IDYES)
{
if (!theApp.SaveProject ())
return;
}
else if (nResult != IDNO)
return;
}
if (theApp.OpenProject ())
m_wndWorkspaceBar.PopulateProject ();
}
void CMainFrame::OnUpdateProjectOpen(CCmdUI* pCmdUI)
{
pCmdUI->Enable (TRUE);
}
void CMainFrame::OnProjectReload()
{
if (g_pProject && g_pProject->IsModified ())
{
CString sText;
sText.Format (IDS_PROJECT_NOT_SAVED, GetName (g_pProject->sPath));
int nResult = AfxMessageBox (sText, MB_YESNOCANCEL|MB_ICONQUESTION);
if (nResult == IDYES)
{
if (!theApp.SaveProject ())
return;
}
else if (nResult != IDNO)
return;
}
if (g_pProject)
{
if (theApp.OpenProject (g_pProject->sPath))
m_wndWorkspaceBar.PopulateProject ();
}
}
void CMainFrame::OnUpdateProjectReload(CCmdUI* pCmdUI)
{
pCmdUI->Enable (g_pProject != NULL);
}
void CMainFrame::OnProjectClose()
{
if (g_pProject && g_pProject->IsModified ())
{
CString sText;
sText.Format (IDS_PROJECT_NOT_SAVED, GetName (g_pProject->sPath));
int nResult = AfxMessageBox (sText, MB_YESNOCANCEL|MB_ICONQUESTION);
if (nResult == IDYES)
{
if (!theApp.SaveProject ())
return;
}
else if (nResult != IDNO)
return;
}
if (g_pProject)
{
m_wndWorkspaceBar.EmptyProject ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -