﻿<?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++博客-Muponder-文章分类-visual stdio </title><link>http://www.cppblog.com/deajosha/category/20565.html</link><description>为者常成，行者常至。</description><language>zh-cn</language><lastBuildDate>Mon, 05 May 2014 13:41:38 GMT</lastBuildDate><pubDate>Mon, 05 May 2014 13:41:38 GMT</pubDate><ttl>60</ttl><item><title>vc2005 显示utf-8编码格式文件</title><link>http://www.cppblog.com/deajosha/articles/UTF-8Encode.html</link><dc:creator>盛源博</dc:creator><author>盛源博</author><pubDate>Tue, 29 Apr 2014 08:16:00 GMT</pubDate><guid>http://www.cppblog.com/deajosha/articles/UTF-8Encode.html</guid><wfw:comment>http://www.cppblog.com/deajosha/comments/206760.html</wfw:comment><comments>http://www.cppblog.com/deajosha/articles/UTF-8Encode.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deajosha/comments/commentRss/206760.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deajosha/services/trackbacks/206760.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 12px; padding: 0px; color: #333333; font-family: 微软雅黑, Helvetica, Times, Arial, serif; font-size: 12px; line-height: 18px; background-color: #ffffff;">使用Coder::Blocks开发时，设置了字符集编码为UTF-8,生成文件移植到Visual Studio 2005时，发现所有的中文字符都乱码了。<br /><br />选择Visual Studio 2005 -&gt; Tool -&gt; Option-&gt; Text Editor-&gt;Auto-detect UTF-8 encoding without signature.</p><p style="margin: 0px 0px 12px; padding: 0px; color: #333333; font-family: 微软雅黑, Helvetica, Times, Arial, serif; font-size: 12px; line-height: 18px; background-color: #ffffff;">重新打开一下工程，乱码就没有了。</p><img src ="http://www.cppblog.com/deajosha/aggbug/206760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deajosha/" target="_blank">盛源博</a> 2014-04-29 16:16 <a href="http://www.cppblog.com/deajosha/articles/UTF-8Encode.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++ 2008 调试技巧之使用 CRT 库查找内存泄漏</title><link>http://www.cppblog.com/deajosha/articles/VS2008_debug_1.html</link><dc:creator>盛源博</dc:creator><author>盛源博</author><pubDate>Sun, 24 Nov 2013 08:30:00 GMT</pubDate><guid>http://www.cppblog.com/deajosha/articles/VS2008_debug_1.html</guid><wfw:comment>http://www.cppblog.com/deajosha/comments/204421.html</wfw:comment><comments>http://www.cppblog.com/deajosha/articles/VS2008_debug_1.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deajosha/comments/commentRss/204421.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deajosha/services/trackbacks/204421.html</trackback:ping><description><![CDATA[<p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px;">&nbsp; &nbsp; 检测内存泄漏的主要工具是调试器和C运行库(CRT)调试堆函数，如果启动调试堆函数，请在程序中包括以下语句：</span></p>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size: 13px; color: #008080;">1</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;</span><span style="font-size: 13px; color: #0000ff;">#define</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;_CRTDBG_MAP_ALLOC<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="font-size: 14px;">&nbsp; &nbsp;</span><span style="font-size: 14px;">&nbsp; &nbsp;</span><span style="color: #008080;">2</span>&nbsp;#include&nbsp;&lt;stdlib.h&gt;</div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="font-size: 14px;">&nbsp; &nbsp;</span><span style="font-size: 14px;">&nbsp; &nbsp;</span><span style="color: #008080;">3</span>&nbsp;#include&nbsp;&lt;crtdbg.h&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: red;">注意：</span><span style="color: red;">为了使CRT函数能够正常工作，#include语句必须遵循上面语句声明的次序。<br /></span>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size: 10pt;">使用这些语句启用调试堆函数之后</span><span style="font-size: 10pt;">，可</span><span style="font-family: Arial; font-size: 10pt; line-height: 18px;">以在某个应用程序退出点之前设置一个对&nbsp;</span><strong xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial; font-size: 10pt; line-height: 18px;">_CrtDumpMemoryLeaks</strong><span style="font-family: Arial; font-size: 10pt; line-height: 18px;">()的调用，以便在应用程序退出时显示内存泄漏报告：<br /></span><span style="font-family: Arial; font-size: 10pt; line-height: 18px;"></span><span style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span id="mt15" class="sentence" data-guid="519ec924645684b804077181e6c3ab4f" data-source="If your application has multiple exits, you do not need to manually place a call to &lt;span class=&quot;mtpsTagOuterHtml&quot; &gt;&lt;span&gt;_CrtDumpMemoryLeaks&lt;/span&gt;&lt;/span&gt; at every exit point." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; font-size: 13px; line-height: 18px;">如果应用程序有多个退出点，并不需要在每个退出点都手动设置一个对&nbsp;<a href="http://msdn.microsoft.com/zh-cn/Library/d41t22sb" style="text-decoration: none; color: #03697a;">_CrtDumpMemoryLeaks</a>()&nbsp;的调用。</span><span style="color: #2a2a2a; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">&nbsp;</span><span id="mt16" class="sentence" data-guid="63d37cf20f5f0ee876d11b541baa79fc" data-source="A call to &lt;strong&gt;_CrtSetDbgFlag&lt;/strong&gt; at the beginning of your application will cause an automatic call to &lt;strong&gt;_CrtDumpMemoryLeaks&lt;/strong&gt; at each exit point." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; font-size: 13px; line-height: 18px;">应用程序开头部分对&nbsp;<strong xmlns="http://www.w3.org/1999/xhtml">_CrtSetDbgFlag</strong>&nbsp;的调用会导致在每个退出点自动调用&nbsp;<strong xmlns="http://www.w3.org/1999/xhtml">_CrtDumpMemoryLeaks</strong>。</span><span style="color: #2a2a2a; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">&nbsp;</span><span id="mt17" class="sentence" data-guid="ddec6e301f7a009e30259e205d8efdb0" data-source="You must set the two bit fields shown here:" xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; font-size: 13px; line-height: 18px;">您必须设置两个位域，如下所示：</span><br /><span style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 13px; color: #008080;">1</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;</span><span style="background-color: #eeeeee; font-size: 13px;">_CrtSetDbgFlag&nbsp;(&nbsp;_CRTDBG_ALLOC_MEM_DF&nbsp;</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;_CRTDBG_LEAK_CHECK_DF&nbsp;);<br /></span><span id="mt18" class="sentence" data-guid="2975bbdd6351eee4e04086994c0cc14d" data-source="By default, &lt;strong&gt;_CrtDumpMemoryLeaks&lt;/strong&gt; outputs the memory-leak report to the &lt;span class=&quot;label&quot;&gt;Debug&lt;/span&gt; pane of the &lt;span class=&quot;label&quot;&gt;Output&lt;/span&gt; window." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; font-size: 13px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;默认情况下，<strong xmlns="http://www.w3.org/1999/xhtml">_CrtDumpMemoryLeaks</strong>&nbsp;将内存泄漏报告输出到<span class="label" xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;输出&#8221;</span>窗口的<span class="label" xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;调试&#8221;</span>窗格中。</span><span style="color: #2a2a2a; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">&nbsp;</span><span id="mt19" class="sentence" data-guid="953d9ce4a6c5550477b8bf6adc1110b7" data-source="You can use &lt;strong&gt;_CrtSetReportMode&lt;/strong&gt; to redirect the report to another location." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; font-size: 13px; line-height: 18px;">您可以使用<strong xmlns="http://www.w3.org/1999/xhtml">_CrtSetReportMode</strong>&nbsp;将该报告重定向到其他位置。<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span id="mt20" data-guid="b622e257f6f2dfbee21d021006075273" data-source="If you use a library, the library might reset the output to another location." xml:space="preserve">如果使用库，该库可能会将输出重置到另一位置。</span>&nbsp;<span id="mt21" class="sentence" data-guid="6ba4b47a635daa9b85981e0bd1a3306f" data-source="In that case, you can set the output location back to the &lt;span window, as shown here:" xml:space="preserve">在此情况下，可以将输出位置设置回<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;输出&#8221;</span>窗口，如下所示：<br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size: 13px; color: #008080;">1</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;</span><span style="background-color: #eeeeee; font-size: 13px;">&nbsp;_CrtSetReportMode(&nbsp;_CRT_ERROR,&nbsp;_CRTDBG_MODE_DEBUG&nbsp;);<br />&nbsp; &nbsp; &nbsp; &nbsp;</span><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt22" class="sentence" data-guid="51662ec722107fefbed63b9104dd46fe" data-source="If your application does not define &lt;span class=&quot;code&quot;&gt;_CRTDBG_MAP_ALLOC&lt;/span&gt;, &lt;span class=&quot;mtpsTagOuterHtml&quot; &gt;&lt;span&gt;_CrtDumpMemoryLeaks&lt;/span&gt;&lt;/span&gt; displays a memory-leak report that looks like this:" xml:space="preserve">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果应用程序未定义&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">_CRTDBG_MAP_ALLOC</span>，则&nbsp;<a href="http://msdn.microsoft.com/zh-cn/Library/d41t22sb" style="text-decoration: none; color: #03697a;">_CrtDumpMemoryLeaks</a>&nbsp;显示的内存泄漏报告如下所示：</span></p><div id="code-snippet-5" class="codeSnippetContainer" xmlns="" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; min-width: 260px; clear: both; font-size: 13px; line-height: 17px;"><div class="codeSnippetContainerTabs" style="vertical-align: middle; height: 23px; position: relative; z-index: 1;"></div><div class="codeSnippetContainerCodeContainer" style="clear: both; margin-bottom: 12px; position: relative; top: -1px;"><div class="codeSnippetToolBar" style="width: auto; height: auto;"><div class="codeSnippetToolBarText" style="float: right; top: -8px; position: relative; background-color: #ffffff; width: auto; height: 0px; vertical-align: top;"></div></div><div id="CodeSnippetContainerCode_86ec5f9e-f4fe-4fca-82ce-051552bfb53e" class="codeSnippetContainerCode" dir="ltr" style="width: auto; margin: 0px; padding: 10px 21px;"><div style="margin: 0px;"><pre style="padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;">Detected memory leaks!
Dumping objects -&gt;
{18} normal block at 0x00780E80, 64 bytes long.
 Data: &lt;                &gt; CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
