Implementation of multiple views in a single document

Source: Internet
Author: User

This article uses cmfctabctrl to implement multi-view option display. The program is as follows:

Step 1: create two dialog boxes and add cfirstdlg and cseconddlg to them respectively;

Step 2: Set the properties of the two dialogs as follows:
Noinheritlayout true
Visible true
Style child

Step 3: Include the header files of the two dialog box classes in the View Class header file of the program, and declare a variable for them respectively:

CFirstDlg m_dlgFirst;CSecondDlg m_dlgSecond;

Step 4: declare a cmfctabctrl variable m_wndtabs in the View Class header file of the program:

CMFCTabCtrl m_wndTabs;

Step 5: create two dialogs, m_wndtabs, and associate the dialog box with m_wndtabs in the oncreate function of the View class of the program. The Code is as follows:

Crect rectdummy; rectdummy. setrectempty (); If (! M_wndtabs.create (cmfctabctrl: style_3d_onenote, rectdummy, this, 1, cmfcbasetabctrl: location_top) {trace0 ("failed to create the tab control! "); Return-1;} m_dlgfirst = new cfirstdlg (); m_dlgsecond = new cseconddlg (); If (! M_dlgfirst-> Create (idd_dialog1, & m_wndtabs) |! M_dlgsecond-> Create (idd_dialog2, & m_wndtabs) {trace0 ("failed to create dialog box! "); Return-1;} updatefonts (); m_wndtabs.addtab (m_dlgfirst," first ", (uint) 0); m_wndtabs.addtab (m_dlgsecond," second ", (uint) 1); m_wndtabs.enableactivetabclosebutton ();

Step 6: Add a wm_size message response to the view class of the program. Set the m_wndtabs position in the response function of the message. The Code is as follows:

m_wndTabs.SetWindowPos(NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);

Step 7: add the void updatefonts () function to the View class of the program, and set the font of the dialog box in the function. The Code is as follows:

m_dlgFirst->SetFont(&afxGlobalData.fontRegular);m_dlgSecond->SetFont(&afxGlobalData.fontRegular);

Now, compile and run the program, and you can see the program shown in the starting image. I hope you can come up with a better method!

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.