Many ActiveX controls, such as: ActiveMovie, the stop button in the IE toolbar, have special meaning for them. When the Stop button is in time these controls can stop playing background music or animations. This article will tell you to add the IOleCommandTarget interface to the ActiveX control to catch the Stop button action.
Detailed content
To support the IOleCommandTarget interface you must manually add the following code to the. h and. cpp files of the COleControl derived class. You can then capture the olecmdid_stop command ID (the ID of the stop button in the IE toolbar) in the IOleCommandTarget::Exec () function. The specific code is as follows:
The. h file of the
//COleControl derived class:
class Cmyolecontrol:public COleControl
{
...
//Interface Maps
Protected:
//ADD The following to support the IOleCommandTarget Interface.
//Note:ne Sted class name is called Cmdtargetobj
Declare_interface_map ()
Begin_interface_part (Cmdtargetobj, IOleCommandTarget)
Stdmethod (querystatus) (const guid*, ULONG, olecmd[], olecmdtext*);
STDMETHOD (Exec) (const guid*, DWORD, DWORD, variantarg*,
variantarg*);
End_interface_part (cmdtargetobj)
};
//colecontrol. cpp files for derived classes:
Begin_interface_map (Cmyolecontrol, COleControl)
Interface_part (Cmyolecontrol , Iid_iolecommandtarget, Cmdtargetobj)
End_interface_map ()
ULONG FAR EXPORT cmyolecontrol::xcmdtargetobj:: AddRef ()
{
Method_prologue (Cmyolecontrol, cmdtargetobj)
return Pthis->externaladdref ();
}
ULONG FAR EXPORT cmyolecontrol::xcmdtargetobj::release ()
{
Method_prologue (Cmyolecontrol, Cmdtargetobj)
Return Pthis->exTernalrelease ();
}
HRESULT FAR EXPORT cmyolecontrol::xcmdtargetobj::queryinterface (
refiid iid, void far* far* ppvobj)
{ Method_prologue (Cmyolecontrol, Cmdtargetobj)
return (HRESULT) pthis->externalqueryinterface (&IID, Ppvobj);
}
Stdmethodimp Cmyolecontrol::xcmdtargetobj::querystatus (
Const guid* pguidCmdGroup, ULONG CCmds, OLECMD Rgcmds[],
olecmdtext* pcmdtext)
{
Method_prologue (Cmyolecontrol, cmdtargetobj)
///... add YOUR own code He Re.
return S_OK;
}
Stdmethodimp Cmyolecontrol::xcmdtargetobj::exec (
Const guid* pguidCmdGroup, DWORD nCmdID, DWORD Ncmdexecopt,
variantarg* pvarargin, variantarg* pvarargout)
{
Method_prologue (Cmyolecontrol, CMDTARGETOBJ
if (nCmdID = olecmdid_stop)
{
//... The STOP button is clicked and add YOUR own code here.
//We just display a message box.
:: MessageBox (NULL, "STOP", "Cmyolecontrol", MB_OK);
}
return S_OK
}