Create a DOC/view application as an ActiveX Control

Source: Internet
Author: User

As we all know, MFC provides a very powerful but incomprehensible programming model called a document/view structure. Its basic idea is to manage data performance and data existence separately. Improvement of MFC
Many current classes are used to achieve this goal. Generally, cframewnd, cview, and cdocument classes are used to reuse csingledoctemplate.
By concatenating them, you can easily build a single-document DOC/view application.
The following is a typical DOC/view application interface:

However
Yes. With the development of the Internet, everything is on the network. Can we make the document/view structure application into a cool application that can be used for network publishing. For example
Use a browser to operate the application. The above frame interface is embedded in the browser. Well, a good choice is to create the application as an ActiveX control. The following introduces the magic.
Cheng:
First, consider that the ActiveX control can be displayed on an HTML page as a subwindow of the browser. If you use the traditional
The cdoctemplate class links documents and views. When a new framework is generated, A Framework Window is displayed, which does not meet the purpose of embedding. Therefore, the transformation
The cdoctemplate class is required. The key points are:
1. Considering that it is embedded in olecontrol, the newly generated Framework Window uses olecontrol as the parent window.
2. This control does not have a menu because it is an embedded subwindow and a subwindow cannot have a menu. However, you can use the drop-down menu instead. Of course, the toolbar is also supported.
3. In addition to menus, most DOC/view functions will be retained.

The
Step 1: we derive a class from csingledoctemplate called cactivedoctemplate. The key is to modify two letters.
Number: createnewframe and opendocumentfile functions. Every time a new framework is created, the exclusive olecontrol window is used as the parent window.
Port. The two functions are changed as follows:
Cdocument * cactivexdoctemplate: opendocumentfile (lpctstr lpszpathname, bool bverifyexists ){
Savedocumentfile (); // Save the current document
M_docfile = lpszpathname;
If (bverifyexists ){
DWORD dwattrib = getfileattributes (lpszpathname); // obtain the document type
If (dwattrib = 0xffffffff |
Dwattrib = file_attribute_directory) // if it is a directory
{
Lpszpathname = NULL;
}


}

Return csingledoctemplate: opendocumentfile (lpszpathname, true );
}

Cframewnd * cactivexdoctemplate: createnewframe (cdocument * pdoc, cframewnd * pother ){
Assert (pother = NULL );
Assert (m_pframeclass! = NULL );

If (pdoc! = NULL)
Assert_valid (pdoc); // check the object Validity

// Create a framework and connect it with the relevant documents
Ccreatecontext context;
Context. m_pcurrentframe = pother;
Context. m_pcurrentdoc = pdoc;
Context. m_pnewviewclass = m_pviewclass;
Context. m_pnewdoctemplate = this;

M_pframewnd = (cframewnd *) m_pframeclass-> Createobject ();
If (m_pframewnd = NULL ){
Trace1 ("Warning: Dynamic create of frame % hs failed./N ",
M_pframeclass-> m_lpszclassname );
Return NULL;
}

Assert_kindof (cframewnd, m_pframewnd );
If (context. m_pnewviewclass = NULL)
Trace0 ("Warning: creating frame with no default view./N ");

Assert_kindof (cactivexdoccontrol, m_pparentwnd );
If (! M_pframewnd-> Create (null, "", ws_child | ws_visible, cframewnd: rectdefault, m_pparentwnd, null, 0, & context )){
Trace0 ("Warning: cdoctemplate couldn't create a frame./N ");
Return NULL;
}
Return m_pframewnd;

}

Step 2: derive a cactivexdoccontrol class from the colecontrol class to transform the colecontrol class
Contains a pointer to cactivedoctemplate. With this pointer, we can create a framework window and save the document content to complete the general DOC/view application.
. The contents of the transformed cactivexdoccontrol header file are as follows:
Class cactivexdoccontrol: Public colecontrol {
Enum {wm_idleupdatecmdui = 0x0363 };

Static bool m_bdocinitialized;
Cactivexdoctemplate * m_pdoctemplate;
Cframewnd * m_pframewnd;
// Setinitialsize (100,100 );
Declare_dynamic (cactivexdoccontrol)
 
Protected:
Void adddoctemplate (cactivexdoctemplate * pdoctemplate );
Cdoctemplate * getdoctemplate () {return m_pdoctemplate ;}
 
Afx_msg int oncreate (maid );
Afx_msg void onsize (uint ntype, int CX, int CY );
Afx_msg void ontimer (uint nidevent );
Afx_msg void ondestroy ();

Declare_message_map ();
Declare_dispatch_map ();
Declare_event_map ();

Public:
Cactivexdoccontrol ();
Virtual ~ Cactivexdoccontrol ();

Enum {

};
};

Add doctemplate to the constructor of the control class:
Adddoctemplate (New cactivexdoctemplate (
Runtime_class (cmy55doc ),
Runtime_class (cmy55frame ),
Runtime_class (cmy55view)
));

Now, the basic framework has been created, and the rest of the process is to build the DOC/view application.
Through these steps, we can easily transform the existing document/View Structure applications into ActiveX controls that can be displayed on the browser. In this way, most of the functions of the existing program are retained and can be published online, so that users can access and use it through a browser.

The following is the interface on which the preceding document/view application runs and operates in the browser after transformation:

Ben
See the design ActiveX components with the MFC Document/View on msdn.
Model.

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.