To detect the press of the Stop button in IE in an ActiveX control

Source: Internet
Author: User

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
}

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.