How to achieve multi-view of a single document?

Source: Internet
Author: User

Design Concept:

The document is responsible for saving data objects. There are no data objects (feature objects, such as the Third-party channel) that contain three types of display: 3D sample images, 2D development charts, and computing documents, preliminary Design: different views are defined to indicate different displays. How can this problem be solved?

This function has been implemented!

Add the View class information to be added by creating a document template,

The key code is as follows:

<Code begin>

Class cintragldoctemplate: Public csingledoctemplate
{
Declare_dynamic (cintragldoctemplate)
// Constructors
Public:
Cintragldoctemplate (uint nidresource, cruntimeclass * pdocclass,
Cruntimeclass * pframeclass, cruntimeclass * pviewclass,
Int nsplitterid =-1, int nrow = 0, int ncol = 0 );
 
// Attributes
Public:
Int m_nsplitterid; //-1, no splitter else splitter ID (0, 1 ,...)
Int m_nrow; // If splitter, row number (0, 1 ,...)
Int m_ncol; // If splitter, Col number (0, 1 ,...)
 
Cview * m_pview; // view pointer
 
// These overrides to retreive The View class and resource ID
Cruntimeclass * getviewclass ()
{Return m_pviewclass ;}
Uint getresourceid ()
{Return m_nidresource ;}
};

//////////////////////////////////////// //////////////////////////////////////// //////

Implement_dynamic (cintragldoctemplate, csingledoctemplate)

Cintragldoctemplate: cintragldoctemplate (uint nidresource, cruntimeclass * pdocclass,
Cruntimeclass * pframeclass, cruntimeclass * pviewclass,
Int nsplitterid, int nrow, int ncol ):
Csingledoctemplate (nidresource, pdocclass, pframeclass, pviewclass)
{
M_nsplitterid = nsplitterid;
M_nrow = nrow;
M_ncol = ncol;
M_pview = NULL;
}

/// The instance function of the app class is as follows:

Bool cintraglapp: initinstance ()
{
Afxenablecontrolcontainer ();

// Standard Initialization
// If you are 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 do not need.

# Ifdef _ afxdll
Enable3dcontrols (); // call this when using MFC in a shared DLL
# Else
Enable3dcontrolsstatic (); // call this when linking to MFC statically
# Endif

// Change the registry key under which our settings are stored.
// Todo: You shocould 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.

Cintragldoctemplate * pdoctemplate;
Pdoctemplate = new cintragldoctemplate (
Idr_mainframe,
Runtime_class (cintragldoc ),
Runtime_class (cmainframe), // main SDI frame window
Runtime_class (cmodelview ));
Adddoctemplate (pdoctemplate );

// Csingledoctemplate * pdoctemplate;
Pdoctemplate = new cintragldoctemplate (
Idr_mainframe,
Runtime_class (cintragldoc ),
Runtime_class (cmainframe), // main SDI frame window
Runtime_class (cdrawingview ));
Adddoctemplate (pdoctemplate );

// Parse command line for standard shell commands, DDE, file open
Ccommandlineinfo using info;
Parsecommandline (partition info );

// Dispatch commands specified on the command line
If (! Processshellcommand (cmdinfo ))
Return false;

// The one and only window has been initialized, so show and update it.
M_pmainwnd-> showwindow (sw_show );
M_pmainwnd-> updatewindow ();

Return true;
}

// Add the following member function to the cmainfram class

Class csplitinfo
{
Public:
Int m_maxrow, m_maxcol;
Csplitterwnd m_wndsplitter;
Csplitinfo: csplitinfo ();
Csplitinfo & operator = (const csplitinfo & splitinfo );
};

Bool cmainframe: oncreateclient (lpcreatestruct/* lpcs */, ccreatecontext * pcontext)
{
Cview * pview;
Cintraglapp * PAPP = (cintraglapp *) afxgetapp ();
Assert_kindof (cintraglapp, Papp );

// Hold informations from doctemplates to create Splitter
Position tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Cintragldoctemplate * ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
Assert_kindof (cintragldoctemplate, ptemplate );
If (ptemplate-> m_nsplitterid! =-1)
{
// Find or create the splitter ID in the splitter Map
Int nid = ptemplate-> m_nsplitterid;
M_splitinfo [NID]. m_maxrow = max (m_splitinfo [NID]. m_maxrow, ptemplate-> m_nrow + 1 );
M_splitinfo [NID]. m_maxcol = max (m_splitinfo [NID]. m_maxcol, ptemplate-> m_ncol + 1 );
}
}

