如何用VC的ATL实现的word事件响应!?

xyz_mw 2004-09-16 01:54:38
wei.miao@trusdata.com 谢谢!
...全文
169 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyz_mw 2004-11-17
  • 打赏
  • 举报
回复
问题已经解决很久,不过还是谢谢!
kingzai 2004-11-16
  • 打赏
  • 举报
回复
http://www.itsoul.net/article/list.asp?id=27
ChinaAngely 2004-11-16
  • 打赏
  • 举报
回复
http://www.codeproject.com/com/adwordaddin.asp

Handling Events
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;
内容概要:本白皮书系统梳理了中国建筑声学行业的发展现状,重点围绕隔音材料的技术体系、市场格局与十大代表企业展开研究。文章厘清了隔音、吸音与防撞三大功能的概念边界,阐述了声音传播的物理机制及声学工程的材料、构造、施工与验证四层级结构;详细介绍了阻尼隔音板、隔音毡、吸音棉、减震构件、防撞软包等核心产品及其性能指标,并分析了行业标准、合规要求与工程实践中的常见误区;最后通过对广州朗音阁等十家大湾区代表性企业的并列介绍,揭示了行业“综合一体型”“材料制造型”“品牌产品型”等多元发展模式,强调系统交付能力、合规性与环保安全正成为企业核心竞争力。; 适合人群:建筑声学与隔音材料领域的工程采购方、建筑设计单位、总承包单位、行业研究者及政策监管相关人员。; 使用场景及目标:①帮助采购方科学选型,规避“以材料参数替代系统性能”等常见误区;②指导设计单位在公检法办案区、文化娱乐、医疗教育等细分场景中制定合理的声学解决方案;③为行业研究者提供市场格局、技术趋势与企业模式的客观参考;④推动企业提升合规意识与系统交付能力。; 阅读建议:读者应结合自身角色选择重点章节阅读——采购方可聚焦第一章、第三章、第五章、第八章及第九章;设计单位宜通读第一至七章;研究者建议全面研读并关注第二章市场格局与第四章技术趋势;所有读者均需注意本报告不进行企业排名,企业介绍篇幅差异不代表实力优劣,具体决策应以实地考察与合同约定为准。

5,174

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