www.pudn.com > LockToolbars.zip > MainFrm.cpp, change:2005-04-21,size:4972b
// MainFrm.cpp : Implementierung der Klasse CMainFrame // #include "stdafx.h" #include "LockToolbars.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_COMMAND(ID_VIEW_LOCKTHETOOLBARS, OnViewLockthetoolbars) ON_UPDATE_COMMAND_UI(ID_VIEW_LOCKTHETOOLBARS, OnUpdateViewLockthetoolbars) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // Statusleistenanzeige ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame Konstruktion/Zerstörung CMainFrame::CMainFrame() { // ZU ERLEDIGEN: Hier Code zur Member-Initialisierung einfügen m_bLocked = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; 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("Symbolleiste konnte nicht erstellt werden\n"); return -1; // Fehler bei Erstellung } if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_TOP, AFX_IDW_DIALOGBAR)) { TRACE0("Dialogleiste konnte nicht erstellt werden\n"); return -1; // Fehler bei Erstellung } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Statusleiste konnte nicht erstellt werden\n"); return -1; // Fehler bei Erstellung } // ZU ERLEDIGEN: Löschen Sie diese drei Zeilen, wenn Sie nicht wollen, dass die Symbolleiste // andockbar ist. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); m_wndDlgBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); DockControlBar(&m_wndDlgBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // ZU ERLEDIGEN: Ändern Sie hier die Fensterklasse oder das Erscheinungsbild, indem Sie // CREATESTRUCT cs modifizieren. return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame Diagnose #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame Nachrichten-Handler ////////////////////////////////////////////////////////////////////////////// // //! Locks the toolbars. //! ////////////////////////////////////////////////////////////////////////////// void CMainFrame::OnViewLockthetoolbars() { DWORD dwToolbarStyle = m_wndToolBar.GetBarStyle(); DWORD dwDlgbarStyle = m_wndDlgBar.GetBarStyle(); if(m_bLocked) { // Changes the bars' style, so they have grippers dwToolbarStyle |= CBRS_GRIPPER; dwDlgbarStyle |= CBRS_GRIPPER; m_wndToolBar.SetBarStyle(dwToolbarStyle); m_wndDlgBar.SetBarStyle(dwDlgbarStyle); //when removing the fixed style, set back the dockbar m_wndToolBar.m_pDockBar = m_pTBDockBar; m_wndDlgBar.m_pDockBar = m_pDBDockBar; } else { // Changes the bars' style, so they have not grippers dwToolbarStyle &= ~CBRS_GRIPPER; dwDlgbarStyle &= ~CBRS_GRIPPER; m_wndToolBar.SetBarStyle(dwToolbarStyle); m_wndDlgBar.SetBarStyle(dwDlgbarStyle); // If the bar is floating, it will be docked before locking it. DockControlBar(&m_wndToolBar); DockControlBar(&m_wndDlgBar); //remove dockbar so that it cannot be moved around m_pTBDockBar = m_wndToolBar.m_pDockBar; m_pDBDockBar = m_wndDlgBar.m_pDockBar; m_wndToolBar.m_pDockBar = NULL; m_wndDlgBar.m_pDockBar = NULL; } m_wndDlgBar.Invalidate(); // dialog bars need Invalidate() RecalcLayout(); m_bLocked = !m_bLocked; } ////////////////////////////////////////////////////////////////////////////// // //! Sets the check box of the menu item 'Lock the Toolbars' if the toolbars //! are locked. //! //! param pCmdUI (in): points to the CCmdUI object //! (see MSDN Library for further information) // ////////////////////////////////////////////////////////////////////////////// void CMainFrame::OnUpdateViewLockthetoolbars(CCmdUI* pCmdUI) { // TODO: Code für die Befehlsbehandlungsroutine zum Aktualisieren der Benutzeroberfläche hier einfügen pCmdUI->SetCheck(m_bLocked); }