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!