// MainFrm.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "Grep.h" #include "GrepView.h" #include "SearchOptions.h" #include "MainFrm.h" #include "SearchThread.h" #include "DialogSettings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define TID_REFRESH 100 ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_CLOSE() ON_COMMAND(ID_VIEW_OPTIONSPANE, OnViewOptionspane) ON_COMMAND(ID_VIEW_SETTINGS, OnViewSettings) //}}AFX_MSG_MAP ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize) ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify) ON_MESSAGE_VOID(WM_SEARCHFINISHED, OnFindDone) ON_WM_TIMER() ON_XTP_CREATECONTROL() ON_UPDATE_COMMAND_UI(ID_APPTHEME, OnThemeUpdate) ON_COMMAND_RANGE(ID_THEMEOFFICE2016_COLORFUL_ACCESS, ID_THEMEOFFICE2016_BLACK_WORD, OnThemeChanged) ON_UPDATE_COMMAND_UI_RANGE(ID_THEMEOFFICE2016_COLORFUL_ACCESS, ID_THEMEOFFICE2016_BLACK_WORD, OnUpdateThemeChanged) 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() { // get path of executable TCHAR szBuff[_MAX_PATH]; VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuff, _MAX_PATH)); LPTSTR lpszExt = _tcsrchr(szBuff, '.'); lstrcpy(lpszExt, _T(".xml")); m_strIniFileName = szBuff; m_pSearchThread = NULL; m_nTimer = 0; g_settings.LoadSettings(); m_nCurrentThemeID = ID_THEMEOFFICE2016_COLORFUL_WORD; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // Create Status bar. // Important: All control bars including the Status Bar // must be created before CommandBars.... 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 } // Initialize the command bars if (!InitCommandBars()) return -1; // Get a pointer to the command bars object. CXTPCommandBars* pCommandBars = GetCommandBars(); if (pCommandBars == NULL) { TRACE0("Failed to create command bars object.\n"); return -1; // fail to create } // Add the menu bar CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME); if (pMenuBar == NULL) { TRACE0("Failed to create menu bar.\n"); return -1; // fail to create } // Create ToolBar CXTPToolBar* pToolBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop); if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME, FALSE)) { TRACE0("Failed to create toolbar\n"); return -1; } pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_NEW, ID_FILE_NEW, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_OPEN, ID_FILE_OPEN, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_SAVE, ID_FILE_SAVE, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_SAVE_AS, ID_FILE_SAVE_AS, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_CUT, ID_EDIT_CUT, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_COPY, ID_EDIT_COPY, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_PASTE, ID_EDIT_PASTE, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_UNDO, ID_EDIT_UNDO, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_PRINT, ID_FILE_PRINT, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_PRINT_PREVIEW, ID_FILE_PRINT_PREVIEW, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_PRINT_SETUP, ID_FILE_PRINT_SETUP, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_ABOUT, ID_APP_ABOUT, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_EXIT, ID_APP_EXIT, XTP_DPI_X(16)); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_NEW, ID_FILE_NEW, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_OPEN, ID_FILE_OPEN, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_SAVE, ID_FILE_SAVE, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_SAVE_AS, ID_FILE_SAVE_AS, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_CUT, ID_EDIT_CUT, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_COPY, ID_EDIT_COPY, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_PASTE, ID_EDIT_PASTE, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_UNDO, ID_EDIT_UNDO, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_PRINT, ID_FILE_PRINT, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_PRINT_PREVIEW, ID_FILE_PRINT_PREVIEW, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_PRINT_SETUP, ID_FILE_PRINT_SETUP, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_ABOUT, ID_APP_ABOUT, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_EXIT, ID_APP_EXIT, XTP_DPI_X(16), xtpImageDisabled); pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault); // Load the previous state for toolbars and menus. LoadCommandBars(_T("CommandBars")); // Initialize the docking pane manager and set the // initial them for the docking panes. Do this only after all // control bars objects have been created and docked. m_paneManager.InstallDockingPanes(this); if (theApp.m_hModule2016.GetModuleState() == CXTPModuleHandle::xtpModLoaded) { CXTPRegistryManager regMgr; int nThemeID = regMgr.GetProfileInt(_T("Settings"), _T("ApplicationTheme"), ID_THEMEOFFICE2016_COLORFUL_WORD); OnThemeChanged(nThemeID); } else { m_nCurrentThemeID = 0; m_paneManager.SetTheme(xtpPaneThemeVisualStudio2008); m_paneManager.SetAlphaDockingContext(TRUE); m_paneManager.SetShowDockingContextStickers(TRUE); m_paneManager.SetShowContentsWhileDragging(TRUE); } // Create docking panes. CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(IDR_PANE_OPTIONS, CRect(0, 0, 200, 120), xtpPaneDockLeft); pwndPane1->SetMinTrackSize(CSize(177, 0)); CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings")); if (px.LoadFromFile(m_strIniFileName)) { CXTPPropExchangeSection pxCommandBars(px.GetSection(_T("CommandBars"))); XTP_COMMANDBARS_PROPEXCHANGE_PARAM param; param.bSerializeControls = TRUE; GetCommandBars()->DoPropExchange(&pxCommandBars, ¶m); CXTPPropExchangeSection pxDockingPane(px.GetSection(_T("DockingPane"))); CXTPDockingPaneLayout layoutNormal(&m_paneManager); if (layoutNormal.DoPropExchange(&pxDockingPane)) { m_paneManager.SetLayout(&layoutNormal); } CXTPPropExchangeSection pxOptions(px.GetSection(_T("Options"))); GetSearchOptions()->DoPropExchange(&pxOptions); } return 0; } void CMainFrame::OnClose() { if (m_pSearchThread) { m_pSearchThread->m_bCancel = TRUE; WaitForSingleObject(m_pSearchThread->m_hThread, INFINITE); m_pSearchThread = NULL; } CXTPPropExchangeXMLNode px(FALSE, 0, _T("Settings")); if (px.OnBeforeExchange()) { CXTPPropExchangeSection pxCommandBars(px.GetSection(_T("CommandBars"))); XTP_COMMANDBARS_PROPEXCHANGE_PARAM param; param.bSerializeControls = TRUE; param.bSaveOriginalControls = FALSE; GetCommandBars()->DoPropExchange(&pxCommandBars, ¶m); CXTPPropExchangeSection pxDockingPane(px.GetSection(_T("DockingPane"))); CXTPDockingPaneLayout layoutNormal(&m_paneManager); m_paneManager.GetLayout(&layoutNormal); layoutNormal.DoPropExchange(&pxDockingPane); CXTPPropExchangeSection pxOptions(px.GetSection(_T("Options"))); GetSearchOptions()->DoPropExchange(&pxOptions); px.SaveToFile(m_strIniFileName); } CFrameWnd::OnClose(); } XTPControlTheme CMainFrame::GetCustomizeDialogTheme() { XTPControlTheme controlTheme = xtpControlThemeDefault; XTPPaintTheme commandBarsTheme = GetCommandBars()->GetPaintManager()->GetCurrentTheme(); switch (commandBarsTheme) { case xtpThemeResource: controlTheme = xtpControlThemeResource; break; case xtpThemeRibbon: controlTheme = xtpControlThemeResource; break; // case xtpThemeOffice2013: case xtpThemeOffice2016: controlTheme = xtpControlThemeOffice2016; break; case xtpThemeVisualStudio2015: controlTheme = xtpControlThemeVisualStudio2015; break; default: controlTheme = xtpControlThemeDefault; break; } return controlTheme; } void CMainFrame::OnCustomize() { // Get a pointer to the command bars object. CXTPCommandBars* pCommandBars = GetCommandBars(); if (pCommandBars != NULL) { // Instanciate the customize dialog object. CXTPCustomizeSheet dlg(pCommandBars); dlg.SetTheme(GetCustomizeDialogTheme()); // Add the options page to the customize dialog. CXTPCustomizeOptionsPage pageOptions(&dlg); dlg.AddPage(&pageOptions); // Add the commands page to the customize dialog. CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage(); pCommands->AddCategories(IDR_MAINFRAME); // Use the command bar manager to initialize the // customize dialog. pCommands->InsertAllCommandsCategory(); pCommands->InsertBuiltInMenus(IDR_MAINFRAME); pCommands->InsertNewMenuCategory(); // Dispaly the dialog. dlg.DoModal(); } } LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam) { if (wParam == XTP_DPN_SHOWWINDOW) { CXTPDockingPane* pPane = (CXTPDockingPane*)lParam; if (!pPane->IsValid()) { switch (pPane->GetID()) { case IDR_PANE_OPTIONS: { CWnd* pView = pPane->AttachView(this, RUNTIME_CLASS(CSearchOptionsView)); if (pView && ::IsWindow(pView->m_hWnd)) { pView->SendMessage(WM_INITIALUPDATE); CSearchOptionsView* pOptionsView = GetSearchOptionsView(); if (pOptionsView) pOptionsView->RefreshColors(); } break; } } } return TRUE; } return FALSE; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if (!CFrameWnd::PreCreateWindow(cs)) return FALSE; cs.lpszClass = _T("XTPMainFrame"); CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME)); cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void AddComboHistory(CComboBox& cmb, CString strText, CStringList& lstHistory) { if (strText.IsEmpty()) return; int nIndex = cmb.FindString(-1, strText); if (nIndex == -1) { cmb.InsertString(0, strText); lstHistory.AddHead(strText); } } void CMainFrame::OnFindDone() { if (m_nTimer != NULL) { KillTimer(TID_REFRESH); m_nTimer = 0; } m_pSearchThread = NULL; CSearchOptionsView* pOptionsView = GetSearchOptionsView(); pOptionsView->SetSearchMode(FALSE); CXTPGridView* pView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); _ASSERTE(pView); if (!pView) return; pOptionsView->GetDlgItem(IDC_BUTTON_REPLACEALL) ->EnableWindow(pView->GetGridCtrl().GetRecords()->GetCount() > 0); pView->GetGridCtrl().Populate(); } void CMainFrame::OnCancelFind() { if (m_nTimer != NULL) { KillTimer(TID_REFRESH); m_nTimer = 0; } _ASSERTE(m_pSearchThread != NULL); m_pSearchThread->m_bCancel = TRUE; m_pSearchThread = NULL; CSearchOptionsView* pOptionsView = GetSearchOptionsView(); pOptionsView->GetDlgItem(IDC_BUTTON_REPLACEALL)->EnableWindow(FALSE); pOptionsView->SetSearchMode(FALSE); CXTPGridView* pView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); _ASSERTE(pView); if (!pView) return; pView->GetGridCtrl().Populate(); SetMessageText(_T("Canceled")); } void CMainFrame::DelayPopulate() { if (m_nTimer == 0) { m_nTimer = SetTimer(TID_REFRESH, 100, NULL); } } void CMainFrame::OnTimer(UINT_PTR nIDEvent) { CFrameWnd::OnTimer(nIDEvent); if ((nIDEvent == TID_REFRESH) && (m_nTimer != 0)) { CXTPGridView* pView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); _ASSERTE(pView); if (!pView) return; pView->GetGridCtrl().Populate(); KillTimer(TID_REFRESH); m_nTimer = 0; } } void CMainFrame::OnFindAll() { CSearchOptions* pOptions = GetSearchOptions(); _ASSERTE(pOptions); CXTPGridView* pView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); _ASSERTE(pView); if (!pView) return; pView->GetGridCtrl().GetRecords()->RemoveAll(); pView->GetGridCtrl().Populate(); ////////////////////////////////////////////////////////////////////////// m_pSearchThread = (CSearchThread*)AfxBeginThread(RUNTIME_CLASS(CSearchThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); m_pSearchThread->m_pMainFrame = this; m_pSearchThread->m_pGridControl = &pView->GetGridCtrl(); m_pSearchThread->ResumeThread(); CSearchOptionsView* pOptionsView = GetSearchOptionsView(); pOptionsView->SetSearchMode(TRUE); AddComboHistory(pOptionsView->m_cmbFind, pOptions->m_strFind, pOptions->m_lstFindHistory); AddComboHistory(pOptionsView->m_cmbReplace, pOptions->m_strReplace, pOptions->m_lstReplaceHistory); AddComboHistory(pOptionsView->m_cmbPath, pOptions->m_strPath, pOptions->m_lstPathHistory); AddComboHistory(pOptionsView->m_cmbFileTypes, pOptions->m_strFileTypes, pOptions->m_lstFileTypesHistory); } void CMainFrame::OnReplaceAll() { USES_CONVERSION; CXTPGridView* pView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); _ASSERTE(pView); if (!pView) return; CXTPGridRecords* pRecords = pView->GetGridCtrl().GetRecords(); if (!pRecords) return; int nFiles = 0; int nChanges = 0; int i; for (i = 0; i < pRecords->GetCount(); i++) { CString strPath = ((CGrepRecord*)pRecords->GetAt(i))->m_strPath; BOOL bChanged = FALSE; int nSamePathCount = 0; while (i + nSamePathCount < pRecords->GetCount() && ((CGrepRecord*)pRecords->GetAt(i + nSamePathCount))->m_strPath == strPath) { CGrepRecord* pRecord = ((CGrepRecord*)pRecords->GetAt(i + nSamePathCount)); nSamePathCount++; if (pRecord->IsChanged() && pRecord->IsChecked()) { bChanged = TRUE; nChanges++; } } if (!bChanged) { i += nSamePathCount - 1; continue; } i += nSamePathCount - 1; nFiles++; } if (nFiles == 0) { AfxMessageBox(_T("There are no selected records")); return; } CString str; str.Format(_T("Are you sure you want make %i replacement(s) in %i file(s)?"), nChanges, nFiles); if (AfxMessageBox(str, MB_YESNO) != IDYES) return; for (i = 0; i < pRecords->GetCount(); i++) { CString strPath = ((CGrepRecord*)pRecords->GetAt(i))->m_strPath; int nSamePathCount = 0; BOOL bChanged = FALSE; while (i + nSamePathCount < pRecords->GetCount() && ((CGrepRecord*)pRecords->GetAt(i + nSamePathCount))->m_strPath == strPath) { CGrepRecord* pRecord = ((CGrepRecord*)pRecords->GetAt(i + nSamePathCount)); nSamePathCount++; if (pRecord->IsChanged() && pRecord->IsChecked()) { bChanged = TRUE; } } CFile file; if (!bChanged || !file.Open(strPath, CFile::modeRead)) { i += nSamePathCount - 1; continue; } DWORD dwCount = (DWORD)file.GetLength(); char* lpszFileBuffer = new char[dwCount]; file.Read(lpszFileBuffer, dwCount); file.Close(); // CFile::Rename(pRecord->m_strPath, pRecord->m_strPath + _T(".bak")); if (!file.Open(strPath, CFile::modeWrite | CFile::modeCreate)) { i += nSamePathCount - 1; delete[] lpszFileBuffer; continue; } long nTail = 0; int k = 0; for (int j = 0; j < nSamePathCount; j++) { CGrepRecord* pRecord = ((CGrepRecord*)pRecords->GetAt(i + j - k)); if (pRecord->IsChecked()) { file.Write(lpszFileBuffer + nTail, pRecord->m_nIndex - nTail); if (!pRecord->m_strReplace.IsEmpty()) { file.Write(T2A((LPTSTR)(LPCTSTR)(pRecord->m_strReplace)), pRecord->m_strReplace.GetLength()); } nTail = pRecord->m_nIndex + pRecord->m_nLength; pRecords->RemoveAt(i + j - k); k++; } } i += nSamePathCount - k - 1; file.Write(lpszFileBuffer + nTail, dwCount - nTail); file.Close(); delete[] lpszFileBuffer; } pView->GetGridCtrl().Populate(); } CSearchOptionsView* CMainFrame::GetSearchOptionsView() { CXTPDockingPane* pPane = m_paneManager.FindPane(IDR_PANE_OPTIONS); if (!pPane) return 0; CWnd* pWnd = pPane->GetChild(); if (!pWnd) return 0; return (CSearchOptionsView*)pWnd->GetDescendantWindow(AFX_IDW_PANE_FIRST); } void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState) { // Toggle CommandBars GetCommandBars()->OnSetPreviewMode(bPreview); // Toggle Docking Panes. m_paneManager.OnSetPreviewMode(bPreview); CFrameWnd::OnSetPreviewMode(bPreview, pState); } void CMainFrame::OnViewOptionspane() { m_paneManager.ShowPane(IDR_PANE_OPTIONS); } void CMainFrame::OnViewSettings() { CDialogSettings sd; sd.DoModal(); } void CMainFrame::OnThemeChanged(UINT nTheme) { if (m_nCurrentThemeID == 0) return; m_nCurrentThemeID = nTheme; CXTPRegistryManager regMgr; regMgr.WriteProfileInt(_T("Settings"), _T("ApplicationTheme"), m_nCurrentThemeID); CXTPCommandBars* pCommandBars = GetCommandBars(); _ASSERTE(pCommandBars); XTPPaintTheme nXTPTheme = xtpThemeOffice2013; XTPDockingPanePaintTheme nXTPPaneTheme = xtpPaneThemeOffice2013; HMODULE hModule = theApp.m_hModule2016; LPCTSTR lpszINI = xtpIniOffice2016WordColorful; switch (nTheme) { case ID_THEMEOFFICE2016_COLORFUL_ACCESS: lpszINI = xtpIniOffice2016AccessColorful; break; case ID_THEMEOFFICE2016_COLORFUL_EXCEL: lpszINI = xtpIniOffice2016ExcelColorful; break; case ID_THEMEOFFICE2016_COLORFUL_ONENOTE: lpszINI = xtpIniOffice2016OneNoteColorful; break; case ID_THEMEOFFICE2016_COLORFUL_OUTLOOK: lpszINI = xtpIniOffice2016OutlookColorful; break; case ID_THEMEOFFICE2016_COLORFUL_POWERPOINT: lpszINI = xtpIniOffice2016PowerPointColorful; break; case ID_THEMEOFFICE2016_COLORFUL_PUBLISHER: lpszINI = xtpIniOffice2016PublisherColorful; break; case ID_THEMEOFFICE2016_COLORFUL_WORD: lpszINI = xtpIniOffice2016WordColorful; break; case ID_THEMEOFFICE2016_WHITE_ACCESS: lpszINI = xtpIniOffice2016AccessWhite; break; case ID_THEMEOFFICE2016_WHITE_EXCEL: lpszINI = xtpIniOffice2016ExcelWhite; break; case ID_THEMEOFFICE2016_WHITE_ONENOTE: lpszINI = xtpIniOffice2016OneNoteWhite; break; case ID_THEMEOFFICE2016_WHITE_OUTLOOK: lpszINI = xtpIniOffice2016OutlookWhite; break; case ID_THEMEOFFICE2016_WHITE_POWERPOINT: lpszINI = xtpIniOffice2016PowerPointWhite; break; case ID_THEMEOFFICE2016_WHITE_PUBLISHER: lpszINI = xtpIniOffice2016PublisherWhite; break; case ID_THEMEOFFICE2016_WHITE_WORD: lpszINI = xtpIniOffice2016WordWhite; break; case ID_THEMEOFFICE2016_DARKGRAY_ACCESS: lpszINI = xtpIniOffice2016AccessDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_EXCEL: lpszINI = xtpIniOffice2016ExcelDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_ONENOTE: lpszINI = xtpIniOffice2016OneNoteDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_OUTLOOK: lpszINI = xtpIniOffice2016OutlookDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_POWERPOINT: lpszINI = xtpIniOffice2016PowerPointDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_PUBLISHER: lpszINI = xtpIniOffice2016PublisherDarkGray; break; case ID_THEMEOFFICE2016_DARKGRAY_WORD: lpszINI = xtpIniOffice2016WordDarkGray; break; case ID_THEMEOFFICE2016_BLACK_ACCESS: lpszINI = xtpIniOffice2016AccessBlack; break; case ID_THEMEOFFICE2016_BLACK_EXCEL: lpszINI = xtpIniOffice2016ExcelBlack; break; case ID_THEMEOFFICE2016_BLACK_ONENOTE: lpszINI = xtpIniOffice2016OneNoteBlack; break; case ID_THEMEOFFICE2016_BLACK_OUTLOOK: lpszINI = xtpIniOffice2016OutlookBlack; break; case ID_THEMEOFFICE2016_BLACK_POWERPOINT: lpszINI = xtpIniOffice2016PowerPointBlack; break; case ID_THEMEOFFICE2016_BLACK_PUBLISHER: lpszINI = xtpIniOffice2016PublisherBlack; break; case ID_THEMEOFFICE2016_BLACK_WORD: lpszINI = xtpIniOffice2016WordBlack; break; default: lpszINI = xtpIniOffice2016WordColorful; } XTPResourceImages()->SetHandle(hModule, lpszINI); CXTPPaintManager::SetTheme(nXTPTheme); m_paneManager.SetTheme(nXTPPaneTheme); m_paneManager.EnableFloatingFrameTheme(TRUE); theApp.m_nControlsTheme = xtpControlThemeOffice2013; theApp.m_csPane.RefreshMetrics(nXTPPaneTheme); CSearchOptionsView* pOptionsView = GetSearchOptionsView(); if (pOptionsView) pOptionsView->RefreshColors(); m_paneManager.SetClientMargin(XTP_DPI_X(1)); m_paneManager.GetPaintManager()->m_nSplitterSize = XTP_DPI_Y(2); m_paneManager.SetAlphaDockingContext(TRUE); m_paneManager.SetShowDockingContextStickers(TRUE); m_paneManager.SetShowContentsWhileDragging(TRUE); pCommandBars->EnableFrameTheme(TRUE); pCommandBars->GetPaintManager()->m_bAutoResizeIcons = TRUE; pCommandBars->GetPaintManager()->RefreshMetrics(); CXTPGridView* pGridView = DYNAMIC_DOWNCAST(CXTPGridView, GetDescendantWindow(AFX_IDW_PANE_FIRST)); if (pGridView) { pGridView->SetTheme(xtpGridThemeOffice2013, TRUE); pGridView->GetGridCtrl().EnablePreviewMode(TRUE); } GetCommandBars()->RedrawCommandBars(); m_paneManager.RedrawPanes(); RedrawWindow(0, 0, RDW_ALLCHILDREN | RDW_INVALIDATE); } void CMainFrame::OnUpdateThemeChanged(CCmdUI* pCmdUI) { pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrentThemeID); pCmdUI->Enable(m_nCurrentThemeID != 0); } int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { if (lpCreateControl->nID == ID_APPTHEME) { CXTPControlPopup* pControl = CXTPControlPopup::CreateControlPopup(xtpControlPopup); pControl->SetFlags(xtpFlagRightAlign); CMenu mnuOptions; mnuOptions.LoadMenu(IDR_MENU_THEME); pControl->SetCommandBar(mnuOptions.GetSubMenu(0)); pControl->SetCaption(_T("Theme")); lpCreateControl->pControl = pControl; return TRUE; } return FALSE; } void CMainFrame::OnThemeUpdate(CCmdUI* pCmdUI) { pCmdUI->Enable(m_nCurrentThemeID != 0); }