⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mvdoctemplate.hpp

📁 Visual C++下的界面设计
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// Created by: Yog Sothoth
// Company: The Old Ones
// More Info: Azathoth@Cyberdude.com
// Home Page: http://www.geocities.com/SiliconValley/Peaks/2976/

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @doc
// @module	MvDocTemplate.hpp | 
//			This module allow you to use document with multiple views.  It
//			can be multiple document interface or single document interface.
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Definition to avoid multiple include.
// ------------------------------------------------------------------------
#if !defined( _MvDocTemplate_H_ )
#define _MvDocTemplate_H_ 
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Include file section.
// ------------------------------------------------------------------------
// Template include file.
#include <afxtempl.h>
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Definition.
// ------------------------------------------------------------------------
class CSDIMVDocTemplate;	// The single document interface class.
class CMDIMVDocTemplate;	// The multi document interface class.
class CMvDocTemplate;		// The document interface base class.

class CDocFrameMgr;			// Manage the list of open frame for a specific doc.
class CFrameTemplate;		// Specific frame information.
class CFrame;				// The frame itself.

// Doing some definition to simplify the code.  The reason why I didn't use
// stl list is to keep that extension MFC specific only and to avoid adding
// an overload to it.
typedef CList< CFrame*, CFrame*& > FrameList_;
typedef CList< CDocFrameMgr*, CDocFrameMgr*& > DocumentFrameList_;
typedef CList< CFrameTemplate*, CFrameTemplate*& > FrameTemplateList_;
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Class declaration.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @class:  (FUNCTIONAL_CLASS)
//          This is used to define each specific frame that are associated
//			with your document template.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
class CFrameTemplate
{
    // --------------------------------------------------------------------
    // @group Data definition.
    // --------------------------------------------------------------------
    private:
		CRuntimeClass* m_pFrameClass;	// To be able to create the frame instance.
		CRuntimeClass* m_pViewClass;	// To be able to create the view instance.
		UINT m_nResourceID;				// The associated resource id for menu, icon, ...
		UINT m_nEventID;				// The associated event id used to open or create the window.
		UINT m_nDefaultWndStatus;		// The status of the window at load time.
		BOOL m_bLoadAtStartup;			// To allow loading the window later.

    public:
    protected:

    // --------------------------------------------------------------------
    // @group Implementation Method definition.
    // --------------------------------------------------------------------
	private:
	public:
		// Constructor.  The only required information is the resource id, the
		// frame RTC, the view RTC and the event ID so that you can display your
		// window.
		CFrameTemplate(
            UINT _nIDResource, CRuntimeClass* _pFrameClass, CRuntimeClass* _pViewClass,
            UINT _nEventID, UINT _nDefaultWndStatus = WS_VISIBLE, 
			BOOL _bLoadAtStartup = FALSE )
		{
			m_nResourceID		= _nIDResource;
			m_pFrameClass		= _pFrameClass;
			m_pViewClass		= _pViewClass;
			m_nEventID			= _nEventID;
			m_nDefaultWndStatus	= _nDefaultWndStatus;
			m_bLoadAtStartup	= _bLoadAtStartup;
		}	

		// Wrapper functions to get object attributes.
		// No need for set functions since everything is provide by the constructor
		// and that the concept of document template is static for an application.
		CRuntimeClass* GetFrameRTC( void )	 	{ return m_pFrameClass; };
		CRuntimeClass* GetViewRTC( void )		{ return m_pViewClass; };
		UINT GetResourceID( void )		 		{ return m_nResourceID; };
		UINT GetEventID( void )		 			{ return m_nEventID; };
		UINT GetDefaultWndStatus( void )		{ return m_nDefaultWndStatus; };
		BOOL GetLoadAtStartup( void )			{ return m_bLoadAtStartup; };

	protected:
};

// Starting from here you will find class that are private to the different
// class declore before.  You don't need to use those class.  In fact they
// should have been put in the private declaration of the class that are
// using them.

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @class:  (IMPLEMENTATION_CLASS)
//			This is the base class for the doc template define before. Will
//			manage a document manager instance for each document open.
// @base    public | CMultiDocTemplate
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
class CMvDocTemplate : public CMultiDocTemplate
{
    // --------------------------------------------------------------------
    // @group Macro definition.
    // --------------------------------------------------------------------

    // --------------------------------------------------------------------
    // @group Data definition.
    // --------------------------------------------------------------------
    private:
    public:
    protected:
        CFrameTemplate* m_pFrameToActivate;		// The frame to show on top when opening doc.
        BOOL m_bAutoDelete;						// Flag to know if we must delete the doc when 
												// all window are closed.
        
        FrameTemplateList_ m_FrameTemplateList;	// The list of frame to open with the document.
		DocumentFrameList_ m_DocumentFrameList;	// The list of document currently open for
												// that type of document.

    // --------------------------------------------------------------------
    // @group Implementation Method definition.
    // --------------------------------------------------------------------
    private:
		// Helpfull class to get the document associated document frame manager.
		CDocFrameMgr* GetAssociatedDocFrameMgr( CDocument* _pDoc );

    public:
		// Constructor.  Those information are directly passed to the
		// base class that will manage the document creation.
        CMvDocTemplate(	UINT _nIDResource, CRuntimeClass* _pDocClass, 
						BOOL _bAutoDelete = TRUE );
        virtual ~CMvDocTemplate( void );

        // We overload the open document method to prepare and open all frame.
        virtual CDocument* OpenDocumentFile( LPCTSTR _lpszPathName, BOOL _bMakeVisible );   

    protected:
		// When removing a document, we must clean the associated allocated
		// memory.
        virtual void CleanDocument( CDocument* _pDoc );

    // --------------------------------------------------------------------
    // @group Funcional Method definition.
    // --------------------------------------------------------------------
    private:
    public:
        // To add a specific frame template to that kind of document.
        virtual void AddFrameTemplate(	CFrameTemplate* _pFrameTemplate, 
										bool _bActivate = false );
        
        // Register the associated icon with the document.  Actually fix a
		// problem with the way MS register your document icon in the system.
        void RegisterIconType( void );

    protected:

    // --------------------------------------------------------------------
    // @group MFC Definition.
    // --------------------------------------------------------------------
    private:
    public:
        // Overloaded method to manage the list of frame.
        CFrameWnd* CreateNewFrame(	CDocument* _pDoc, CFrameWnd* _pOther );
        void InitialUpdateFrame(	CFrameWnd* _pFrame, CDocument* _pDoc, 
									BOOL _bMakeVisible = TRUE );

		// Overloaded method to open the frame associated with the event id.
        BOOL OnCmdMsg(	UINT _nID, int _nCode, void* _pExtra, 
						AFX_CMDHANDLERINFO* _pHandlerInfo );
        
    protected:
};

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @class:  (IMPLEMENTATION_CLASS)
//          Manage the list of frame template for a given document instance.
//			For each document open, there is an associated instance of that
//			class.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
class CDocFrameMgr
{
    // --------------------------------------------------------------------
    // @group Type definition.
    // --------------------------------------------------------------------
    
	// --------------------------------------------------------------------
    // @group Data definition.
    // --------------------------------------------------------------------
	private:
		// List member.
		FrameList_	m_FrameList;			// The list of frame use by this document.
        CFrame*		m_pFrameToActivate;		// The frame to activate when loading.
		CDocument*	m_pDocument;			// The associated document instance.

	public:
	protected:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -