﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-codeArt-随笔分类-COM</title><link>http://www.cppblog.com/codeart/category/14770.html</link><description>codeArt</description><language>zh-cn</language><lastBuildDate>Sun, 05 Sep 2010 00:19:10 GMT</lastBuildDate><pubDate>Sun, 05 Sep 2010 00:19:10 GMT</pubDate><ttl>60</ttl><item><title>c++操作word接口</title><link>http://www.cppblog.com/codeart/archive/2010/08/31/125430.html</link><dc:creator>codeArt</dc:creator><author>codeArt</author><pubDate>Tue, 31 Aug 2010 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/codeart/archive/2010/08/31/125430.html</guid><wfw:comment>http://www.cppblog.com/codeart/comments/125430.html</wfw:comment><comments>http://www.cppblog.com/codeart/archive/2010/08/31/125430.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codeart/comments/commentRss/125430.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codeart/services/trackbacks/125430.html</trackback:ping><description><![CDATA[注意事项：1多用Range，少用Selection，因为Word中，Selection对象只有一个。<br>【1】开启word<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">_ApplicationPtr&nbsp;word_app;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">HRESULT&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_app.CreateInstance(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Word.Application</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;NULL);&nbsp;</span></div>
【2】新建一个文档<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">COleVariant&nbsp;vTrue((</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)TRUE),vFalse((</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)FALSE),vOpt((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)DISP_E_PARAMNOTFOUND,&nbsp;VT_ERROR);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">DocumentsPtr&nbsp;docs;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">_DocumentPtr&nbsp;oDoc;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">docs&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_app</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetDocuments();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">doc&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;docs</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Add(vOpt,&nbsp;vOpt,&nbsp;vOpt,&nbsp;vOpt);&nbsp;&nbsp;</span></div>
【3】设置文档的页面布局<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">PageSetupPtr&nbsp;page_setup&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetPageSetup();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">page_setup</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutTopMargin(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">page_setup</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutBottomMargin(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">page_setup</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutRightMargin(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">page_setup</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutLeftMargin(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);</span></div>
【4】插入文本<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">SelectionPtr&nbsp;selection;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">selection&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_app</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetSelection();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">_ParagraphFormatPtr&nbsp;parafmt&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;selection</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetParagraphFormat();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">parafmt</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutLineSpacingRule(wdLineSpaceExactly);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">parafmt</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutLineSpacing(</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">_FontPtr&nbsp;font;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">font&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetFont();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutBold(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutColor(wdColorGreen);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutSize(</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutName(_T(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">宋体</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">selection</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">TypeText(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ABC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">TypeParagraph();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">TypeText(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">12345678901234567890</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">TypeParagraph();</span></div>
【5】插入文本框<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">ShapesPtr&nbsp;shapes&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetShapes();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">ShapePtr&nbsp;textbox&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;&nbsp;shapspp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">AddTextbox(Office::msoTextOrientationHorizontal,&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);</span></div>
【6】文本框中插入文本<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">ShapesPtr&nbsp;shapes&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetShapes();<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">ShapePtr&nbsp;textbox&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;&nbsp;shapspp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">AddTextbox(Office::msoTextOrientationHorizontal,&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">TextFramePtr&nbsp;textframe&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame();<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">RangePtr&nbsp;range&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;textframe</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextRange();<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;insert_before_count&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;range</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Characters</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetCount();<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">range</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">InsertAfter(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">TEXT</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(insert_before_count&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;range</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">MoveStart(COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)Word::wdCharacter),&nbsp;COleVariant(insert_before_count</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(range&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_453_667_Open_Image onclick="this.style.display='none'; Codehighlighter1_453_667_Open_Text.style.display='none'; Codehighlighter1_453_667_Closed_Image.style.display='inline'; Codehighlighter1_453_667_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_453_667_Closed_Image onclick="this.style.display='none'; Codehighlighter1_453_667_Closed_Text.style.display='none'; Codehighlighter1_453_667_Open_Image.style.display='inline'; Codehighlighter1_453_667_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_453_667_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_453_667_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;_FontPtr&nbsp;font&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;range</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetFont();<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutBold(isBold);<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutItalic(isItalic);<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutColor((Word::WdColor)FontColor());<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutSize(FontSize);<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;font</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutName(FontType().c_str());<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
【7】设置文本框的属性<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutAutoSize(Office::msoAutoShape);<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutMarginBottom(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutMarginTop(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutMarginLeft(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTextFrame()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutMarginRight(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetLine()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutVisible(Office::msoFalse);<br></span><span style="COLOR: #008080">7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">textbox</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetFill()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutTransparency(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span></div>
【8】插入图片，这里需要注意，必须得先用InlineShape,这样可以把图片插入到指定的页中，不然，所有的图片只在第一页。<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">ShapesPtr&nbsp;shapes&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;m_WordDoc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetShapes();<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">InlineShapesPtr&nbsp;inline_shapes&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;selection_doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetRange()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetInlineShapes();<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">InlineShapePtr&nbsp;inline_shape&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;inline_shapes</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">AddPicture(&#8220;picture_path&#8221;,&nbsp;COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">),&nbsp;COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">ShapePtr&nbsp;shape&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;inline_shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">ConvertToShape();<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutWidth(width);<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutHeight(hehight());<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutTop(Y);<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutLeft(X);<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetType()&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;Office::msoPicture)<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_420_518_Open_Image onclick="this.style.display='none'; Codehighlighter1_420_518_Open_Text.style.display='none'; Codehighlighter1_420_518_Closed_Image.style.display='inline'; Codehighlighter1_420_518_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_420_518_Closed_Image onclick="this.style.display='none'; Codehighlighter1_420_518_Closed_Text.style.display='none'; Codehighlighter1_420_518_Open_Image.style.display='inline'; Codehighlighter1_420_518_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_420_518_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_420_518_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;Word::WrapFormatPtr&nbsp;wrapp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;shape</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetWrapFormat();<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;wrapp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutType(Word::wdWrapBehind);<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
【9】插入直线<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">ShapesPtr&nbsp;shapes&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetShapes();<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">Word::ShapePtr&nbsp;line&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;shapes</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">AddLine(x1,y1,&nbsp;x2,y2);<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(line</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetType()&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;Office::msoLine)<br></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img id=Codehighlighter1_130_220_Open_Image onclick="this.style.display='none'; Codehighlighter1_130_220_Open_Text.style.display='none'; Codehighlighter1_130_220_Closed_Image.style.display='inline'; Codehighlighter1_130_220_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_130_220_Closed_Image onclick="this.style.display='none'; Codehighlighter1_130_220_Closed_Text.style.display='none'; Codehighlighter1_130_220_Open_Image.style.display='inline'; Codehighlighter1_130_220_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_130_220_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_130_220_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;Word::LineFormatPtr&nbsp;LineFmt&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;line</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetLine();<br></span><span style="COLOR: #008080">6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;LineFmt</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutWeight(lr</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">weight_);<br></span><span style="COLOR: #008080">7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
【10】插入分隔符<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">selection</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">InsertBreak(COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)wdColumnBreak));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">selection</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">InsertBreak(COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)wdSectionBreakContinuous));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">selection</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">InsertBreak(COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)wdPageBreak));</span></div>
<br>【11】设置栏目个数和栏目的宽度<br>这里一定要注意add函数的逻辑<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">SectionsPtr&nbsp;word_sections&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetSections();<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;num&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_sections</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetCount();<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">SectionPtr&nbsp;word_section&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_sections</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Item(num</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">PageSetupPtr&nbsp;page_setup&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_section</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetPageSetup();<br></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">TextColumnsPtr&nbsp;text_cols&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;page_setup</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">GetTextColumns();<br></span><span style="COLOR: #008080">6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">text_cols</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutEvenlySpaced(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">text_cols</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Add(COleVariant(col_width),&nbsp;COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">),&nbsp;COleVariant((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">));</span></div>
【12】插入表格<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">TablesPtr&nbsp;tables&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetTables();&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">TablePtr&nbsp;table&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;tables</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Add(oSel</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetRange(),&nbsp;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BordersPtr&nbsp;bords&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;table</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetBorders();<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">bords</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutOutsideLineStyle(wdLineStyleSingle);<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">bords</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutInsideLineStyle(wdLineStyleSingle);<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_255_338_Open_Image onclick="this.style.display='none'; Codehighlighter1_255_338_Open_Text.style.display='none'; Codehighlighter1_255_338_Closed_Image.style.display='inline'; Codehighlighter1_255_338_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_255_338_Closed_Image onclick="this.style.display='none'; Codehighlighter1_255_338_Closed_Text.style.display='none'; Codehighlighter1_255_338_Open_Image.style.display='inline'; Codehighlighter1_255_338_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_255_338_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_255_338_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_286_336_Open_Image onclick="this.style.display='none'; Codehighlighter1_286_336_Open_Text.style.display='none'; Codehighlighter1_286_336_Closed_Image.style.display='inline'; Codehighlighter1_286_336_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_286_336_Closed_Image onclick="this.style.display='none'; Codehighlighter1_286_336_Closed_Text.style.display='none'; Codehighlighter1_286_336_Open_Image.style.display='inline'; Codehighlighter1_286_336_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_286_336_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_286_336_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Cell(i,j)</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetRange()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">PutText(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">CellPtr&nbsp;cell&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;table</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Cell(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">cell</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Merge(table</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Cell(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">));</span></div>
【13】保存文档并退出<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">COleVariant&nbsp;vTrue((</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)TRUE),vFalse((</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)FALSE),vOpt((</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)DISP_E_PARAMNOTFOUND,&nbsp;VT_ERROR);<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">_DocumentPtr&nbsp;active_doc;&nbsp;<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">active_doc&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;word_app</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetActiveDocument();<br></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">active_doc</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">SaveAs(COleVariant(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">D:\\doc1.doc</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),&nbsp;<br></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COleVariant((</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">),<br></span><span style="COLOR: #008080">6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vFalse,&nbsp;COleVariant(</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">),&nbsp;vTrue,&nbsp;COleVariant(</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">),<br></span><span style="COLOR: #008080">7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vFalse,&nbsp;vFalse,&nbsp;vFalse,&nbsp;vFalse,&nbsp;vFalse);<br></span><span style="COLOR: #008080">8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">word_app</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Quit(vOpt,&nbsp;vOpt,&nbsp;vOpt);</span></div>
在word优秀的构架中还有许许多多的接口，上面只是举例实现一个普通的文档，希望对大家有用。 
<img src ="http://www.cppblog.com/codeart/aggbug/125430.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codeart/" target="_blank">codeArt</a> 2010-08-31 19:35 <a href="http://www.cppblog.com/codeart/archive/2010/08/31/125430.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BEGIN_COM_MAP和END_COM_MAP</title><link>http://www.cppblog.com/codeart/archive/2010/07/05/119353.html</link><dc:creator>codeArt</dc:creator><author>codeArt</author><pubDate>Mon, 05 Jul 2010 07:45:00 GMT</pubDate><guid>http://www.cppblog.com/codeart/archive/2010/07/05/119353.html</guid><wfw:comment>http://www.cppblog.com/codeart/comments/119353.html</wfw:comment><comments>http://www.cppblog.com/codeart/archive/2010/07/05/119353.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codeart/comments/commentRss/119353.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codeart/services/trackbacks/119353.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;&nbsp;1</span>&nbsp;<span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;BEGIN_COM_MAP(x)&nbsp;public:&nbsp;\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;2</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;x&nbsp;_ComMapClass;&nbsp;\<br></span><span style="color: #008080;">&nbsp;&nbsp;3</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;HRESULT&nbsp;WINAPI&nbsp;_Cache(</span><span style="color: #0000ff;">void</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;pv,&nbsp;REFIID&nbsp;iid,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">&nbsp;ppvObject,&nbsp;DWORD_PTR&nbsp;dw)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()\<br></span><span style="color: #008080;">&nbsp;&nbsp;4</span>&nbsp;<span style="color: #000000;">{\<br></span><span style="color: #008080;">&nbsp;&nbsp;5</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_ComMapClass</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;p&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;(_ComMapClass</span><span style="color: #000000;">*</span><span style="color: #000000;">)pv;\<br></span><span style="color: #008080;">&nbsp;&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Lock();\<br></span><span style="color: #008080;">&nbsp;&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;HRESULT&nbsp;hRes&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;E_FAIL;&nbsp;\<br></span><span style="color: #008080;">&nbsp;&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;__try&nbsp;\<br></span><span style="color: #008080;">&nbsp;&nbsp;9</span>&nbsp;<span style="color: #000000;">{&nbsp;\<br></span><span style="color: #008080;">&nbsp;10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;hRes&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;ATL::CComObjectRootBase::_Cache(pv,&nbsp;iid,&nbsp;ppvObject,&nbsp;dw);\<br></span><span style="color: #008080;">&nbsp;11</span>&nbsp;<span style="color: #000000;">}&nbsp;\<br></span><span style="color: #008080;">&nbsp;12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;__finally&nbsp;\<br></span><span style="color: #008080;">&nbsp;13</span>&nbsp;<span style="color: #000000;">{&nbsp;\<br></span><span style="color: #008080;">&nbsp;14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Unlock();\<br></span><span style="color: #008080;">&nbsp;15</span>&nbsp;<span style="color: #000000;">}&nbsp;\<br></span><span style="color: #008080;">&nbsp;16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;hRes;\<br></span><span style="color: #008080;">&nbsp;17</span>&nbsp;<span style="color: #000000;">}\<br></span><span style="color: #008080;">&nbsp;18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;IUnknown</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;_GetRawUnknown()&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;\<br></span><span style="color: #008080;">&nbsp;19</span>&nbsp;<span style="color: #000000;">{&nbsp;ATLASSERT(_GetEntries()[</span><span style="color: #000000;">0</span><span style="color: #000000;">].pFunc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;_ATL_SIMPLEMAPENTRY);&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;(IUnknown</span><span style="color: #000000;">*</span><span style="color: #000000;">)((INT_PTR)</span><span style="color: #0000ff;">this</span><span style="color: #000000;">+</span><span style="color: #000000;">_GetEntries()</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">dw);&nbsp;}&nbsp;\<br></span><span style="color: #008080;">&nbsp;20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_ATL_DECLARE_GET_UNKNOWN(x)\<br></span><span style="color: #008080;">&nbsp;21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;HRESULT&nbsp;_InternalQueryInterface(REFIID&nbsp;iid,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">&nbsp;ppvObject)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;\<br></span><span style="color: #008080;">&nbsp;22</span>&nbsp;<span style="color: #000000;">{&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;InternalQueryInterface(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">,&nbsp;_GetEntries(),&nbsp;iid,&nbsp;ppvObject);&nbsp;}&nbsp;\<br></span><span style="color: #008080;">&nbsp;23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;ATL::_ATL_INTMAP_ENTRY</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;WINAPI&nbsp;_GetEntries()&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;{&nbsp;\<br></span><span style="color: #008080;">&nbsp;24</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;ATL::_ATL_INTMAP_ENTRY&nbsp;_entries[]&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;{&nbsp;DEBUG_QI_ENTRY(x)<br></span><span style="color: #008080;">&nbsp;25</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;26</span>&nbsp;<span style="color: #000000;">#ifdef&nbsp;_ATL_DEBUG<br></span><span style="color: #008080;">&nbsp;27</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;DEBUG_QI_ENTRY(x)&nbsp;\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;28</span>&nbsp;<span style="color: #000000;">{NULL,&nbsp;\<br></span><span style="color: #008080;">&nbsp;29</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;(DWORD_PTR)_T(#x),&nbsp;\<br></span><span style="color: #008080;">&nbsp;30</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;(ATL::_ATL_CREATORARGFUNC</span><span style="color: #000000;">*</span><span style="color: #000000;">)</span><span style="color: #000000;">0</span><span style="color: #000000;">},<br></span><span style="color: #008080;">&nbsp;31</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;32</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;DEBUG_QI_ENTRY(x)</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;33</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#endif</span><span style="color: #000000;">&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">_ATL_DEBUG</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;34</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;35</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;COM_INTERFACE_ENTRY_IMPL(x)\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;36</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;COM_INTERFACE_ENTRY_IID(_ATL_IIDOF(x),&nbsp;x##Impl</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">_ComMapClass</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;37</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;38</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;_ATL_IIDOF(x)&nbsp;__uuidof(x)</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;39</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;40</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;COM_INTERFACE_ENTRY_IID(iid,&nbsp;x)\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;41</span>&nbsp;<span style="color: #000000;">{</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">iid,\<br></span><span style="color: #008080;">&nbsp;42</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;offsetofclass(x,&nbsp;_ComMapClass),\<br></span><span style="color: #008080;">&nbsp;43</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_ATL_SIMPLEMAPENTRY},<br></span><span style="color: #008080;">&nbsp;44</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;45</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;offsetofclass(base,&nbsp;derived)&nbsp;((DWORD_PTR)(static_cast&lt;base*&gt;((derived*)_ATL_PACKING))-_ATL_PACKING)</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;46</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;47</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;_ATL_SIMPLEMAPENTRY&nbsp;((ATL::_ATL_CREATORARGFUNC*)1)</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;48</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;49</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;COM_INTERFACE_ENTRY(x)\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;50</span>&nbsp;<span style="color: #000000;">{</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">_ATL_IIDOF(x),&nbsp;\<br></span><span style="color: #008080;">&nbsp;51</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;offsetofclass(x,&nbsp;_ComMapClass),&nbsp;\<br></span><span style="color: #008080;">&nbsp;52</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_ATL_SIMPLEMAPENTRY},<br></span><span style="color: #008080;">&nbsp;53</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;54</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;END_COM_MAP()&nbsp;\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;55</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;__if_exists(_GetAttrEntries)&nbsp;{{NULL,&nbsp;(DWORD_PTR)_GetAttrEntries,&nbsp;_ChainAttr&nbsp;},&nbsp;}\<br></span><span style="color: #008080;">&nbsp;56</span>&nbsp;<span style="color: #000000;">{NULL,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">}};&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">_entries[</span><span style="color: #000000;">1</span><span style="color: #000000;">];}&nbsp;\<br></span><span style="color: #008080;">&nbsp;57</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;AddRef(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;\<br></span><span style="color: #008080;">&nbsp;58</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;Release(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;\<br></span><span style="color: #008080;">&nbsp;59</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;STDMETHOD(QueryInterface)(REFIID,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;60</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;61</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;END_COM_MAP()&nbsp;\</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;62</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;__if_exists(_GetAttrEntries)&nbsp;{{NULL,&nbsp;(DWORD_PTR)_GetAttrEntries,&nbsp;_ChainAttr&nbsp;},&nbsp;}\<br></span><span style="color: #008080;">&nbsp;63</span>&nbsp;<span style="color: #000000;">{NULL,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">}};&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;_entries;}&nbsp;\<br></span><span style="color: #008080;">&nbsp;64</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;AddRef(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;\<br></span><span style="color: #008080;">&nbsp;65</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;Release(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;\<br></span><span style="color: #008080;">&nbsp;66</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;STDMETHOD(QueryInterface)(REFIID,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;67</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#endif</span><span style="color: #000000;">&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;_ATL_DEBUG</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;68</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;69</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;70</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;71</span>&nbsp;<span style="color: #008000;"></span><span style="color: #0000ff;">class</span><span style="color: #000000;">&nbsp;d<br></span><span style="color: #008080;">&nbsp;72</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;73</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">public</span><span style="color: #000000;">:<br></span><span style="color: #008080;">&nbsp;74</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;d(){}<br></span><span style="color: #008080;">&nbsp;75</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;x&nbsp;_ComMapClass;<br></span><span style="color: #008080;">&nbsp;76</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;HRESULT&nbsp;WINAPI&nbsp;_Cache(</span><span style="color: #0000ff;">void</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;pv,&nbsp;REFIID&nbsp;iid,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">&nbsp;ppvObject,&nbsp;DWORD_PTR&nbsp;dw)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()\<br></span><span style="color: #008080;">&nbsp;77</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;78</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ComMapClass</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;p&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;(_ComMapClass</span><span style="color: #000000;">*</span><span style="color: #000000;">)pv;<br></span><span style="color: #008080;">&nbsp;79</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Lock();<br></span><span style="color: #008080;">&nbsp;80</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HRESULT&nbsp;hRes&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;E_FAIL;<br></span><span style="color: #008080;">&nbsp;81</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__try<br></span><span style="color: #008080;">&nbsp;82</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;83</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hRes&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;ATL::CComObjectRootBase::_Cache(pv,&nbsp;iid,&nbsp;ppvObject,&nbsp;dw);<br></span><span style="color: #008080;">&nbsp;84</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;85</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__finally<br></span><span style="color: #008080;">&nbsp;86</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;87</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Unlock();<br></span><span style="color: #008080;">&nbsp;88</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;89</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;hRes;<br></span><span style="color: #008080;">&nbsp;90</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;91</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;IUnknown</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;_GetRawUnknown()&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()<br></span><span style="color: #008080;">&nbsp;92</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;ATLASSERT(_GetEntries()[</span><span style="color: #000000;">0</span><span style="color: #000000;">].pFunc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;_ATL_SIMPLEMAPENTRY);&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;(IUnknown</span><span style="color: #000000;">*</span><span style="color: #000000;">)((INT_PTR)</span><span style="color: #0000ff;">this</span><span style="color: #000000;">+</span><span style="color: #000000;">_GetEntries()</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">dw);&nbsp;}<br></span><span style="color: #008080;">&nbsp;93</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_ATL_DECLARE_GET_UNKNOWN(x)<br></span><span style="color: #008080;">&nbsp;94</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HRESULT&nbsp;_InternalQueryInterface(REFIID&nbsp;iid,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">&nbsp;ppvObject)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()<br></span><span style="color: #008080;">&nbsp;95</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;InternalQueryInterface(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">,&nbsp;_GetEntries(),&nbsp;iid,&nbsp;ppvObject);&nbsp;}<br></span><span style="color: #008080;">&nbsp;96</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;ATL::_ATL_INTMAP_ENTRY</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;WINAPI&nbsp;_GetEntries()&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()<br></span><span style="color: #008080;">&nbsp;97</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;98</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;ATL::_ATL_INTMAP_ENTRY&nbsp;_entries[]&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;99</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">100</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{NULL,&nbsp;(DWORD_PTR)_T(#x),&nbsp;(ATL::_ATL_CREATORARGFUNC</span><span style="color: #000000;">*</span><span style="color: #000000;">)</span><span style="color: #000000;">0</span><span style="color: #000000;">},<br></span><span style="color: #008080;">101</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">iid,&nbsp;((DWORD_PTR)(static_cast</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">base</span><span style="color: #000000;">*&gt;</span><span style="color: #000000;">((derived</span><span style="color: #000000;">*</span><span style="color: #000000;">)_ATL_PACKING))</span><span style="color: #000000;">-</span><span style="color: #000000;">_ATL_PACKING),&nbsp;((ATL::_ATL_CREATORARGFUNC</span><span style="color: #000000;">*</span><span style="color: #000000;">)</span><span style="color: #000000;">1</span><span style="color: #000000;">)},<br></span><span style="color: #008080;">102</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">__uuidof(x),&nbsp;((DWORD_PTR)(static_cast</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">base</span><span style="color: #000000;">*&gt;</span><span style="color: #000000;">((derived</span><span style="color: #000000;">*</span><span style="color: #000000;">)_ATL_PACKING))</span><span style="color: #000000;">-</span><span style="color: #000000;">_ATL_PACKING),&nbsp;((ATL::_ATL_CREATORARGFUNC</span><span style="color: #000000;">*</span><span style="color: #000000;">)</span><span style="color: #000000;">1</span><span style="color: #000000;">)},<br></span><span style="color: #008080;">103</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__if_exists(_GetAttrEntries)&nbsp;{{NULL,&nbsp;(DWORD_PTR)_GetAttrEntries,&nbsp;_ChainAttr&nbsp;},&nbsp;}<br></span><span style="color: #008080;">104</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{NULL,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">}<br></span><span style="color: #008080;">105</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br></span><span style="color: #008080;">106</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">_entries[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br></span><span style="color: #008080;">107</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">108</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;AddRef(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">109</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">virtual</span><span style="color: #000000;">&nbsp;ULONG&nbsp;STDMETHODCALLTYPE&nbsp;Release(&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">110</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;STDMETHOD(QueryInterface)(REFIID,&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">**</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">throw</span><span style="color: #000000;">()&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">111</span>&nbsp;<span style="color: #000000;">}</span></div>
<br> <img src ="http://www.cppblog.com/codeart/aggbug/119353.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codeart/" target="_blank">codeArt</a> 2010-07-05 15:45 <a href="http://www.cppblog.com/codeart/archive/2010/07/05/119353.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>