</pre></div></div></div></div><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt23" class="sentence" data-guid="c4d6f99bb574f6c024c25877c33114cf" data-source="If your application defines &lt;span class=&quot;code&quot;&gt;_CRTDBG_MAP_ALLOC&lt;/span&gt;, the memory-leak report looks like this:" xml:space="preserve">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果应用程序定义了&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">_CRTDBG_MAP_ALLOC</span>，则显示的内存泄漏报告如下所示：</span></p><div id="code-snippet-6" class="codeSnippetContainer" xmlns="" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; min-width: 260px; clear: both; font-size: 13px; line-height: 17px;"><div class="codeSnippetContainerTabs" style="vertical-align: middle; height: 23px; position: relative; z-index: 1;"></div><div class="codeSnippetContainerCodeContainer" style="clear: both; margin-bottom: 12px; position: relative; top: -1px;"><div class="codeSnippetToolBar" style="width: auto; height: auto;"><div class="codeSnippetToolBarText" style="float: right; top: -8px; position: relative; background-color: #ffffff; width: auto; height: 0px; vertical-align: top;"></div></div><div id="CodeSnippetContainerCode_d8f163de-49af-4ba2-96b9-8b03be211378" class="codeSnippetContainerCode" dir="ltr" style="width: auto; margin: 0px; padding: 10px 21px;"><div style="margin: 0px;"><pre style="padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;">Detected memory leaks!
Dumping objects -&gt;
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18} 
normal block at 0x00780E80, 64 bytes long.
 Data: &lt;                &gt; CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
