<b>在ActiveX控件中检测IE中STOP按钮的按下</b>[VC/C++编程]
本文“<b>在ActiveX控件中检测IE中STOP按钮的按下</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
很多ActiveX控件,比方:ActiveMovie, IE工具条中的Stop按钮关于他们来说有特别的意义.当Stop按钮下按时这些控件可以终止播放后台音乐或动画.这篇文章将奉告你在ActiveX控件中增添IOleCommandTarget接口来捕捉Stop 按钮的行动.
具体内容
为了支持IOleCommandTarget接口你必须手工在COleControl派生类的.h 和.cpp文件中增添以下代码.然后,你可以在IOleCommandTarget::Exec()函数中捕捉OLECMDID_STOP号令id (IE工具条中Stop 按钮的id).具体代码以下:
// COleControl派生类的.h文件:
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)
};
//COleControl派生类的.cpp文件:
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","CMyOleControl", MB_OK);
}
return S_OK;
}
以上是“<b>在ActiveX控件中检测IE中STOP按钮的按下</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |