VC如何对word文档不同字设置不同颜色

wq1982718 2013-12-21 12:07:33
我想实现这样功能:对一个句子中的不同词语设置不同颜色,有如下代码。

Selection wsel;
wsel = wwin.GetSelection();
wsel.WholeStory();

_Font f1,f2;
Range r1,r2;
f1 = wsel.GetFont();
f1.SetColorIndex((long)3);
wsel.SetFont(f1);
wsel.TypeText("颜色一");

f2 = wsel.GetFont();
f2.SetColorIndex((long)2);
wsel.SetFont(f2);
f1.SetColorIndex((long)1);
wsel.InsertAfter("其他颜色");

但是运行到 wsel.SetFont(f2); 时就报错“参数不正确”,而前面的wsel.SetFont(f1);就可以执行,请问这个是怎么回事? 我这个功能应该如何实现呢

...全文
332 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
boylafong 2013-12-31
  • 打赏
  • 举报
回复
引用 3 楼 wq1982718 的回复:
[quote=引用 1 楼 boylafong 的回复:] 貌似 wsel = wwin.GetSelection();要重调下
加了 wsel = wwin.GetSelection(); 还是报同样的错误“参数不正确” Selection wsel; wsel = wwin.GetSelection(); wsel.WholeStory(); _Font f1,f2; f1 = wsel.GetFont(); f1.SetColorIndex((long)3); wsel.SetFont(f1); wsel.TypeText("颜色一"); wsel = wwin.GetSelection(); f2 = wsel.GetFont(); f2.SetColorIndex((long)2); wsel.SetFont(f2); wsel.InsertAfter("其他颜色"); [/quote] 我做插件也有类似的问题,wwin需要释放掉再重新GetSelection,很奇怪。
wq1982718 2013-12-30
  • 打赏
  • 举报
回复
引用 1 楼 boylafong 的回复:
貌似 wsel = wwin.GetSelection();要重调下
加了 wsel = wwin.GetSelection(); 还是报同样的错误“参数不正确” Selection wsel; wsel = wwin.GetSelection(); wsel.WholeStory(); _Font f1,f2; f1 = wsel.GetFont(); f1.SetColorIndex((long)3); wsel.SetFont(f1); wsel.TypeText("颜色一"); wsel = wwin.GetSelection(); f2 = wsel.GetFont(); f2.SetColorIndex((long)2); wsel.SetFont(f2); wsel.InsertAfter("其他颜色");
wq1982718 2013-12-30
  • 打赏
  • 举报
回复
加了 wsel = wwin.GetSelection(); 还是报同样的错误“参数不正确” Selection wsel; wsel = wwin.GetSelection(); wsel.WholeStory(); _Font f1,f2; f1 = wsel.GetFont(); f1.SetColorIndex((long)3); wsel.SetFont(f1); wsel.TypeText("颜色一"); wsel = wwin.GetSelection(); f2 = wsel.GetFont(); f2.SetColorIndex((long)2); wsel.SetFont(f2); wsel.InsertAfter("其他颜色");
boylafong 2013-12-24
  • 打赏
  • 举报
回复
貌似 wsel = wwin.GetSelection();要重调下

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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