// MainFrm.cpp : implementation of the CMainFrame class // // (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 "GaugeBrowser.h" #include "GaugeRectTracker.h" #include "GaugeBrowserDoc.h" #include "GaugeBrowserView.h" #include "PaneAssets.h" #include "PaneGauges.h" #include "MainFrm.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_CLOSE() //}}AFX_MSG_MAP ON_COMMAND(XTP_ID_CUSTOMIZE, CMainFrame::OnCustomize) ON_UPDATE_COMMAND_UI(IDR_THEME, CMainFrame::OnUpdateThemeMenu) ON_COMMAND_RANGE(ID_COLORFUL_WORD, ID_WHITE_OUTLOOK, CMainFrame::OnTheme) ON_UPDATE_COMMAND_UI_RANGE(ID_COLORFUL_WORD, ID_WHITE_OUTLOOK, CMainFrame::OnUpdateTheme) ON_XTP_CREATECONTROL() ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, CMainFrame::OnDockingPaneNotify) ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString) ON_REGISTERED_MESSAGE(WM_UPDATEASSETSCOMBO, CMainFrame::UpdateAssetsCombo) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { LoadResourceDLL(); } CMainFrame::~CMainFrame() { } void CMainFrame::LoadResourceDLL() { // load saved theme from the registry. m_nTheme = theApp.GetProfileInt(_T("MainFrame"), _T("ApplicationTheme"), ID_COLORFUL_WORD); // construct the resource dll file path. TCHAR szStylesPath[_MAX_PATH]; VERIFY(::GetModuleFileName(theApp.m_hInstance, szStylesPath, _MAX_PATH)); m_strAssetPath = szStylesPath; int nIndex = m_strAssetPath.ReverseFind(_T('\\')); if (nIndex > 0) { m_strAssetPath = m_strAssetPath.Left(nIndex); } else { m_strAssetPath.Empty(); } // load the resource dll. m_hModule.LoadLibrary(m_strAssetPath + _T("\\Styles\\Office2016.dll")); // save asset path location. m_strAssetPath += _T("\\Gauge"); } 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 } pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME); // 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)) { TRACE0("Failed to create toolbar\n"); return -1; } CXTPControls* pControls = pToolBar->GetControls(); if (pControls) { int nIndex = pControls->CommandToIndex(ID_FILE_OPEN); CXTPControl* pControl = pControls->GetAt(nIndex); if (pControl) { pControl->SetStyle(xtpButtonIconAndCaption); } } // Set Office 2016 Theme if (m_hModule.GetModuleState() == CXTPModuleHandle::xtpModLoaded) { if (m_nTheme == 0) { m_nTheme = ID_COLORFUL_WORD; } OnTheme(m_nTheme); } else { m_nTheme = 0; } pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME); //-- finalize statusbar setup. m_wndStatusBar.SetCommandBars(pCommandBars); m_wndStatusBar.GetPane(0)->SetBeginGroup(FALSE); //-- add slider control to status bar. CXTPStatusBarSliderPane* pSliderPane = (CXTPStatusBarSliderPane*)m_wndStatusBar.AddIndicator( new CXTPStatusBarSliderPane(), ID_INDICATOR_SLIDER); pSliderPane->SetWidth(XTP_DPI_X(250)); pSliderPane->SetRange(0, 100); pSliderPane->SetPos(0); pSliderPane->SetStyle(SBPS_NOBORDERS); pSliderPane->SetBeginGroup(FALSE); pSliderPane->SetCaption(_T("&Gauge Pos")); pSliderPane->SetTooltip(_T("Set Gauge pointer position.")); //-- add button control to status bar. CXTPStatusBarPane* pButtonPane = m_wndStatusBar.AddIndicator(ID_INDICATOR_RESET); pButtonPane->SetWidth(pButtonPane->GetBestFit()); pButtonPane->SetButton(); pButtonPane->SetTextAlignment(DT_CENTER); pButtonPane->SetBeginGroup(FALSE); pButtonPane->SetCaption(_T("&Reset")); pButtonPane->SetTooltip(_T("Reset Gauge to default size and position.")); #ifndef _DEBUG // Load the previous state for toolbars and menus. LoadCommandBars(_T("CommandBars")); #endif // 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); // Set Office 2016 Theme m_paneManager.SetTheme(xtpPaneThemeOffice2016); CRect rcPane = CRect(XTP_DPI_X(0), XTP_DPI_Y(0), XTP_DPI_Y(350), XTP_DPI_Y(200)); // Create docking panes. CXTPDockingPane* pwndPaneCircular = m_paneManager.CreatePane(IDR_PANE_GAUGES, rcPane, xtpPaneDockLeft); CXTPDockingPane* pwndPaneAssets = m_paneManager.CreatePane(IDR_PANE_ASSETS, rcPane, xtpPaneDockBottom, pwndPaneCircular); m_paneManager.HidePane(pwndPaneAssets); pwndPaneCircular->Select(); return 0; } void CMainFrame::OnClose() { // Save the current state for toolbars and menus. SaveCommandBars(_T("CommandBars")); #ifndef _DEBUG // save selected theme. theApp.WriteProfileInt(_T("MainFrame"), _T("ApplicationTheme"), m_nTheme); #endif CFrameWnd::OnClose(); } CXTPStatusBarSliderPane* CMainFrame::GetSliderPane() { return (CXTPStatusBarSliderPane*)m_wndStatusBar.FindPane(ID_INDICATOR_SLIDER); } 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); // Add the keyboard page to the customize dialog. CXTPCustomizeKeyboardPage pageKeyboard(&dlg); dlg.AddPage(&pageKeyboard); pageKeyboard.AddCategories(IDR_MAINFRAME); // 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(); } } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if (!CFrameWnd::PreCreateWindow(cs)) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs 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 CMainFrame::OnTheme(UINT nTheme) { if (m_hModule.GetModuleState() != CXTPModuleHandle::xtpModLoaded) return; switch (nTheme) { // colorful case ID_COLORFUL_WORD: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016WordColorful); break; case ID_COLORFUL_EXEL: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016ExcelColorful); break; case ID_COLORFUL_ACCESS: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016AccessColorful); break; case ID_COLORFUL_PUBLISHER: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PublisherColorful); break; case ID_COLORFUL_POWERPOINT: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PowerPointColorful); break; case ID_COLORFUL_ONENOTE: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OneNoteColorful); break; case ID_COLORFUL_OUTLOOK: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OutlookColorful); break; // dark gray case ID_DARKGRAY_WORD: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016WordDarkGray); break; case ID_DARKGRAY_EXEL: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016ExcelDarkGray); break; case ID_DARKGRAY_ACCESS: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016AccessDarkGray); break; case ID_DARKGRAY_PUBLISHER: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PublisherDarkGray); break; case ID_DARKGRAY_POWERPOINT: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PowerPointDarkGray); break; case ID_DARKGRAY_ONENOTE: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OneNoteDarkGray); break; case ID_DARKGRAY_OUTLOOK: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OutlookDarkGray); break; // black case ID_BLACK_WORD: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016WordBlack); break; case ID_BLACK_EXEL: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016ExcelBlack); break; case ID_BLACK_ACCESS: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016AccessBlack); break; case ID_BLACK_PUBLISHER: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PublisherBlack); break; case ID_BLACK_POWERPOINT: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PowerPointBlack); break; case ID_BLACK_ONENOTE: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OneNoteBlack); break; case ID_BLACK_OUTLOOK: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OutlookBlack); break; // white case ID_WHITE_WORD: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016WordWhite); break; case ID_WHITE_EXEL: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016ExcelWhite); break; case ID_WHITE_ACCESS: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016AccessWhite); break; case ID_WHITE_PUBLISHER: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PublisherWhite); break; case ID_WHITE_POWERPOINT: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016PowerPointWhite); break; case ID_WHITE_ONENOTE: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OneNoteWhite); break; case ID_WHITE_OUTLOOK: XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016OutlookWhite); break; // default default: { nTheme = ID_COLORFUL_WORD; XTPResourceImages()->SetHandle(m_hModule, xtpIniOffice2016WordColorful); TRACE(_T("Warning: Unknown theme specified, setting default theme.\n")); } break; } m_nTheme = nTheme; CXTPPaintManager::SetTheme(xtpThemeOffice2016); GetCommandBars()->EnableFrameTheme(TRUE); XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE; GetCommandBars()->RedrawCommandBars(); m_paneManager.SetTheme(xtpPaneThemeOffice2016); m_paneManager.RedrawPanes(); m_paneManager.SetDockingContextStickerStyle( (m_nTheme >= ID_BLACK_WORD && m_nTheme <= ID_BLACK_OUTLOOK) ? xtpPaneStickerStyleVisualStudio2015Dark : xtpPaneStickerStyleVisualStudio2015Light); RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN); } void CMainFrame::OnUpdateTheme(CCmdUI* pCmdUI) { if (m_nTheme == 0) { pCmdUI->Enable(FALSE); pCmdUI->SetCheck(FALSE); } else { pCmdUI->SetCheck(pCmdUI->m_nID == m_nTheme ? 1 : 0); } } int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { if (lpCreateControl->nID == IDR_THEME) { CXTPControlPopup* pControl = CXTPControlPopup::CreateControlPopup(xtpControlPopup); pControl->SetFlags(xtpFlagRightAlign); CMenu mnuOptions; mnuOptions.LoadMenu(IDR_THEME_MENU); pControl->SetCommandBar(mnuOptions.GetSubMenu(0)); pControl->SetCaption(_T("Options")); lpCreateControl->pControl = pControl; return TRUE; } return FALSE; } void CMainFrame::OnUpdateThemeMenu(CCmdUI* pCmdUI) { pCmdUI->Enable(); } 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_GAUGES: { if (!::IsWindow(m_paneGauges.m_hWnd)) { m_paneGauges.Create(_T("Gauges"), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP, CRect(0, 0, 0, 0), this, 0); } pPane->Attach(&m_paneGauges); } break; case IDR_PANE_ASSETS: { if (!::IsWindow(m_paneAssets.m_hWnd)) { m_paneAssets.Create(_T("Preview"), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP, CRect(0, 0, 0, 0), this, 0); } pPane->Attach(&m_paneAssets); m_paneAssets.UpdateComboBox(); } break; } } return TRUE; } return FALSE; } LRESULT CMainFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam) { UINT nIDLast = m_nIDLastMessage; m_nFlags &= ~WF_NOPOPMSG; CXTPStatusBarPane* pMessageBar = m_wndStatusBar.GetPane(0); if (pMessageBar != NULL) { LPCTSTR lpsz = NULL; CString strMessage; // set the message bar text if (lParam != 0) { ASSERT(wParam == 0 || wParam == 1); // can't have both an ID and a string lpsz = (LPCTSTR)lParam; // set an explicit string if (wParam == 1) { m_strMessage = lpsz; } } else if (wParam != 0) { // map SC_CLOSE to PREVIEW_CLOSE when in print preview mode if (wParam == AFX_IDS_SCCLOSE && m_lpfnCloseProc != NULL) wParam = AFX_IDS_PREVIEW_CLOSE; // get message associated with the ID indicated by wParam if (wParam == AFX_IDS_IDLEMESSAGE) { strMessage.LoadString(AFX_IDS_IDLEMESSAGE); lpsz = (LPCTSTR)m_strMessage.IsEmpty() ? strMessage : m_strMessage; } else { lpsz = pMessageBar->GetText(); } } pMessageBar->SetText(lpsz); } m_nIDLastMessage = (UINT)wParam; // new ID (or 0) m_nIDTracking = (UINT)wParam; // so F1 on toolbar buttons work return nIDLast; } LRESULT CMainFrame::UpdateAssetsCombo(WPARAM wParam, LPARAM lParam) { CGaugeInfo* pGI = (CGaugeInfo*)wParam; if (pGI) { m_paneAssets.SetGaugeInfo(pGI); CXTPStatusBarSliderPane* pSliderPane = (CXTPStatusBarSliderPane*)m_wndStatusBar.FindPane( ID_INDICATOR_SLIDER); pSliderPane->SetRange(pGI->min, pGI->max); pSliderPane->SetPos(pGI->pos); return 0; } return -1; }