Comparison between the classic MFC interface and the Ribbon interface framework (single document is used as an example)

Source: Internet
Author: User

IDE: vs2008 + SP1

A is the single-document interface of the classic MFC:

B is the single-document interface of the ribbon-style MFC:

 

After the Basic Framework Code of A and B is generated, the comparison tool finds that the interfaces of the two different styles are mainly different in the mainframe class.

In the initinstance () function of the application class (cxxxapp), the Class B executes the initshellmanager () initialization after initcontextmenumanager () is called.

The code of this sentence is mainly used to initialize shell for the use of cmfcshelltreectrl (file directory tree) and cmfcshelllistctrl (file list.

++ ++

The mainfrm. h data member variables have a certain correspondence relationship.

A

Cmfctoolbar m_wndtoolbar; // tool bar cmfctoolbarimages m_userimages; // image resources used in the tool bar cmfcmenubar m_wndmenubar; // cmfcstatusbar m_wndstatusbar in the menu bar; // Status Bar

B. No menu bar

Cmfcribbonbar m_wndribbonbar; // ribbon tool bar cmfctoolbarimages m_panelimages; // The image resource cmfcribbonapplicationbutton m_mainbutton used in the toolbar; // click cmfcribbonstatusbar m_wndstatusbar in the upper left corner

The main difference code in mainfrm. cpp is still reflected in the oncreate () function.

A

// Create and initialize each control int cmainframe: oncreate (lpcreatestruct) {If (cframewndex: oncreate (lpcreatestruct) =-1) Return-1; bool bnamevalid; // set the visual manager and style based on persisted valueonapplicationlook (theapp. m_napplook); If (! M_wndmenubar.create (this) {trace0 ("failed to create menubar \ n"); Return-1; // fail to create} m_wndmenubar.setpanestyle (m_wndmenubar.getpanestyle () | cbrs_size_dynamic | cbrs_tooltips | cbrs_flyby); // prevent the menu bar from taking the focus on activationcmfcpopupmenu: setforcemenufocus (false); 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 (theapp. m_bhicoloricons? Idr_mainframe_256: idr_mainframe) {trace0 ("failed to create Toolbar \ n"); Return-1; // fail to create} cstring strtoolbarname; bnamevalid = strtoolbarname. loadstring (ids_toolbar_standard); Assert (bnamevalid); m_wndtoolbar.setwindowtext (strtoolbarname); cstring strcustomize; bnamevalid = strcustomize. loadstring (ids_toolbar_customize); Assert (bnamevalid); m_wndtoolbar.enablecustomizebutton (true, id_view_cuz Tomize, strcustomize); // allow user-defined toolbars operations: initusertoolbars (null, uifirstusertoolbarid, uilastusertoolbarid); If (! M_wndstatusbar.create (this) {trace0 ("failed to create status bar \ n"); Return-1; // fail to create} m_wndstatusbar.setindicators (indicators, sizeof (indicators) /sizeof (uint); // todo: delete these five lines if you don't want the toolbar and menubar to be empty (cbrs_align_any); m_wndtoolbar.enabledocking (cbrs_align_any ); enabledocking (cbrs_align_any); dockpane (& m_wndmenubar); dockpane (& m_wndtoolbar); // enable Visual Studio 2005 style docking window labels: setdockingmode (dt_smart ); // enable Visual Studio 2005 style docking window auto-hide labels (cbrs_align_any); // enable toolbar and docking Window Menu values (true, id_view_mimize, strcustomize, id_view_toolbar ); // enable quick (Alt + drag) toolbar customizationcmfctoolbar: enablequickcustomization (); Return 0 ;}

  

Call initializeribbon () in B oncreate () to initialize the ribbon toolbar.

// Create and initialize each control int cmainframe: oncreate (lpcreatestruct) {If (cframewndex: oncreate (lpcreatestruct) =-1) Return-1; bool bnamevalid; // set the visual manager and style based on persisted valueonapplicationlook (theapp. m_napplook); m_wndribbonbar.create (this); initializeribbon (); If (! M_wndstatusbar.create (this) {trace0 ("failed to create status bar \ n"); Return-1; // fail to create} cstring strtitlepane1; cstring strtitlepane2; bnamevalid = upper (lower); Assert (bnamevalid); bnamevalid = lower (lower); Assert (bnamevalid); upper (new lower (lower, strtitlepane1, true), strtitlepane1 ); partition (new partition (id_statusbar_pane2, strtitlepane2, true), strtitlepane2); // enable Visual Studio 2005 style docking window behaviorcdockingmanager: setdockingmode (dt_smart ); // enable Visual Studio 2005 style docking window auto-hide behaviorenableautohidepanes (cbrs_align_any); // Navigation Pane will be created at left, so temporary disable docking at the left side: enabledocking (cbrs_align_top | cbrs_align_bottom | cbrs_align_right); // outlook bar is created and docking on the left side shoshould be allowed. enabledocking (events); enableautohidepanes (events); Return 0;} // initialize the ribbion toolbar void cmainframe: initializeribbon () {bool bnamevalid; cstring strtemp; // load panel images: values (csize (16, 16); m_panelimages.load (idb_buttons); // init main button: m_mainbutton.setimage (idb_main); m_mainbutton.settext (_ T ("\ NF ")); m_mainbutton.settooltiptext (strtemp); m_wndribbonbar.setapplicationbutton (& m_mainbutton, csize (45, 45); // Add "home" category with "Clipboard" Panel: bnamevalid = strtemp. loadstring (plaintext); Assert (bnamevalid); cmfcribboncategory * pcategoryhome = delimiter (strtemp, idb_writesmall, idb_writelarge); // create and add a "View" Panel: bnamevalid = strtemp. loadstring (ids_ribbon_view); Assert (bnamevalid); cmfcribbonpanel * ppanelview = pcategoryhome-> addpanel (strtemp, temperature (7); bnamevalid = strtemp. loadstring (plaintext); Assert (bnamevalid); cmfcribbonbutton * pbtnstatusbar = new cmfcribboncheckbox (id_view_status_bar, strtemp); ppanelview-> Add (pbtnstatusbar ); // add elements to the right side of tabs: bnamevalid = strtemp. loadstring (plaintext); Assert (bnamevalid); cmfcribbonbutton * pvisualstylebutton = new cmfcribbonbutton (-1, strtemp,-1,-1); delimiter-> setmenu (idr_theme_menu, false/* no default command */, true/* Right align */); bnamevalid = strtemp. loadstring (ids_ribbon_style_tip); Assert (bnamevalid); pvisualstylebutton-> settooltiptext (strtemp); bnamevalid = strtemp. loadstring (ids_ribbon_style_desc); Assert (bnamevalid); pvisualstylebutton-> setdescription (strtemp); m_wndribbonbar.addtotabs (pvisualstylebutton );}

 

PS: cxxxapp is no longer derived from cwinapp, but from cwinappex

Cmainframe is no longer derived from cframewnd, but from cframewndex

 

Download the ribbonmfc framework sample code:Ribbonmfc.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.