﻿<?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++博客-微笑黑可可-文章分类-C/C++温习</title><link>http://www.cppblog.com/moqiancong/category/1179.html</link><description>无论经历什么，请保持微笑!</description><language>zh-cn</language><lastBuildDate>Wed, 13 Apr 2011 14:40:46 GMT</lastBuildDate><pubDate>Wed, 13 Apr 2011 14:40:46 GMT</pubDate><ttl>60</ttl><item><title>WPF的性能问题</title><link>http://www.cppblog.com/moqiancong/articles/74645.html</link><dc:creator>莫千聪</dc:creator><author>莫千聪</author><pubDate>Sun, 22 Feb 2009 18:27:00 GMT</pubDate><guid>http://www.cppblog.com/moqiancong/articles/74645.html</guid><wfw:comment>http://www.cppblog.com/moqiancong/comments/74645.html</wfw:comment><comments>http://www.cppblog.com/moqiancong/articles/74645.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/moqiancong/comments/commentRss/74645.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/moqiancong/services/trackbacks/74645.html</trackback:ping><description><![CDATA[     最近因为工作的原因，修改了一些同事写的Silverlight程序。知道Silverlight是WPF的一个子集，倒是很想看看WPF能有怎样一个效率表现。想起以前做过的一个“质点链”的Demo.于是就抄起VS2008将例子改写成WPF。<br />:<a href="http://moqiancong.blogbus.com/files/12353248560.rar"><font color="#000000">（完整项目文件)</font></a><br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">   </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> partial </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Window1 : Window<br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img id="Codehighlighter1_45_2068_Open_Image" onclick="this.style.display='none'; Codehighlighter1_45_2068_Open_Text.style.display='none'; Codehighlighter1_45_2068_Closed_Image.style.display='inline'; Codehighlighter1_45_2068_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_45_2068_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_45_2068_Closed_Text.style.display='none'; Codehighlighter1_45_2068_Open_Image.style.display='inline'; Codehighlighter1_45_2068_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span><span id="Codehighlighter1_45_2068_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_45_2068_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> Ellipse[] circles;<br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Window1()<br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img id="Codehighlighter1_115_190_Open_Image" onclick="this.style.display='none'; Codehighlighter1_115_190_Open_Text.style.display='none'; Codehighlighter1_115_190_Closed_Image.style.display='inline'; Codehighlighter1_115_190_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_115_190_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_115_190_Closed_Text.style.display='none'; Codehighlighter1_115_190_Open_Image.style.display='inline'; Codehighlighter1_115_190_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_115_190_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_115_190_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            InitializeComponent();<br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            InitCirlces(</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> InitCirlces(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nCircle)<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img id="Codehighlighter1_247_803_Open_Image" onclick="this.style.display='none'; Codehighlighter1_247_803_Open_Text.style.display='none'; Codehighlighter1_247_803_Closed_Image.style.display='inline'; Codehighlighter1_247_803_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_247_803_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_247_803_Closed_Text.style.display='none'; Codehighlighter1_247_803_Open_Image.style.display='inline'; Codehighlighter1_247_803_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_247_803_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_247_803_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            circles </span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Ellipse[nCircle];<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">nCircle; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img id="Codehighlighter1_345_779_Open_Image" onclick="this.style.display='none'; Codehighlighter1_345_779_Open_Text.style.display='none'; Codehighlighter1_345_779_Closed_Image.style.display='inline'; Codehighlighter1_345_779_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_345_779_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_345_779_Closed_Text.style.display='none'; Codehighlighter1_345_779_Open_Image.style.display='inline'; Codehighlighter1_345_779_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_345_779_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_345_779_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Ellipse c </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Ellipse();<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c.Height </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c.Width </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c.Stroke </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SolidColorBrush(Colors.Black);<br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c.Visibility</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Visibility.Visible;<br /></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c.RenderTransform </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> TranslateTransform();<br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Canvas.SetTop(c, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Canvas.SetLeft(c, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                board.Children.Add(c);<br /></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                circles[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c;<br /></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Window_MouseMove(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, MouseEventArgs e)<br /></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img id="Codehighlighter1_884_1531_Open_Image" onclick="this.style.display='none'; Codehighlighter1_884_1531_Open_Text.style.display='none'; Codehighlighter1_884_1531_Closed_Image.style.display='inline'; Codehighlighter1_884_1531_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_884_1531_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_884_1531_Closed_Text.style.display='none'; Codehighlighter1_884_1531_Open_Image.style.display='inline'; Codehighlighter1_884_1531_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_884_1531_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_884_1531_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            Point p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">e.GetPosition(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            var firstC </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> circles[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            SetPos(firstC, p);<br /></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> circles.Length; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i )<br /></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img id="Codehighlighter1_1061_1508_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1061_1508_Open_Text.style.display='none'; Codehighlighter1_1061_1508_Closed_Image.style.display='inline'; Codehighlighter1_1061_1508_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1061_1508_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1061_1508_Closed_Text.style.display='none'; Codehighlighter1_1061_1508_Open_Image.style.display='inline'; Codehighlighter1_1061_1508_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_1061_1508_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1061_1508_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Ellipse c </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> circles[i];<br /></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Point curP </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> GetPos(c);<br /></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Vector v </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> p </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> curP;<br /></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000"> len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v.Length;<br /></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (len </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img id="Codehighlighter1_1264_1424_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1264_1424_Open_Text.style.display='none'; Codehighlighter1_1264_1424_Closed_Image.style.display='inline'; Codehighlighter1_1264_1424_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1264_1424_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1264_1424_Closed_Text.style.display='none'; Codehighlighter1_1264_1424_Open_Image.style.display='inline'; Codehighlighter1_1264_1424_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span><span id="Codehighlighter1_1264_1424_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1264_1424_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    v.Normalize();<br /></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    v </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (len </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> curP </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> v;<br /></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    SetPos(c, p);<br /></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img id="Codehighlighter1_1446_1494_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1446_1494_Open_Text.style.display='none'; Codehighlighter1_1446_1494_Closed_Image.style.display='inline'; Codehighlighter1_1446_1494_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1446_1494_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1446_1494_Closed_Text.style.display='none'; Codehighlighter1_1446_1494_Open_Image.style.display='inline'; Codehighlighter1_1446_1494_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span><span id="Codehighlighter1_1446_1494_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1446_1494_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> curP;<br /></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> SetPos(UIElement ue, Point p)<br /></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img id="Codehighlighter1_1593_1806_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1593_1806_Open_Text.style.display='none'; Codehighlighter1_1593_1806_Closed_Image.style.display='inline'; Codehighlighter1_1593_1806_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1593_1806_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1593_1806_Closed_Text.style.display='none'; Codehighlighter1_1593_1806_Open_Image.style.display='inline'; Codehighlighter1_1593_1806_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1593_1806_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1593_1806_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            TranslateTransform tr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ue.RenderTransform </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> TranslateTransform;<br /></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            tr.X </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> p.X;<br /></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            tr.Y </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> p.Y;<br /></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Canvas.SetTop(ue, p.Y);<br /></span><span style="COLOR: #008080">60</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Canvas.SetLeft(ue, p.X);</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">61</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> Point GetPos(UIElement ue)<br /></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img id="Codehighlighter1_1860_2061_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1860_2061_Open_Text.style.display='none'; Codehighlighter1_1860_2061_Closed_Image.style.display='inline'; Codehighlighter1_1860_2061_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1860_2061_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1860_2061_Closed_Text.style.display='none'; Codehighlighter1_1860_2061_Open_Image.style.display='inline'; Codehighlighter1_1860_2061_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1860_2061_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1860_2061_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            TranslateTransform tr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ue.RenderTransform </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> TranslateTransform;<br /></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Point(tr.X, tr.Y);<br /></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">return new Point(Canvas.GetLeft(ue), Canvas.GetTop(ue));</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">68</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span></div><br /><p>实际运行结果很不理想。cpu占用率很高。通过性能分析工具发现，大多数时间都浪费在了TranslateTransform.Set_X和TranslateTransform.Set_Y上。<br />刚刚翻看WPF不足半天，不敢确认效率低是WPF本身的问题，还是自己选择的实现方式的问题。</p><p>如果有好的建议，请留言。<br />:<a href="http://moqiancong.blogbus.com/files/12353248560.rar"><font color="#000000">（完整项目文件)</font></a></p><img src ="http://www.cppblog.com/moqiancong/aggbug/74645.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/moqiancong/" target="_blank">莫千聪</a> 2009-02-23 02:27 <a href="http://www.cppblog.com/moqiancong/articles/74645.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>strnins</title><link>http://www.cppblog.com/moqiancong/articles/4404.html</link><dc:creator>莫千聪</dc:creator><author>莫千聪</author><pubDate>Tue, 21 Mar 2006 03:09:00 GMT</pubDate><guid>http://www.cppblog.com/moqiancong/articles/4404.html</guid><wfw:comment>http://www.cppblog.com/moqiancong/comments/4404.html</wfw:comment><comments>http://www.cppblog.com/moqiancong/articles/4404.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/moqiancong/comments/commentRss/4404.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/moqiancong/services/trackbacks/4404.html</trackback:ping><description><![CDATA[
		<div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); 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: rgb(0, 0, 255);">bool</span>
				<span style="color: rgb(0, 0, 0);"> strnins(</span>
				<span style="color: rgb(0, 0, 255);">char</span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);"> dst, size_t n, </span>
				<span style="color: rgb(0, 0, 255);">const</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">char</span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);"> src, </span>
				<span style="color: rgb(0, 0, 255);">int</span>
				<span style="color: rgb(0, 0, 0);"> pos);<br /></span>
				<span style="color: rgb(0, 128, 0);">/*</span>
				<span style="color: rgb(0, 128, 0);">***********************************************<br />有以下几种情况要考虑<br />** dst ==NULL<br />** src == NULL<br />** pos超过尾部<br />** 希望对pos为负数时，能按python的方式解释.<br />** 如果dst空间不够时,只插入src的一部分.<br />*************************************************</span>
				<span style="color: rgb(0, 128, 0);">*/</span>
		</div>
		<br />
