Embedding a view in a dialog is not as complicated as you think. follow the steps below.
1. Create a child-type cframewnd and place it in the correct position.
2. Set ccreatecontext correctly
3. Create a view and cframewnd are associated. 4. Show it!
Check the Code:
Cwnd * pposwnd = getdlgitem (idc_view_positon );
Crect rect;
Pposwnd-> getwindowrect (& rect );
Crect rectview = rect;
Screentoclient (& rect );
M_pframe = new cframewnd ();
M_pframe-> Create (null, null, ws_child | ws_visible, rect, this );
M_pframe-> screentoclient (& rectview );
M_pdoc = static_cast <cdlgviewdoc *> (runtime_class (cdlgviewdoc)-> Createobject ());
Ccreatecontext context;
Context. m_pnewviewclass = runtime_class (cdlgviewview );
Context. m_pcurrentdoc = m_pdoc;
Context. m_pnewdoctemplate = NULL;
Context. m_plastview = NULL;
Context. m_pcurrentframe = m_pframe;
Cview * pview = static_cast <cview *> (runtime_class (cdlgviewview)-> Createobject ());
If (! Pview)
Return false;
If (! Pview-> Create (null, null, afx_ws_default_view, rectview, m_pframe, afx_idw_pane_first, & context ))
Return false;
Pview-> showwindow (sw_show );
Pview-> oninitialupdate ();