[MSDN] ActiveX Controls 备忘

MSDN ActiveX Controls 备忘


Introduction to ActiveX Controls
http://msdn.microsoft.com/en-us/library/aa751972%28VS.85%29.aspx


◆ MSDN -- ActiveX Controls ■=□=■=□=■=□=■=□=■=□=■=□=■=□=■

● About ActiveX Controls

a simple OLE object that supports the IUnknown interface.

OLE programs should use QueryInterface to acquire interface pointers, and must check
the return value. OLE apps cannot safely assume that QueryInterface will succeed.
not available returns E_NOINTERFACE

just another term for "OLE Object" or "Component Object Model (COM) Object".

Self-Registration
must support self-registration by impl DllRegisterServer and DllUnregisterServer.
must register all the standard registry entries for embeddable objects and automation servers.
In addition, might register the "control" keyword to allow older containers, such as VB4.
should also register the ToolBoxBitmap32 registry key.

What Support for an Interface Means

‧ IOleObject
  If the control requires communication with its client site for events.
  impl this interface, must support: IOleObject::SetHostNames, ...

‧ IOleInPlaceObject
‧ IOleInPlaceActiveObject

‧ IOleControl
  deal with mnemonics (IOleControl::GetControlInfo, IOleControl::OnMnemonic);
  ambient properties (IOleControl::OnAmbientPropertyChange);
  and/or events requires the container to handle (IOleControl::FreezeEvents).

‧ IDataObject
  Indicates that the control can supply at least graphical renderings of the control
  (CF_METAFILEPICT). ::GetData, ::QueryGetData, ::EnumFormatEtc, ::DAdvise, ...

‧ IViewObject2

‧ IDispatch
  Indicates that the control has either custom methods or custom properties that are both
  available by late-binding through IDispatch::Invoke. requires type through other IDispatch
  methods. can support multiple IDispatch impl where only one is associated with IID_IDispatch
  -- the others must have their own unique dispinterface identifiers. encouraged to supply
  dual interfaces for custom method and property access.

‧ IConnctionPointContainer
‧ IProvideClassInfo2

‧ ISpecifyPropertyPages
  has property pages that it can display so that a container can coordinate this control's
  property pages with other controls' pages when property pages are to be shown for a
  multicontrol selection.

‧ IOleCache2
  Indicates support for container caching of control visuals. A control generally obtains
  caching support itself through the OLE CreateDataCache function. Only controls with
  meaningful static content should choose to do this.

‧ IExternalConnection
  Indicates that the control supports external links to itself; that is, the control is
  not marked with OLEMISC_CANTLINKINSIDE and supports IOleObject::SetMoniker and
  IOleObject::GetMoniker. A container never queries for this interface itself nor calls
  it directly, because calls are generated from inside OLE's remoting layer.

‧ IRunnableObject
  Indicates that the control differentiates being "loaded" from being "running",
  as some in-process objects do.


Persistence Interfaces
minimum impl either IPersistStream or IPersistStreamInit (not together).
is used when a control wants to know when it is created new as oppsed to reloaded
from an existing persistent state. can save and load its persistent state into a stream (IStream).

‧ IPersistStream, IPersistStreamInit, IPersistMemory

‧ IPersistStorage

‧ IPersistMoniker, IPersistPropertyBag

Optional Methods

‧ IOleControl::GetControlInfo, IOleControl::OnMnemonic
‧ IOleControl::OnAmbientPropertyChange
‧ IOleControl::FreezeEvents
‧ IOleObject::SetMoniker
‧ IOleObject::GetMoniker
‧ IOleObject::InitFromData
‧ GetClipboardData
‧ IOleObject::SetExtend
‧ IOleObject::GetExtend
‧ IOleObject::SetColorScheme
‧ IOleObject::DoVerb

Class Factory Options
An ActiveX control, by virtue of being a COM object, must have associated server code that
supports control creation through IClassFactory as a minimum.

It's optional, not required, also supports IClassFactory2 for licensing management.
Only those vendors that are concerned about licensing need to support COM's licensing mechanism.

Porperty Pages
should standard size: 250 x 62 or 250 x 110 dialog window units (DLUs)

Ambient Properties
LocalID           -705
UserMode          -709
UIDead            -710
ShowGrabHandles   -711  if control supports in-place resizing of itself.
ShowHatching      -712  if control supports in-place activation and UI activation.
DisplayAsDefault  -713  only marked OLEMISC_ACTSLIKEBUTTON

Using the Container's Functionality
‧ IOleClientSite
  ::SaveObject, ::ShowObject, ::OnShowWindow ...

‧ IOleInPlaceSite
‧ IAdviseSink
‧ IOleControlSite
‧ IDispatch
‧ IPropertyNotifySink
‧ IOleInPlaceFrame
‧ IOleInPlaceUIWindow

- General Guidelines

Overloading IPropertyNotifySink
If a control's properties are altered through the control's property pages, the control's
property page, the control's properties can get out of sync with the container's view of
those properties. To ensure that it always has the current values for a control's props,
An ActiveX control container can overload the IProperty NotifySink interface (data binding)
and also use it to be notified that a control property has changed.

Multithreaded Issues
Starting Win95 and NT3.5.1, OLE provides support for multithreaded apps, allowing apps
to make OLE calls from multiple threads. called "apartment model" The apartment model
requires that interface pointers are marshaled (CoMarshallInterface and CoUnmarshallInterface)
when passed between threads.

Event Freezing
A container can notify a control that it is not ready to respond to events by calling
IOleControl::FreezeEvents(TRUE). unfreeze by calling IOleControl::FreezeEvents(FALSE).

Multiple Controls in One DLL
A single .ocx DLL can container any number of ActiveX Controls, thus simplifying the
distribution and use of a set of related controls.

be sure include the vendor name in each control name in the package. Including the vendor's
names in each control naem enables users to easily identify controls within a package.

  Con1 Control
  Con2 Control
  Con3 Control


● About Control Instantiation




















~ THE END ~

原文:大专栏  [MSDN] ActiveX Controls 备忘


猜你喜欢

转载自www.cnblogs.com/petewell/p/11465797.html