Many ActiveX controls, such as: ActiveMovie, the STOP button in the IE toolbar has a special meaning for them. These controls can stop playing background music or animation when the STOP button is pressed. This article will tell you to add an IOLCOMMANDTARGET interface to the ActiveX control to capture the action of the STOP button. Details In order to support the iOleCommandTarget interface, you must manually add the following code in the ColeControl derived class .h and .cpp files. Then you can capture the OLECMDID_STOP command ID in the IolecommandTarget :: Exec () function (ID of the STOP button in the IE toolbar).
Specific code as follows: // .h file COleControl derived class: class CMyOleControl: public COleControl {... // Interface Maps protected:. // Add the following to support the IOleCommandTarget interface // NOTE: Nested 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)}; .cpp file // COleControl derived class: 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 here 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) {// ... STOP button is clicked, add YOUR own code here. // We just display a message box. :: MessageBox (NULL, "STOP" "