Visual C++ COM Summary reference: Using Visual C++ 5 by Kate Gregory, published by QUE 1997 | ||||||||||||||||||||||||||||||||||||||||||||||||||
ActiveX summary:
History: Clipboard -> DDE (Dynamic Data Exchange) -> OLE(Object Linking and Embedding) -> ActiveX (or COM) The rationale is to make a file system document-centered , rather than application-centered. It allows embedding or linking of objects associated with other applications in documents Thus: Compound Documents have portions developed in multiple applications. The ActiveX Container application handles compound documents. The ActiveX Server allows distributed handling of Compound Document objects. Objects can be portions of actual files. When MFC and AppWizards handle most of the complexity of COM, this is called ActiveX. At the heart of COM is the ActiveX interface, which is just a collection of pure virtual functions. All ActiveX objects must have an interface called IUnknown. This is used to find other interfaces, thru its QueryInterface() function. AddRef() and Release() keep track of applications using the interface. An ActiveX Automation server application is just a slave to other applications. It exposes functions and data (methods and properties). ActiveX Automations can only be invoked in an ActiveX Automation controller(or Container). Automation servers involve a special interface: IDispatch, which inherits from IUnknown. Added functions: GetTypeInfoCount(UINT *), GetTypeInfo(UINT, LCID, ITypeInfo **), GetIDsOfNames(REFIID, LPOLESTR **, UINT, LCID, DISPID *), and Invoke(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *). ActiveXControls are small ActiveX Automation servers that load in process. History: VBX -> OLE Custom Control (.OCX) -> ActiveX controls. These controls are event-driven. | ||||||||||||||||||||||||||||||||||||||||||||||||||
ActiveX Container Application:
Make a new MDI application using AppWizard
Class C…App has the following in InitInstance():
Class C...Doc (:COleDocument)
ON_UPDATE_COMMAND_UI(ID_PASTE_LINK, COleDocument::OnUpdatePasteLinkMenu) ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleDocument::OnUpdateObjectVerbMenu) ON_COMMAND(ID_OLE_EDIT_CONVERT, COleDocument::OnEditConvert) ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleDocument::OnUEditLinks) ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, COleDocument::OnUpdateObjectVerbMenu) The above are for Edit/Paste, Edit/PasteLink, Edit/Links, and OLE Verbs Also the C...Doc constuctor has: EnableCompoundFile(); Serialize passes straight thru to COleDocument::Serialize(ar) Class C...View: This has the new message map entries: ON_WM_SETFOCUS() ON_WM_SIZE(), ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject) ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr); Also a new member variable: C...CntrItem *m_pSelection; which is initialized to null in the constructor OnDraw needs revising. Also following functions will need code added: OnInitialUpdate(), IsSelected(), OnInsertObject(), OnSetFocus(), OnSize(), OnCancelEditCntr(). Class C...CntrItem: (:COleClientItem) Thisclass describes items contained in the document. It has a dozen functions that can be overridden. including GetDocument(), GetActiveView(), OnChange(), OnActivate(), OnGetItemPosition(), OnDeactivateUI(), OnChangeItemPosition(), AssertValid(), Dump(), and Serialize();The default for OnChange calls GetDocument()->UpdateAllViews(NULL) by default. OnActivate is called when a user tries to edit an object in place.....then put in the specific code... Contained items can get a tracker rectange (a hashed line around item) can be done with the MFC class CRectTracker: Do this by adding member variable CRect m_rect; Initialize m_rect in the constructor (the only function called once in a container item class). Then replace in C...View::OnDraw(): m_pSelection->Draw(pDC, CRect(...)); with m_pSelection->Draw(pDC, m_pSelection->m_rect); Then change C...CntrItem::OnGetItemPosition() to include rPosition = m_rect; In C...CntrItem::OnChangeItemPositon() after call to COleClientItem::OnChangeItemPosition(), add:
To cach mouse clicks and double clicks for sizing, moving or activating: Add following procedure to C...View.cpp:: C...CntrItem* C...View::HitTest(CPoint point){
Do similar job on C...View::OnDraw():
Select C...View in CLassView, choose Add Windows Message Handler. THen select WM_LBUTTONDOWN, Add and Edit handler, and support: void C...View::SetSelection(C...CntrItem* item){
void C...View::OnLButtonDown(UINT nFlags, CPoint point){
| ||||||||||||||||||||||||||||||||||||||||||||||||||
ActiveX Server:
MDI + select Full Server in Compound Document Support Class C...App gets new member: COleTemplateServer m_server
C...Doc (: COleServerDoc)
C...SrvrItem *GetEmbeddedItem(){
new line in message map:
Class C...SrvrItem provides an interface between container app and the new type of document
Class CInPlaceFrame provides things like toolbars, status bars, dialog-bars and has:
To change the file type names used by the Registry:
Then fill in code in ...Doc.h (member variables, Get functions, etc.
Add code to C..View::OnDraw(CDC*) and C...SrvrItem::OnDraw(CDC *, CSize&) etc. ActiveX Server AND Container: Select both in AppWizard (Both Container And Server radio button)
ActiveX Documents: If document extension for an ActiveX document server app, following is added to C...App::InitInstance():
ActiveX Automation ActiveX Automation exposes a collection of functions
and data (methods and properties). IDispatch is derived
from IUnknown
Embedding ActiveX Control, Java Applet. Video Clip, or Sound in an HTML Document
Registering an ActiveX Control as Safe:
Compound Document Support OLE/ActiveX Active Template Library uses actual Win32 SDK functions, rather than MFC. Advantage is no DLLs are required on other end, as only functions actually used are included. 1. In DevStudio: File/New, select ATL COM AppWizard
Control inherits from numerous template classes class ATL_NO_VTABLE CyourClass:: public CComObjectRootEx The CStockPropImpl The following COM map is the connection between all the interfaces supported by the control and IUnknown::QueryInterface():
BEGIN_COM_MAP(CyourClass)
interface IyourClass: IDispatch{
|