</pre></div></div></div></div><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt24" class="sentence" data-guid="1ca76db57854de9e95dd9b9584248d68" data-source="The difference is that the second report shows name of the file and the line number where the leaked memory is first allocated. " xml:space="preserve">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;区别在于，第二份报告显示文件名，以及泄漏的内存初次分配所在位置的行号。</span></p><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt25" class="sentence" data-guid="998cb259fa75f19bfc134463024e3b13" data-source="Whether you define &lt;span class=&quot;code&quot;&gt;_CRTDBG_MAP_ALLOC&lt;/span&gt; or not, the memory-leak report will display the following information:" xml:space="preserve">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;不论是否定义&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">_CRTDBG_MAP_ALLOC</span>，内存泄漏报告都显示以下信息：</span></p><ul style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 17px;"><li style="list-style-image: none;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt26" class="sentence" data-guid="b465a0bd7b2eb5a4ca26da133d2c084a" data-source="The memory allocation number, which is &lt;span class=&quot;code&quot;&gt;18&lt;/span&gt; in this example" xml:space="preserve">内存分配编号，在本例中为&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">18</span>。</span></p></li><li style="list-style-image: none;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt27" class="sentence" data-guid="aa042e3361584e1758718f1bc6d6de9c" data-source="The &lt;span class=&quot;mtpsTagOuterHtml&quot; &gt;&lt;span&gt;block type&lt;/span&gt;&lt;/span&gt;, which is &lt;span class=&quot;code&quot;&gt;normal&lt;/span&gt; in this example. " xml:space="preserve"><a href="http://msdn.microsoft.com/zh-cn/Library/htdyz80k" style="text-decoration: none; color: #03697a;">块类型</a>，在本例中为&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">normal</span>。</span></p></li><li style="list-style-image: none;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt28" class="sentence" data-guid="57cb93e543bf2ffa4ed553cc65d093df" data-source="The hexadecimal memory location, which is &lt;span class=&quot;code&quot;&gt;0x00780E80&lt;/span&gt; in this example." xml:space="preserve">十六进制内存位置，在本例中为&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">0x00780E80</span>。</span></p></li><li style="list-style-image: none;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt29" class="sentence" data-guid="4e322d15fea1f9cbd5f4c2467564e79f" data-source="The size of the block, &lt;span class=&quot;code&quot;&gt;64 bytes&lt;/span&gt; in this example." xml:space="preserve">块的大小，在本例中为&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">64 bytes</span>。</span></p></li><li style="list-style-image: none;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt30" class="sentence" data-guid="9944768770d9cfd40894e90966e130bc" data-source="The first 16 bytes of data in the block, in hexadecimal form." xml:space="preserve">块中前 16 个字节的数据（十六进制形式）。</span></p></li></ul><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt31" class="sentence" data-guid="7355d64b27a2c3822148815e2551c9bc" data-source="The memory-leak report identifies a block of memory as normal, client, or CRT." xml:space="preserve">内存泄漏报告将内存块标识为普通、客户端或 CRT。</span>&nbsp;<span id="mt32" class="sentence" data-guid="f6fae82cb04ceb7082e73251445ea5bc" data-source="A &lt;span class=&quot;parameter&quot;&gt;normal block&lt;/span&gt; is ordinary memory allocated by your program." xml:space="preserve">&#8220;普通块&#8221;是由程序分配的普通内存。</span>&nbsp;<span id="mt33" class="sentence" data-guid="b542d901bcef093fa8ef83c55e8ecccf" data-source="A &lt;span class=&quot;parameter&quot;&gt;client block&lt;/span&gt; is a special type of memory block used by MFC programs for objects that require a destructor." xml:space="preserve">&#8220;客户端块&#8221;是由 MFC 程序用于需要析构函数的对象的特殊类型内存块。</span>&nbsp;<span id="mt34" class="sentence" data-guid="68dd48cc671a9ac490bf5e9519a95d45" data-source="The MFC &lt;span class=&quot;code&quot;&gt;new&lt;/span&gt; operator creates either a normal block or a client block, as appropriate for the object being created." xml:space="preserve">MFC&nbsp;<span class="code" xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">new</span>&nbsp;运算符根据正在创建的对象的需要创建普通块或客户端块。</span>&nbsp;<span id="mt35" class="sentence" data-guid="6095b9a7e1f55e9d28ee113ee5a15708" data-source="A &lt;span class=&quot;parameter&quot;&gt;CRT block&lt;/span&gt; is allocated by the CRT library for its own use." xml:space="preserve">&#8220;CRT 块&#8221;是由 CRT 库为自己使用而分配的内存块。</span>&nbsp;<span id="mt36" class="sentence" data-guid="351c81dc7fa9a2c5ce085c56cd8c991b" data-source="The CRT library handles the deallocation for these blocks." xml:space="preserve">CRT 库可处理这些块的释放。</span>&nbsp;<span id="mt37" class="sentence" data-guid="a2bf03f59ab97673b366ecc40a29d549" data-source="Therefore, it is unlikely you will see these in the memory leak report unless something is significantly wrong, for example, the CRT library is corrupted." xml:space="preserve">因此，您不大可能在内存泄漏报告中看到这些块，除非出现严重错误（例如 CRT 库损坏）。</span></p><p style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-size: 13px;"><span id="mt38" class="sentence" data-guid="51df2e106f30a0ecc4b4b5cabd8ea76c" data-source="There are two other types of memory blocks that never appear in memory-leak reports." xml:space="preserve">内存泄漏报告中绝对不会出现另外两个内存块类型。</span>&nbsp;<span id="mt39" class="sentence" data-guid="355585cd18d46e4b569437502b43326a" data-source="A &lt;span class=&quot;parameter&quot;&gt;free block&lt;/span&gt; is memory that has been released." xml:space="preserve">&#8220;可用块&#8221;是已释放的内存。</span>&nbsp;<span id="mt40" class="sentence" data-guid="a88c370db1ff57ae762d2b6640c12332" data-source="That means it is not leaked, by definition." xml:space="preserve">也就是说，根据定义，这种块不会泄漏。</span>&nbsp;<span id="mt41" class="sentence" data-guid="73519991ff900cc9b19a0ae326a43cf5" data-source="An &lt;span class=&quot;parameter&quot;&gt;ignore block&lt;/span&gt; is memory that you have explicitly marked to exclude it from the memory-leak report." xml:space="preserve">&#8220;忽略块&#8221;是已明确标记、不出现在内存泄漏报告中的块。<br /></span></p><div class="LW_CollapsibleArea_TitleDiv" style="font-family: 'Segoe UI Semibold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; margin-top: 9px; margin-bottom: 19px; line-height: 17px;"><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><a class="LW_CollapsibleArea_TitleAhref" title="单击以折叠。双击以全部折叠。" style="outline: none;"><span class="LW_CollapsibleArea_Title" style="font-family: 'Segoe UI Semibold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; padding-left: 10px; font-size: 1.769em; display: block; overflow: hidden;"></span></a><a title="单击以折叠。双击以全部折叠。" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; outline: none;"><span style="font-family: 'Segoe UI Semibold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; padding-left: 10px; font-size: 10pt; display: block; overflow: hidden;"><strong>在内存分配编号上设置断点</strong></span></a><div class="LW_CollapsibleArea_HrDiv"></div></div></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; padding-left: 15px; padding-bottom: 20px; font-size: 13px; line-height: 17px;"><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt45" data-guid="c8c9e43505c411ff67c254c4c60e88de" data-source="The memory allocation number tells you when a leaked memory block was allocated." xml:space="preserve"><sentencetext xmlns="http://www.w3.org/1999/xhtml">如果分配了泄漏内存块，内存分配编号会通知您。</sentencetext>&nbsp;</span><span id="mt46" data-guid="f930c34f5161b2b6165628bb350066b4" data-source="A block with a memory allocation number of 18, for example, is the 18th block of memory allocated during the run of the application." xml:space="preserve">例如，内存分配编号为 18 的块就是在应用程序运行过程中所分配的第 18 个内存块。</span>&nbsp;<span id="mt47" data-guid="0ba35daf6a12c643179437d2484bdace" data-source="The CRT report counts all memory-block allocations during the run." xml:space="preserve">CRT 报告包含运行过程中的所有内存块分配情况。</span>&nbsp;<span id="mt48" data-guid="bcf79ea0f1264ba54e3b47e5a8b6dc97" data-source="This includes allocations by the CRT library and other libraries such as MFC." xml:space="preserve">其中包括 CRT 库和其他库（如 MFC）的分配情况。</span>&nbsp;<span id="mt49" data-guid="d6641a4d58334a5f83a548fe85e6bb1c" data-source="Therefore, a block with a memory allocation number of 18 may not be the 18th memory block allocated by your code." xml:space="preserve">因此，内存分配编号为 18 的块可能不是您的代码所分配的第 18 个内存块。</span>&nbsp;<span id="mt50" data-guid="086305df32e13518d883f6a4f700ce38" data-source="Typically, it will not be." xml:space="preserve">通常，二者并不一致。</span></p><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt51" data-guid="78561ac8d17a18edda3bdb8e3fe9615b" data-source="You can use the allocation number to set a breakpoint on the memory allocation." xml:space="preserve">可以使用分配编号在内存分配位置设置断点。</span></p><h3>使用&#8220;监视&#8221;窗口设置内存分配断点</h3><div><ol><li><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt52" data-guid="30751cb7d54919688e6d2f120c10c8ef" data-source="Set a breakpoint near the start of your application, and then start your application." xml:space="preserve">在应用程序的起点附近设置断点，然后启动应用程序。</span></p></li><li><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt53" class="sentence" data-guid="cdaa6acc586183d0fd40853fe4075354" data-source="When the application breaks at the breakpoint, the &lt;span window." xml:space="preserve">当应用程序在断点处中断时，会出现<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;监视&#8221;</span>窗口。</span></p></li><li><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt54" class="sentence" data-guid="58a8efde2fe73132b2fae6ec4ef85c54" data-source="In the &lt;span class=&quot;label&quot;&gt;Watch&lt;/span&gt; window, type &lt;span class=&quot;code&quot;&gt;_crtBreakAlloc&lt;/span&gt; in in the &lt;span column." xml:space="preserve">在<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;监视&#8221;</span>窗口中，在<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;名称&#8221;</span>列中键入&nbsp;<span xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">_crtBreakAlloc</span>。</span></p><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt55" class="sentence" data-guid="865d7972d163da31879a8987ff38e759" data-source="If you are using the multithreaded DLL version of the CRT library (the /MD option), include the context operator: &lt;span xml:space="  preserve"=""><sentencetext xmlns="http://www.w3.org/1999/xhtml">如果要使用 CRT 库的多线程 DLL 版本（/MD 选项），请加入上下文运算符：<span xmlns="http://www.w3.org/1999/xhtml" style="font-family: Consolas, Courier, monospace; color: #006400;">{,,msvcr100d.dll}_crtBreakAlloc</span></sentencetext></span></p></li><li><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt56" class="sentence" data-guid="7ae6945e1968d55508ce78b9b840a12a" data-source="Press &lt;span xml:space="  preserve"="">按<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;Return&#8221;</span>。</span></p><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt57" class="sentence" data-guid="2470f6d9b49cca1c2c87893b7e4ca702" data-source="The debugger evaluates the call and places the result in the &lt;span column." xml:space="preserve"><sentencetext xmlns="http://www.w3.org/1999/xhtml">调试器将计算调用，并将结果放入<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;值&#8221;</span>列。</sentencetext>&nbsp;</span><span id="mt58" data-guid="c3defe40316047a933078d4ff84707b3" data-source="This value will be &#8211;1 if you have not set any breakpoints on memory allocations." xml:space="preserve">如果没有在内存分配上设置任何断点，该值将为 &#8211;1。</span></p></li><li><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt59" class="sentence" data-guid="caed5266283c76384df0987c80385ce3" data-source="In the &lt;span column, replace the value shown with the allocation number of the memory allocation where you want to break." xml:space="preserve">在<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;值&#8221;</span>列中，将显示的值替换为要在其位置中断的内存分配的分配编号。</span></p></li></ol></div><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt60" data-guid="50c65354a12cca24cfb21cb92271331d" data-source="After you set a breakpoint on a memory-allocation number, you can continue to debug." xml:space="preserve"><sentencetext xmlns="http://www.w3.org/1999/xhtml">在某个内存分配编号设置断点之后，您可以继续调试。</sentencetext>&nbsp;</span><span id="mt61" data-guid="0709c7eee640514d70da3c1dbf67d94b" data-source="Be careful to run the program under the same conditions as the previous run so that the memory-allocation order does not change." xml:space="preserve">请注意在与以前运行相同的条件下运行程序，以便内存分配顺序不会更改。</span>&nbsp;<span id="mt62" class="sentence" data-guid="855b0eb715da28d527329839c992a34a" data-source="When your program breaks at the specified memory allocation, you can use the &lt;span Stack&lt;/span&gt; window and other debugger windows to determine the conditions under which the memory was allocated." xml:space="preserve">当程序在指定的内存分配处中断时，可以使用<span xmlns="http://www.w3.org/1999/xhtml" style="font-weight: 700;">&#8220;调用堆栈&#8221;</span>窗口和其他调试器窗口来确定分配内存时的情况。</span>&nbsp;<span id="mt63" data-guid="e1333ca20f6f3ecfb88463c21cdfb946" data-source="Then, you can continue execution to observe what happens to the object and determine why it is not correctly deallocated." xml:space="preserve">然后，可以继续执行程序以观察对象发生什么情况，并确定未正确释放对象的原因。</span></p><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt66" data-guid="a9be5b0ea513b34d017d6aa7ae512178" data-source="You can also set memory-allocation breakpoints in code." xml:space="preserve"><sentencetext xmlns="http://www.w3.org/1999/xhtml">也可以在代码中设置内存分配断点。</sentencetext>&nbsp;</span><span id="mt67" data-guid="49f79e4b847a6ce8d3f44c38d136200b" data-source="There are two ways to do this:" xml:space="preserve">有两种方法可以实现此目的：</span></p><div id="code-snippet-8" xmlns="" style="min-width: 260px; clear: both;"><div style="vertical-align: middle; height: 23px; position: relative; z-index: 1;"></div><div style="clear: both; margin-bottom: 12px; position: relative; top: -1px;"><div style="width: auto; height: auto;"><div style="float: right; top: -8px; position: relative; background-color: #ffffff; width: auto; height: 0px; vertical-align: top;"></div></div><div id="CodeSnippetContainerCode_6a990612-92ce-494c-ae14-bf93077632c6" dir="ltr" style="width: auto; margin: 0px; padding: 10px 21px;"><div style="margin: 0px;"><pre style="padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;">_crtBreakAlloc = 18; </pre></div></div></div></div><p style="color: #2a2a2a; margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><span id="mt68" data-guid="e8c7746c798038181311eeb1ac3fda10" data-source="or:" xml:space="preserve">或：</span></p><div id="code-snippet-9" xmlns="" style="min-width: 260px; clear: both;"><div style="vertical-align: middle; height: 23px; position: relative; z-index: 1;"></div><div style="clear: both; margin-bottom: 12px; position: relative; top: -1px;"><div style="width: auto; height: auto;"><div style="float: right; top: -8px; position: relative; background-color: #ffffff; width: auto; height: 0px; vertical-align: top;"></div></div><div id="CodeSnippetContainerCode_4d7a7fc6-0e41-4f24-a9ea-2f66ebaf2aa6" dir="ltr" style="width: auto; margin: 0px; padding: 10px 21px;"><div style="margin: 0px;"><pre style="padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important;">_CrtSetBreakAlloc(18);</pre></div></div></div></div></div></div><img src ="http://www.cppblog.com/deajosha/aggbug/204421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deajosha/" target="_blank">盛源博</a> 2013-11-24 16:30 <a href="http://www.cppblog.com/deajosha/articles/VS2008_debug_1.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【总结】VC++ 2008 常用快捷键使用技巧</title><link>http://www.cppblog.com/deajosha/articles/ToolSkills.html</link><dc:creator>盛源博</dc:creator><author>盛源博</author><pubDate>Thu, 29 Aug 2013 15:20:00 GMT</pubDate><guid>http://www.cppblog.com/deajosha/articles/ToolSkills.html</guid><wfw:comment>http://www.cppblog.com/deajosha/comments/202860.html</wfw:comment><comments>http://www.cppblog.com/deajosha/articles/ToolSkills.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deajosha/comments/commentRss/202860.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deajosha/services/trackbacks/202860.html</trackback:ping><description><![CDATA[1. 快捷键在当前行上面或者下面插入新行<br />&nbsp; &nbsp;&nbsp;<span style="background-color: #ffffff; color: #2a2a2a; font-family: 宋体, 微软雅黑, Verdana; line-height: 23px;">　 按下Ctrl+Enter会在上面插入一个空行，Ctrl+Shift+Enter则会在下面插入一个空行。光标会移至新行的开始处。<br />2. 快捷键函数调用与函数定义之间切换<br />&nbsp; &nbsp; &nbsp;F12定位到函数的定义，Ctrl+ -(减号)快速回到函数调用处，Ctrl+F12快速定位到函数声明处。<br />3. 比Ctrl + F 更方便的查询方式<br />&nbsp; &nbsp; 按下Ctrl + I,输入要查询的文字，重复按下Ctrl + I 跳到下一个匹配位置处，按下Ctrl+Shift + I 向后搜索，按下ESC退出查询。<br />4. 使用Ctrl + Tab打开IDE的导航，获得鸟瞰视图<br />5. Ctrl+K,F格式化程序代码<br />6. Ctrl+M,M 隐藏当前代码段<br />7. Ctrl + K,C 注释选中的代码段 Ctrl +K,U取消选中的代码段<br />8. Ctrl + K,K 添加代码标签/或取消代码标签， Ctrl + K,P，查看上一个代码标签 Ctrl + K,N查看下一代码标签 Ctrl + B,C 清空全部标签<br />9. Ctrl + U 把选中的所有字母全部变成小写 Ctrl + Shift + U 把选中的所有字母变成大写<br />10. Ctrl + H 打开替换窗口 &nbsp;Ctrl + F 打开查询窗口<br />11. Ctrl + K,I 显示程序中的快捷信息<br />12. F9 新增/去除快捷键 Ctrl + F9 启用断点 &nbsp;Ctrl + Shift + F9 去除当前项目中的所有断点<br />13. F10 单步调试 &nbsp; F11 单行调试 &nbsp;F5 &nbsp;程序启动调试 &nbsp;Ctrl + F5 程序执行无调试模式 &nbsp;Shift + F5 退出程序调试 Ctrl + Shift + F5 重启调试<br />14. F7 &nbsp;生成解决方案 &nbsp; Ctrl + Alt + F7 重新生成解决方案&nbsp;<br />15. Alt + F7 打开项目属性对话要框<br />16. Ctrl + N 新建文件 &nbsp; &nbsp;Ctrl + O 打开文件 &nbsp; &nbsp; Ctrl + Shift + N 新建项目 &nbsp; &nbsp; Ctrl + Shift + O 打开项目&nbsp;<br />17. Shift + Alt + Enter 全屏显示IDE界面 &nbsp;Ctrl + Shift + C 打开类图视图窗口 &nbsp; Ctrl + Shift + E 打开资源视图窗口 Ctrl + Alt + L 打开解决方案资源器</span><img src ="http://www.cppblog.com/deajosha/aggbug/202860.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deajosha/" target="_blank">盛源博</a> 2013-08-29 23:20 <a href="http://www.cppblog.com/deajosha/articles/ToolSkills.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】Visual Studio Macro to switch between CPP and H files</title><link>http://www.cppblog.com/deajosha/articles/switch_CPP_and_H_files.html</link><dc:creator>盛源博</dc:creator><author>盛源博</author><pubDate>Tue, 18 Jun 2013 14:17:00 GMT</pubDate><guid>http://www.cppblog.com/deajosha/articles/switch_CPP_and_H_files.html</guid><wfw:comment>http://www.cppblog.com/deajosha/comments/201135.html</wfw:comment><comments>http://www.cppblog.com/deajosha/articles/switch_CPP_and_H_files.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deajosha/comments/commentRss/201135.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deajosha/services/trackbacks/201135.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->I&#8217;ve&nbsp;been&nbsp;doing&nbsp;a&nbsp;lot&nbsp;of&nbsp;managed&nbsp;C++&nbsp;programming&nbsp;lately&nbsp;and&nbsp;I&nbsp;had&nbsp;forgotten&nbsp;what&nbsp;a&nbsp;pain&nbsp;it&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;switching&nbsp;back&nbsp;and&nbsp;forth&nbsp;between&nbsp;the&nbsp;header&nbsp;file&nbsp;and&nbsp;source&nbsp;file.&nbsp;&nbsp;Back&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;the&nbsp;days&nbsp;of&nbsp;Visual&nbsp;Studio&nbsp;6&nbsp;I&nbsp;had&nbsp;a&nbsp;macro&nbsp;that&nbsp;switched&nbsp;between&nbsp;the&nbsp;CPP&nbsp;and&nbsp;H&nbsp;file,&nbsp;so&nbsp;I&nbsp;went&nbsp;googling,&nbsp;but&nbsp;the&nbsp;macro&nbsp;I&nbsp;found&nbsp;didn&#8217;t&nbsp;work&nbsp;very&nbsp;well&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;VS2008.&nbsp;&nbsp;Like&nbsp;any&nbsp;good&nbsp;coder,&nbsp;I&nbsp;decided&nbsp;to&nbsp;write&nbsp;it&nbsp;myself&nbsp;instead.<br /><br />If&nbsp;you&nbsp;haven&#8217;t&nbsp;written&nbsp;a&nbsp;macro&nbsp;before,&nbsp;here&nbsp;are&nbsp;the&nbsp;steps.<br /><br />In&nbsp;Visual&nbsp;Studio,&nbsp;go&nbsp;to&nbsp;Tools&nbsp;|&nbsp;Macros&nbsp;|&nbsp;Macros&nbsp;IDE.&nbsp;A&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;window&nbsp;should&nbsp;open&nbsp;and&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;the&nbsp;Project&nbsp;Explorer,&nbsp;the&nbsp;MyMacros&nbsp;project&nbsp;should&nbsp;be&nbsp;open.<br />Right&nbsp;click&nbsp;on&nbsp;the&nbsp;MyMacros&nbsp;project&nbsp;and&nbsp;select&nbsp;Add&nbsp;|&nbsp;Add&nbsp;Module.&nbsp;Name&nbsp;it&nbsp;CppUtilities.&nbsp;&nbsp;The&nbsp;CppUtilities&nbsp;should&nbsp;open&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;the&nbsp;editor&nbsp;window.<br />Add&nbsp;the&nbsp;code&nbsp;from&nbsp;below&nbsp;into&nbsp;the&nbsp;module&nbsp;and&nbsp;save&nbsp;the&nbsp;project.<br />view&nbsp;plaincopy&nbsp;to&nbsp;clipboardprint?<br />&#8216;=====================================================================&nbsp;&nbsp;<br />&#8216;&nbsp;If&nbsp;the&nbsp;currently&nbsp;open&nbsp;document&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;a&nbsp;CPP&nbsp;or&nbsp;an&nbsp;H&nbsp;file,&nbsp;attempts&nbsp;to&nbsp;&nbsp;<br />&#8216;&nbsp;<span style="color: #0000FF; ">switch</span>&nbsp;between&nbsp;the&nbsp;CPP&nbsp;and&nbsp;the&nbsp;H&nbsp;file.&nbsp;&nbsp;<br />&#8216;=====================================================================&nbsp;&nbsp;<br />Public&nbsp;Sub&nbsp;SwitchBetweenSourceAndHeader()&nbsp;&nbsp;<br />&nbsp;&nbsp;Dim&nbsp;currentDocument&nbsp;As&nbsp;String&nbsp;&nbsp;<br />&nbsp;&nbsp;Dim&nbsp;targetDocument&nbsp;As&nbsp;String&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;currentDocument&nbsp;=&nbsp;ActiveDocument.FullName&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;If&nbsp;currentDocument.EndsWith(&#8220;.cpp&#8221;,&nbsp;StringComparison.InvariantCultureIgnoreCase)&nbsp;Then&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;targetDocument&nbsp;=&nbsp;Left(currentDocument,&nbsp;Len(currentDocument)&nbsp;-&nbsp;3)&nbsp;+&nbsp;&#8220;h&#8221;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;OpenDocument(targetDocument)&nbsp;&nbsp;<br />&nbsp;&nbsp;ElseIf&nbsp;currentDocument.EndsWith(&#8220;.h&#8221;,&nbsp;StringComparison.InvariantCultureIgnoreCase)&nbsp;Then&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;targetDocument&nbsp;=&nbsp;Left(currentDocument,&nbsp;Len(currentDocument)&nbsp;-&nbsp;1)&nbsp;+&nbsp;&#8220;cpp&#8221;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;OpenDocument(targetDocument)&nbsp;&nbsp;<br />&nbsp;&nbsp;End&nbsp;If&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />End&nbsp;Sub&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&#8216;=====================================================================&nbsp;&nbsp;<br />&#8216;&nbsp;Given&nbsp;a&nbsp;document&nbsp;name,&nbsp;attempts&nbsp;to&nbsp;activate&nbsp;it&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;it&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;already&nbsp;open,&nbsp;&nbsp;<br />&#8216;&nbsp;otherwise&nbsp;attempts&nbsp;to&nbsp;open&nbsp;it.&nbsp;&nbsp;<br />&#8216;=====================================================================&nbsp;&nbsp;<br />Private&nbsp;Sub&nbsp;OpenDocument(ByRef&nbsp;documentName&nbsp;As&nbsp;String)&nbsp;&nbsp;<br />&nbsp;&nbsp;Dim&nbsp;document&nbsp;As&nbsp;EnvDTE.Document&nbsp;&nbsp;<br />&nbsp;&nbsp;Dim&nbsp;activatedTarget&nbsp;As&nbsp;Boolean&nbsp;&nbsp;<br />&nbsp;&nbsp;activatedTarget&nbsp;=&nbsp;False&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;For&nbsp;Each&nbsp;document&nbsp;In&nbsp;Application.Documents&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;document.FullName&nbsp;=&nbsp;documentName&nbsp;And&nbsp;document.Windows.Count&nbsp;&gt;&nbsp;0&nbsp;Then&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.Activate()&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;activatedTarget&nbsp;=&nbsp;True&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit&nbsp;For&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;If&nbsp;&nbsp;<br />&nbsp;&nbsp;Next&nbsp;&nbsp;<br />&nbsp;&nbsp;If&nbsp;Not&nbsp;activatedTarget&nbsp;Then&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;Application.Documents.Open(documentName,&nbsp;&#8220;Text&#8221;)&nbsp;&nbsp;<br />&nbsp;&nbsp;End&nbsp;If&nbsp;&nbsp;<br />End&nbsp;Sub&nbsp;&nbsp;<br />If&nbsp;you&nbsp;<span style="color: #0000FF; ">switch</span>&nbsp;back&nbsp;to&nbsp;Visual&nbsp;Studio&nbsp;and&nbsp;open&nbsp;the&nbsp;Macro&nbsp;Explorer,&nbsp;you&nbsp;should&nbsp;see&nbsp;the&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;module&nbsp;CppUtilities&nbsp;and&nbsp;the&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;macro&nbsp;SwitchBetweenSourceAndHeader&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;the&nbsp;tree.&nbsp;&nbsp;You&nbsp;could&nbsp;run&nbsp;the&nbsp;macro&nbsp;from&nbsp;here,&nbsp;but&nbsp;it&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;much&nbsp;easier&nbsp;to&nbsp;bind&nbsp;it&nbsp;to&nbsp;a&nbsp;keystroke.<br /><br />Click&nbsp;on&nbsp;Tools&nbsp;|&nbsp;Options&nbsp;then&nbsp;go&nbsp;to&nbsp;the&nbsp;Environment&nbsp;|&nbsp;Keyboard&nbsp;tab.<br />In&nbsp;the&nbsp;Show&nbsp;commands&nbsp;containing:&nbsp;box,&nbsp;type&nbsp;CppUtilities.&nbsp;This&nbsp;should&nbsp;filter&nbsp;the&nbsp;list&nbsp;down&nbsp;to&nbsp;one&nbsp;entry,Macros.MyMacros.CppUtilitities.SwitchBetweenSourceAndHeader.<br />Click&nbsp;on&nbsp;the&nbsp;Press&nbsp;shortcut&nbsp;keys:&nbsp;text&nbsp;box&nbsp;and&nbsp;then&nbsp;press&nbsp;the&nbsp;keystroke&nbsp;you&nbsp;would&nbsp;like&nbsp;to&nbsp;use&nbsp;to&nbsp;run&nbsp;the&nbsp;macro.&nbsp;If&nbsp;the&nbsp;keystroke&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;already&nbsp;used,&nbsp;it&nbsp;will&nbsp;show&nbsp;you&nbsp;below&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;the&nbsp;Shortcut&nbsp;currently&nbsp;used&nbsp;by:&nbsp;dropdown.&nbsp;&nbsp;When&nbsp;you&nbsp;find&nbsp;one&nbsp;that&nbsp;<span style="color: #0000FF; ">is</span>&nbsp;unused,&nbsp;click&nbsp;the&nbsp;Assign&nbsp;button&nbsp;to&nbsp;use&nbsp;it.&nbsp;&nbsp;I&nbsp;use&nbsp;Ctrl+Shift+Alt+Bkspce.<br />Click&nbsp;OK&nbsp;then&nbsp;open&nbsp;a&nbsp;CPP&nbsp;or&nbsp;H&nbsp;file&nbsp;and&nbsp;give&nbsp;it&nbsp;a&nbsp;<span style="color: #0000FF; ">try</span>.<br />If&nbsp;you&nbsp;found&nbsp;<span style="color: #0000FF; ">this</span>&nbsp;post&nbsp;helpful,&nbsp;please&nbsp;"Kick"&nbsp;it&nbsp;so&nbsp;others&nbsp;can&nbsp;find&nbsp;it&nbsp;too:</div><img src ="http://www.cppblog.com/deajosha/aggbug/201135.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deajosha/" target="_blank">盛源博</a> 2013-06-18 22:17 <a href="http://www.cppblog.com/deajosha/articles/switch_CPP_and_H_files.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>