Original Address http://blog.csdn.net/teleinfor/article/details/1858976
Class Cmultiviewapp:public CWINAPP
{
Public
cview* M_pfirstview;
cview* M_potherview;
int M_currentview;
cview* M_pview2;
cview* M_pview1;
Cmultiviewapp ();
Overrides
ClassWizard generated virtual function overrides
{{afx_virtual (Cmultiviewapp)
Public
Virtual BOOL InitInstance ();
}}afx_virtual
Implementation
{{afx_msg (Cmultiviewapp)
afx_msg void Onappabout ();
afx_msg void Onviewotherview ();
afx_msg void Onviewfirstview ();
}}afx_msg
afx_msg void Onviewchange (UINT ncmdid);
Declare_message_map ()
};
Second, the CPP file has the following message map:
/////////////////////////////////////////////////////////////////////////////
Cmultiviewapp
Begin_message_map (Cmultiviewapp, CWINAPP)
{{Afx_msg_map (Cmultiviewapp)
On_command (Id_app_about, Onappabout)
On_command (Id_view_otherview, Onviewotherview)
On_command (Id_view_firstview, Onviewfirstview)
}}afx_msg_map
Standard file based document commands
On_command (id_file_new, CWinApp::OnFileNew)
On_command (Id_file_open, Cwinapp::onfileopen)
Standard Print Setup command
On_command (Id_file_print_setup, Cwinapp::onfileprintsetup)
On_command_range (Id_view_view1, Id_view_view2, Onviewchange)
End_message_map ()
Description: The SDI program in Cmyapp::initinstance () has created an associated view/document instance through DocTemplate, which is cut and displayed. The implementation is as follows:
BOOL cmultiviewapp::initinstance ()
{
AfxEnableControlContainer ();
Standard initialization
If you is not using these features and wish to reduce the size
of your final executable, you should remove from the following
The specific initialization routines you does not need.
#ifdef _afxdll
Enable3dcontrols (); Call the When using the MFC in a shared DLL
#else
Enable3dcontrolsstatic (); Linking to MFC statically
#endif
The change of the registry key under which our settings is stored.
Todo:you should modify this string to be something appropriate
such as the name of your company or organization.
Setregistrykey (_t ("Local appwizard-generated Applications"));
LoadStdProfileSettings (); Load standard INI file options (including MRU)
Register the application ' s document templates. Document templates
Serve as the connection between documents, frame windows and views.
Csingledoctemplate* pdoctemplate;
Pdoctemplate = new CSingleDocTemplate (
Idr_mainframe,
Runtime_class (Cmultiviewdoc),
Runtime_class (CMainFrame),//main SDI frame window
Runtime_class (Cmultiviewview));
AddDocTemplate (pdoctemplate);
Parse command line to standard shell commands, DDE, File Open
CCommandLineInfo Cmdinfo;
ParseCommandLine (Cmdinfo);
Dispatch commands specified on the command line
if (! ProcessShellCommand (Cmdinfo))
return FALSE;
cview* Pactiveview = ((cframewnd*) m_pMainWnd)->getactiveview ();
M_pfirstview = Pactiveview;
M_potherview = (cview*) new Cotherview;
cdocument* PDoc = ((cframewnd*) m_pMainWnd)->getactivedocument ();
Implementing a second view and document association through CCreateContext
CCreateContext context;
Context.m_pcurrentdoc = PDoc;
UINT m_id = Afx_idw_pane_first + 1;
CRect rect;
To demonstrate that the first multi-view is the implementation method, the Vew instance creation is placed here
M_potherview->create (null, NULL, WS_CHILD, rect, m_pMainWnd, m_id, &context);
The one and only window have been initialized, so show and update it.
M_pmainwnd->showwindow (sw_showmaximized);
M_pmainwnd->updatewindow ();
M_currentview=1;