XTToolkitPro使用... 1 開(kāi)發(fā)環(huán)境... 2 添加SDI程序的CommandBar和MenuBar支持... 2 定制toolbars和menus的支持... 3 添加自定義的主題支持... 5 添加Docking Panes支持... 6 發(fā)現(xiàn)定義在XTPDeprecated.h中的符號(hào),為廢棄符號(hào),修改為新符號(hào)即可... 9 添加智能菜單支持... 9 添加自定義特性的派生控件... 9
2、 在stdafx.h添加 #include <XTToolkitPro.h> // Xtreme Toolkit Pro component library 3、 修改mainfrm.h的CMainFrame基類(lèi),MDI對(duì)應(yīng)為 CXTPMDIFrameWnd class CMainFrame : public CXTPFrameWnd 4、 修改CMainFrame::OnCreate函數(shù) // 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)) { TRACE0("Failed to create toolbar\n"); return -1; }
// Set Office 2003 Theme CXTPPaintManager::SetTheme(xtpThemeOffice2003); 注釋掉以下幾行 //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("未能創(chuàng)建工具欄\n"); // return -1; // 未能創(chuàng)建 //} /*m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar);*/ 5、 如果需要重載CMainFrame::PreTranslateMessage和CMainFrame::OnCmdMsg,修改如下 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class
return CXTPMDIFrameWnd::PreTranslateMessage(pMsg); }
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // TODO: Add your specialized code here and/or call the base class
return CXTPMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } 6、 編譯運(yùn)行,出現(xiàn)Offiice 2003主題風(fēng)格的應(yīng)用程序
1、 在CMainFrm類(lèi)增加響應(yīng)ON_COMMAND的消息 XTP_ID_CUSTOMIZE 支持 在mainfrm.cpp中修改 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize) END_MESSAGE_MAP() 在mainfrm.h中修改 //{{AFX_MSG(CMainFrame) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); //}}AFX_MSG afx_msg void OnCustomize(); DECLARE_MESSAGE_MAP() 2、 在mainfrm.cpp中增加 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 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_MDISAMTYPE);
// Use the command bar manager to initialize the // customize dialog. pCommands->InsertAllCommandsCategory(); pCommands->InsertBuiltInMenus(IDR_MDISAMTYPE); pCommands->InsertNewMenuCategory();
// Dispaly the dialog. dlg.DoModal(); } } 3、 添加CMainFrm類(lèi)的對(duì)commandbar和menubar的定制配置序列化支持 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ...
// Load the previous state for toolbars and menus. LoadCommandBars(_T("CommandBars"));
return 0; } void CMainFrame::OnClose() { // Save the current state for toolbars and menus. SaveCommandBars(_T("CommandBars")); CMDIFrameWnd::OnClose(); } 4、 資源包含,查看rc2資源文件代碼,添加xttoolkitpro.rc,在資源附加目錄中添加xttoolkitpro.rc所在目錄 5、 編譯運(yùn)行,發(fā)現(xiàn)定制化工具欄和菜單的資源沒(méi)有加載進(jìn)來(lái),如圖標(biāo)、字符串等,解決方法是修改字符資源語(yǔ)言為英文(這里編譯的是英文資源的lib庫(kù),根據(jù)自己需要也可以編譯中文資源的lib庫(kù))
CXTPDefaultTheme to inherit Office 2000 theme CXTPOfficeTheme to inherit Office XP theme CXTPOffice2003Theme to inherit Office 2003 theme CXTPNativeXPTheme to inherit Native XP theme 2、 實(shí)現(xiàn)自定義主題類(lèi)的接口,接口函數(shù)為DrawCommandBarGripper class CDoubleGripperTheme : public CXTPDefaultTheme { virtual CSize DrawCommandBarGripper( CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw); };
// DrawCommandBarGripper function. // if bDraw if FALSE must return gripper size. // if bDraw is TRUE must draw gripper. CSize CDoubleGripperTheme::DrawCommandBarGripper(CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw) { // If Toolbar is vertical docked if (pBar->GetPosition() == xtpBarRight || pBar->GetPosition() == xtpBarLeft) { if (bDraw) { CXTPClientRect rc(pBar); Draw3dRect(pDC, CRect(3, 3, rc.right - 3, 6), COLOR_BTNHILIGHT, COLOR_3DSHADOW); Draw3dRect(pDC, CRect(3, 7, rc.right - 3, 10), COLOR_BTNHILIGHT, COLOR_3DSHADOW); } return CSize(0, 10); } // if Toolbar is horizontal docked else if (pBar->GetPosition() == xtpBarTop || pBar->GetPosition() == xtpBarBottom) { CXTPClientRect rc(pBar); if (bDraw) { Draw3dRect(pDC, CRect(3, 3, 6, rc.bottom - 3), COLOR_BTNHILIGHT, COLOR_3DSHADOW); Draw3dRect(pDC, CRect(7, 3, 10, rc.bottom - 3), COLOR_BTNHILIGHT, COLOR_3DSHADOW); } return CSize(10, 0); } else return CXTPDefaultTheme::DrawCommandBarGripper(pDC, pBar, bDraw); } 3、 運(yùn)行查看效果 支持 1、 在CMainFrame類(lèi)中添加CXTPDockingPaneManager成員 // Attributes public: CXTPDockingPaneManager m_paneManager; 2、 添加字符串資源 IDR_PANE_OPTIONS 61446 Options IDR_PANE_PROPERTIES 61447 Properties 3、 在CMainFrame::OnCreate中添加 // 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); m_paneManager.SetTheme(xtpPaneThemeOffice);
// Create docking panes. CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane( IDR_PANE_OPTIONS, CRect(0, 0,200, 120), dockLeftOf); CXTPDockingPane* pwndPane2 = m_paneManager.CreatePane( IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), dockBottomOf, pwndPane1) 4、 運(yùn)行查看Docking Panes效果 5、 綁定窗口控件類(lèi)到Docking Panes中 6、 添加CMainFrame的窗口控件成員 // Attributes public: CStatic m_wndOptions; CEdit m_wndProperties; 7、 添加OnDockingPaneNotify函數(shù)處理,綁定窗口控件成員到Docking Panes上 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify) END_MESSAGE_MAP()
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_PROPERTIES: { if (m_wndProperties.GetSafeHwnd() == 0) { m_wndProperties.Create(WS_CHILD| ES_AUTOVSCROLL|ES_MULTILINE, CRect(0, 0, 0, 0), this, 0); } pPane->Attach(&m_wndProperties); break; } case IDR_PANE_OPTIONS: { if (m_wndOptions.GetSafeHwnd() == 0) { m_wndOptions.Create(_T("\n\nOptions"), WS_CHILD|WS_CLIPCHILDREN| WS_CLIPSIBLINGS|SS_CENTER, CRect(0, 0, 0, 0), this, 0); } pPane->Attach(&m_wndOptions); break; } } } return TRUE; } return FALSE; } 8、 添加Bitmap圖片資源,2個(gè)圖標(biāo)大小33x15 9、 添加CMainFrame::OnCreate中 int nIDIcons[] = {IDR_PANE_OPTIONS, IDR_PANE_PROPERTIES}; m_paneManager.SetIcons(IDB_BITMAP_ICONS, nIDIcons, _countof(nIDIcons), RGB(0, 255, 0)); 10、 添加Docking Panes的序列化支持 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ...
// Load the previous state for docking panes. CXTPDockingPaneLayout layoutNormal(&m_paneManager); if (layoutNormal.Load(_T("NormalLayout"))) { m_paneManager.SetLayout(&layoutNormal); } return 0; } void CMainFrame::OnClose() { // Save the current state for docking panes. CXTPDockingPaneLayout layoutNormal(&m_paneManager); m_paneManager.GetLayout(&layoutNormal); layoutNormal.Save(_T("NormalLayout")); CMDIFrameWnd::OnClose(); } 11、 運(yùn)行查看帶圖標(biāo)的Docking Panes效果
1、 定義想隱藏的菜單ID數(shù)組 static UINT uHideCmds[] = { ID_FILE_PRINT, ID_FILE_PRINT_PREVIEW, ID_WINDOW_CASCADE }; 2、 在CMainFrame::OnCreate中添加 // Hide array of commands pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));
// Set "Always Show Full Menus" option to the FALSE XTP_COMMANDBARS_OPTIONS* pOptions = pCommandBars->GetCommandBarsOptions(); pOptions->bAlwaysShowFullMenus = FALSE; 3、 運(yùn)行查看結(jié)果
2、 重載實(shí)現(xiàn)CXTPControlComboBoxEditCtrl的OnChar成員 class CControlComboBoxEditEx : public CXTPControlComboBoxEditCtrl { public: afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
DECLARE_MESSAGE_MAP() };
BEGIN_MESSAGE_MAP(CControlComboBoxEditEx, CXTPControlComboBoxEditCtrl) ON_WM_CHAR() END_MESSAGE_MAP()
void CControlComboBoxEditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CString strChar((TCHAR)nChar), strUpper((TCHAR)nChar); strUpper.MakeUpper();
if (strChar != strUpper) ReplaceSel(strUpper, TRUE); else CXTPControlComboBoxEditCtrl::OnChar(nChar, nRepCnt, nFlags); } 3、 重載實(shí)現(xiàn)CControlComboBoxEx的CreateEditControl成員 class CControlComboBoxEx: public CXTPControlComboBox { DECLARE_XTP_CONTROL(CControlComboBoxEx) public: CXTPControlComboBoxEditCtrl* CreateEditControl() { return new CControlComboBoxEditEx(); } };
IMPLEMENT_XTP_CONTROL(CControlComboBoxEx, CXTPControlComboBox) 4、 增加CControlComboBoxEx新成員對(duì)內(nèi)嵌CXTPControlComboBoxEditCtrl進(jìn)行數(shù)據(jù)交換操作 class CControlComboBoxEx: public CXTPControlComboBox { ...
protected: void Copy(CXTPControl* pControl, BOOL bRecursive = FALSE); virtual void DoPropExchange(CXTPPropExchange* pPX);
protected: CString m_strMask; };
void CControlComboBoxEx::Copy(CXTPControl* pControl, BOOL bRecursive) { ASSERT_KINDOF(CControlComboBoxEx, pControl);
m_strMask = ((CControlComboBoxEx*)pControl)->m_strMask;
CXTPControlComboBox::Copy(pControl, bRecursive); }
void CControlComboBoxEx::DoPropExchange(CXTPPropExchange* pPX) { CXTPControlComboBox::DoPropExchangepPX);
PX_String(pPX, _T("Mask"), m_strMask); } 5、 在CMainFrame類(lèi)的OnCreateControl成員里面添加CControlComboBoxEx控件,資源ID為ID_POPUP_COMBO BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ON_XTP_CREATECONTROL() END_MESSAGE_MAP()
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { if (lpCreateControl->nID == ID_POPUP_COMBO) { CXTPControlComboBox* pComboFind = (CXTPControlComboBox*)CControlComboBoxEx::CreateObject(); pComboFind->SetDropDownListStyle(); pComboFind->SetFlags(xtpFlagManualUpdate);
lpCreateControl->pControl = pComboFind; return TRUE; } return FALSE; } 6、 運(yùn)行成員檢查結(jié)果 |
聯(lián)系客服