<img src ="http://www.cppblog.com/moqiancong/aggbug/4404.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/moqiancong/" target="_blank">莫千聪</a> 2006-03-21 11:09 <a href="http://www.cppblog.com/moqiancong/articles/4404.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>toUpper</title><link>http://www.cppblog.com/moqiancong/articles/4396.html</link><dc:creator>莫千聪</dc:creator><author>莫千聪</author><pubDate>Tue, 21 Mar 2006 01:22:00 GMT</pubDate><guid>http://www.cppblog.com/moqiancong/articles/4396.html</guid><wfw:comment>http://www.cppblog.com/moqiancong/comments/4396.html</wfw:comment><comments>http://www.cppblog.com/moqiancong/articles/4396.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/moqiancong/comments/commentRss/4396.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/moqiancong/services/trackbacks/4396.html</trackback:ping><description><![CDATA[
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 0, 255);">void</span>
				<span style="color: rgb(0, 0, 0);"> toUpper(</span>
				<span style="color: rgb(0, 0, 255);">char</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);">s) {<br />    </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(</span>
				<span style="color: rgb(0, 0, 0);">!</span>
				<span style="color: rgb(0, 0, 0);">s) {<br />      </span>
				<span style="color: rgb(0, 0, 255);">return</span>
				<span style="color: rgb(0, 0, 0);">;<br />    }<br />    </span>
				<span style="color: rgb(0, 0, 255);">while</span>
				<span style="color: rgb(0, 0, 0);">(</span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);">s) {<br />       </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);"> ( (</span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);">s</span>
				<span style="color: rgb(0, 0, 0);">&gt;=</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">a</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">) </span>
				<span style="color: rgb(0, 0, 0);">&amp;&amp;</span>
				<span style="color: rgb(0, 0, 0);"> (</span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);">s</span>
				<span style="color: rgb(0, 0, 0);">&lt;=</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">z</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">) ) {<br />        </span>
				<span style="color: rgb(0, 0, 0);">*</span>
				<span style="color: rgb(0, 0, 0);">s</span>
				<span style="color: rgb(0, 0, 0);">+=</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">A</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">-</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">a</span>
				<span style="color: rgb(0, 0, 0);">'</span>
				<span style="color: rgb(0, 0, 0);">;<br />       }<br />       </span>
				<span style="color: rgb(0, 0, 0);">++</span>
				<span style="color: rgb(0, 0, 0);">s;<br />    }<br />}</span>
		</div>
		<br />
<img src ="http://www.cppblog.com/moqiancong/aggbug/4396.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/moqiancong/" target="_blank">莫千聪</a> 2006-03-21 09:22 <a href="http://www.cppblog.com/moqiancong/articles/4396.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>