描述:
我用ATL编写了一个程序,完成对word的开发。现在对word文档的结构做一些改动,添加自定义的流,出现了很头痛的问题:
1、为什么在Word文档中自己创建的存储对象和流对象在文档修改过之后保存或另存为时全部丢失了。不知道Word的保存机制是什么,我在哪里可以查到相关方面的资料呢。
2、Word在保存文档之后是否给我们开发人员提供了接口,来处理保存之后的事件。因为我想在文档保存后知道它在保存之前的文档名。我现在只能做到响应保存之前的DocumentBeforeSave()函数。
解决方案1:
这个问题俺以前遇到过,
印象中你的控件要实现 IPersistStreamInit或者类似的接口
word文件在保存的时候,会自动调用该接口的几个方法,
你可以在接口方法中把你的数据写入到传递来的Stream对象中。
参考Knowledge Base Q241936,PRB: ATL Control Properties Do Not Persist when Embedded in Word。
Try DocumentBeforeClose(), it may work.
/////
interface IApplicationEvents2 : IDispatch {
[id(0x00000001), restricted, hidden]
HRESULT Startup();
[id(0x00000002), helpcontext(0x00061a82)]
HRESULT Quit();
[id(0x00000003), helpcontext(0x00061a83)]
HRESULT DocumentChange();
[id(0x00000004), helpcontext(0x00061a84)]
HRESULT DocumentOpen([in] Document* Doc);
[id(0x00000006), helpcontext(0x00061a85)]
HRESULT DocumentBeforeClose(
[in] Document* Doc,
[in] VARIANT_BOOL* Cancel);
[id(0x00000007), helpcontext(0x00061a86)]
HRESULT DocumentBeforePrint(
[in] Document* Doc,
[in] VARIANT_BOOL* Cancel);
[id(0x00000008), helpcontext(0x00061a87)]
HRESULT DocumentBeforeSave(
[in] Document* Doc,
[in] VARIANT_BOOL* SaveAsUI,
[in] VARIANT_BOOL* Cancel);
[id(0x00000009), helpcontext(0x00061a88)]
HRESULT NewDocument([in] Document* Doc);
[id(0x0000000a), helpcontext(0x00061a89)]
HRESULT WindowActivate(
[in] Document* Doc,
[in] Window* Wn);
[id(0x0000000b), helpcontext(0x003d090a)]
HRESULT WindowDeactivate(
[in] Document* Doc,
[in] Window* Wn);
[id(0x0000000c), helpcontext(0x003d090b)]
HRESULT WindowSelectionChange([in] Selection* Sel);
[id(0x0000000d), helpcontext(0x003d090c)]
HRESULT WindowBeforeRightClick(
[in] Selection* Sel,
[in] VARIANT_BOOL* Cancel);
[id(0x0000000e), helpcontext(0x003d090d)]
HRESULT WindowBeforeDoubleClick(
[in] Selection* Sel,
[in] VARIANT_BOOL* Cancel);
};