介面開發中如何實現Office樣式工具欄和選單
阿新 • • 發佈:2020-10-11
Xtreme Toolkit Pro是MFC開發中最全面介面控制元件套包,它提供了Windows開發所需要的11種主流的Visual C++ MFC控制元件,包括Command Bars、Controls、Chart Pro、Calendar、Docking Pane、Property Grid、Report Control、Shortcut Bar、Syntax Edit、Skin Framework 和Task Panel。如果對產品感興趣的話歡迎下載Xtreme Toolkit Pro最新試用版!
【同類開發工具】
- BCGControlBar Professional Edition for MFC
- BCGControlBar for .NET:包含有大量高度自定義、完全可設計的.NET介面控制元件,使用者可以使用這些來建立精緻美觀的圖形使用者介面。
以下是有關如何為應用程式工具欄和應用程式選單新增新增自定義設定的教程。本教程假定您已經建立了使用Office樣式的工具欄和選單的應用程式。
新增工具欄和選單的自定義
1.將XTP_ID_CUSTOMIZE的ON_COMMAND新增到CMainFrame的訊息對映中。這將處理工具欄和選單自定義對話方塊的設定和顯示。
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.為OnCustomize函式新增主體:
void CMainFrame::OnCustomize() { // Get a pointer to the Command Bar object. CXTPCommandBars* pCommandBars = GetCommandBars(); if(pCommandBars != NULL) { // Instantiate 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(); // Display the dialog. dlg.DoModal(); } }
3.新增LoadCommandBars(_T(“ CommandBars”)); 到CMainFrame的OnCreate函式。這將恢復工具欄和選單的先前狀態以及所做的任何自定義。
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ... // Load the previous state for toolbars and menus. LoadCommandBars(_T("CommandBars")); return 0; }
4.將OnClose訊息處理程式新增到CMainFrame並新增SaveCommandBars(_T(“ CommandBars”)); 在呼叫基類之前。這將儲存工具欄和選單的當前狀態以及所做的任何自定義。
void CMainFrame::OnClose() { // Save the current state for toolbars and menus. SaveCommandBars(_T("CommandBars")); CMDIFrameWnd::OnClose(); }
今天的內容就是這些了,下載最新版Xtreme ToolKit Pro並在下方評論區分享您對該產品的想法。您的反饋意見可幫助我們在以後的更新中找到正確的方向!