我用C++写了一个ATL,在WORD启动的时候跟着启动,现在想拦截(重载)WORD中的事件或命令,比如说FILEOPEN(),FILESAVE()等等,该如何实现?
回答用VBA写WORD模板的不给分。
回答用VBA写WORD模板的不给分。
解决方案 »
- Alpha一个ATL类继承了一个绘图类//接口函数{Fun();//找不标示符?}
- 点击对话框上的任何控件 vc崩溃
- 分割窗体问题
- ATL 事件订阅的问题,怎么不能给500分?
- 关于缺少dll的问题
- 用INADDR_ANY方式,在宽带拨号上网方式下或得的是内部IP,怎样才能获得公共IP?
- nt下如何做到wininit.ini的效果?
- 如何在vc中修改ldap服务器中的结点属性
- 动态申请2维数组。释放的时候出错。请高人指点!!
- 请教下,流媒体视频编码解码编程
- 100分求:如何实现位图原文件图像的直接平滑缩放后保存,不经过StretchBlt,求源码。
- 相约潘爱民,共同领略VISUAL C++.NET技术精髓
How To Catch Microsoft Word97 Application Events Using VC++
View products that this article applies to.
This article was previously published under Q183599
Probably in your addin, you'd also be interested in handling some of Word's events.A case in point is the Application objects DocumentOpen event, with DISPID=4, which is handled here. Word has a complex object model and you will find a host of other such events. If you use the good old OLE/COM Object Viewer to view msword9.olb, you'd find IDL like : .... [id(0x00000003), helpcontext(0x00061a83)]
void DocumentChange();
[id(0x00000004), helpcontext(0x00061a84)]
void DocumentOpen([in] Document* Doc); ......As before we will use ATL's IDispEventSimpleImpl<> template class to implement our sink. For brevity, only the changes necessary to the earlier code has been mentioned.extern _ATL_FUNC_INFO DocumentOpenInfo;class ATL_NO_VTABLE CAddin :
public CComObjectRootEx,
public CComCoClass,
public ISupportErrorInfo,
public IDispatchImpl,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2,
&LIBID_AddInDesignerObjects>,
public IDispEventSimpleImpl<1,CAddin,
&__uuidof(MSWord::ApplicationEvents2)>
{
public:
....
....void __stdcall DocumentOpen(IDispatchPtr ptr)
{
CComQIPtr<_Document> spDoc(ptr);
ATLASSERT(spDoc);
....
....
}BEGIN_SINK_MAP(CAddin)
SINK_ENTRY_INFO(1,__uuidof(MSWord::ApplicationEvents2),4,
DocumentOpen,&DocumentOpenInfo)
END_SINK_MAP()private:
CComPtr<MSWord::_Application> m_spApp;
};DocumentOpenInfo is defined at the top of CAddin.cpp as _ATL_FUNC_INFO DocumentOpenInfo = {CC_STDCALL,VT_EMPTY,1,
{VT_DISPATCH|VT_BYREF}};All that remains for us to do is to add the code to setup and break down the connection. Using the ATL template class, therefore all we have to do is call DispEventAdvise() and DispEventUnadvise(). Our CAddin's OnConnection() and OnDisconnection(), needless to say, is the right place for doing this.CComQIPtr<_Application> spApp(Application);
ATLASSERT(spApp);
m_spApp = spApp;
HRESULT hr = DispEventAdvise(m_spApp);
if(FAILED(hr))
return hr;
and in OnDisconnection(), DispEventUnadvise(m_spApp);
m_spApp = NULL;