// Create the splitter and the views in the Splitter
Position mappos = m_splitinfo.getstartposition ();
While (mappos)
{
Int NID; csplitinfo splitinfo;
M_splitinfo.getnextassoc (mappos, NID, splitinfo );
If (m_splitinfo [NID]. m_maxrow & m_splitinfo [NID]. m_maxcol)
{
Crect rect; getclientrect (& rect );
Int Cx = rect. Width (); int Cy = rect. Height ();

// Normaly always toolbar & statusbar
Cy = cy-56; If (CY <56) Cy = 0;

If (m_splitinfo [NID]. m_maxcol) CX/= m_splitinfo [NID]. m_maxcol;
If (m_splitinfo [NID]. m_maxrow) cy/= m_splitinfo [NID]. m_maxrow;
Csize sizedefault (CX, CY );

M_splitinfo [NID]. m_wndsplitter.createstatic (this, m_splitinfo [NID]. m_maxrow, m_splitinfo [NID]. m_maxcol );
// Disable View ID to use for next Splitter
M_splitinfo [NID]. m_wndsplitter.setdlgctrlid (0 );
 
Tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Cintragldoctemplate * ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
If (ptemplate-> m_nsplitterid = NID)
{
// Create View
Int nrow = ptemplate-> m_nrow, ncol = ptemplate-> m_ncol;
Pcontext-> m_pnewdoctemplate = ptemplate;
Pcontext-> m_pnewviewclass = ptemplate-> getviewclass ();
If (! M_splitinfo [NID]. m_wndsplitter.createview (nrow, ncol,
Pcontext-> m_pnewviewclass, sizedefault, pcontext) return false;
Ptemplate-> m_pview = (cview *) m_splitinfo [NID]. m_wndsplitter.getpane (nrow, ncol );
}
}
// Disable View ID to use for next splitter View
Tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Cintragldoctemplate * ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
If (ptemplate-> m_nsplitterid = NID)
Ptemplate-> m_pview-> setdlgctrlid (0 );
}
}
}

// Create the other views (no splitter)
Tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Cintragldoctemplate * ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
If (ptemplate-> m_nsplitterid =-1)
{
Pcontext-> m_pnewviewclass = ptemplate-> getviewclass ();
Pview = (cview *) createview (pcontext, afx_idw_pane_first );
Assert (pview! = NULL );
Ptemplate-> m_pview = pview;
// Disable View ID to use for next view
Pview-> setdlgctrlid (0 );
}
}
Setactiveview (null );

Cintragldoctemplate * ptemplate;

// Litle problem! If a cricheditview is in the View list
// We must activate it first to update the layout correctly
Ptemplate = PAPP-> gettemplate (runtime_class (cmodelview ));
If (ptemplate) activateview (ptemplate-> getviewclass ());

// Activate the first doctemplate View
Ptemplate = PAPP-> getfirsttemplate ();
Activateview (ptemplate-> getviewclass ());

Return true;
}

Void cmainframe: activateview (cruntimeclass * pviewclass)
{
Cintraglapp * PAPP = (cintraglapp *) afxgetapp ();
Cview * pactiveview = getactiveview ();
Cintragldoctemplate * pnewtemplate = PAPP-> gettemplate (pviewclass );
Cintragldoctemplate * pactivetemplate = PAPP-> gettemplate (pactiveview );

// The View class doesn' t exist
If (pnewtemplate = NULL) return;
 
// The new template is the Active Template, do nothing
If (pnewtemplate = pactivetemplate) return;

// The active and new template are in the same splitter, change the active View
If (pactivetemplate! = NULL)
{
If (pactivetemplate-> m_nsplitterid! =-1 &&
Pactivetemplate-> m_nsplitterid = pnewtemplate-> m_nsplitterid)
{
Updateresource (pnewtemplate );
Setactiveview (pnewtemplate-> m_pview );
Return;
}

// The active view is in a splitter, hide all views in the splitter and the Splitter
If (pactivetemplate-> m_nsplitterid! =-1)
{
Position tmppos;
Cintragldoctemplate * ptemplate;
Int nid = pactivetemplate-> m_nsplitterid;
Tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
If (ptemplate-> m_nsplitterid = NID)
{
Ptemplate-> m_pview-> showwindow (sw_hide );
Ptemplate-> m_pview-> setdlgctrlid (0 );
}
}
// Hide the Splitter
M_splitinfo [NID]. m_wndsplitter.setdlgctrlid (0 );
M_splitinfo [NID]. m_wndsplitter.showwindow (sw_hide );
}
// The active view is not in a splitter, hide this view
Else
{
Pactivetemplate-> m_pview-> setdlgctrlid (0 );
Pactivetemplate-> m_pview-> showwindow (sw_hide );
}
}

// The new view is in a splitter, show all splitter views and the Splitter
If (pnewtemplate-> m_nsplitterid! =-1)
{
Position tmppos;
Cintragldoctemplate * ptemplate;
Int nid = pnewtemplate-> m_nsplitterid;
Tmppos = PAPP-> getfirstdoctemplateposition ();
While (tmppos)
{
Ptemplate = (cintragldoctemplate *) PAPP-> getnextdoctemplate (tmppos );
If (ptemplate-> m_nsplitterid = NID)
{
Int nrow = ptemplate-> m_nrow;
Int ncol = ptemplate-> m_ncol;
Int ndlgid = m_splitinfo [NID]. m_wndsplitter.idfromrowcol (nrow, ncol );
Ptemplate-> m_pview-> setdlgctrlid (ndlgid );
Ptemplate-> m_pview-> showwindow (sw_show );
}
}
// Show the Splitter
M_splitinfo [NID]. m_wndsplitter.setdlgctrlid (afx_idw_pane_first );
M_splitinfo [NID]. m_wndsplitter.showwindow (sw_show );
}
// The new view is not in a splitter, active the New View
Else
{
Pnewtemplate-> m_pview-> setdlgctrlid (afx_idw_pane_first );
Pnewtemplate-> m_pview-> showwindow (sw_show );
}

Updateresource (pnewtemplate );

// Display and update the new view
Setactiveview (pnewtemplate-> m_pview );
Recalclayout ();
}

Bool cmainframe: isviewactive (cruntimeclass * pviewclass)
{
Cview * pactiveview = getactiveview ();
If (pactiveview = NULL) return false;
Return (pactiveview-> getruntimeclass () = pviewclass );
}

Void cmainframe: updateresource (cintragldoctemplate * pnewtemplate)
{
Cintraglapp * PAPP = (cintraglapp *) afxgetapp ();

// Support for view context menu, accelerator and help Id like MDI
Hinstance hinst = afxfindresourcehandle (makeintresource (pnewtemplate-> getresourceid (), rt_menu );

// If menu is not the default menu, destroy it
Hmenu =: getmenu (m_hwnd );
If (hmenu! = M_hmenudefault): destroymenu (hmenu );
// Load menu from doctemplate
Hmenu =: loadmenu (hinst, makeintresource (pnewtemplate-> getresourceid ()));
// If no menu, get default
If (hmenu = NULL) hmenu = m_hmenudefault;
// Load menu
: Setmenu (m_hwnd, hmenu );

// Load new accelerator table
Haccel =: loadaccelerators (hinst, makeintresource (pnewtemplate-> getresourceid ()));
// If no table for this template, load default
If (haccel = NULL): loadaccelerators (hinst, makeintresource (PAPP-> getfirsttemplate ()-> getresourceid ()));
 
// Chage help ID for this view
M_nidhelp = pnewtemplate-> getresourceid ();

// Change the title of the document
Pnewtemplate-> getdocstring (m_strtitle, cdoctemplate: windowtitle );
Onupdateframetitle (true );
}

// The command notification function is

Void cmainframe: onviewmodel ()
{
// Todo: add your command handler code here
Activateview (runtime_class (cmodelview ));
 
}

Void cmainframe: onupdateviewmodel (ccmdui * pcmdui)
{
// Todo: add your command update UI handler code here
Pcmdui-> setcheck (isviewactive (runtime_class (cmodelview )));
 
}

<Code end>

If you need the source code please email to me. hongxian.qin@autodesk.com

Created by hongxianqin

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.