﻿<?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++</title><link>http://www.cppblog.com/gohan/category/935.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 07 Aug 2008 09:25:50 GMT</lastBuildDate><pubDate>Thu, 07 Aug 2008 09:25:50 GMT</pubDate><ttl>60</ttl><item><title>山伏札记[1]</title><link>http://www.cppblog.com/gohan/archive/2008/08/07/58197.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Wed, 06 Aug 2008 18:30:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/08/07/58197.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/58197.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/08/07/58197.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/58197.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/58197.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp; 这段日子一直没来，blog长了不少草，没办法，填几块山石吧。 &nbsp;&nbsp; 山伏就是修行者，不少都是在野的浪人之辈，我目前就仍然是这个状态。假期里放松不少，技术上面，csdn上赚分捡漏折腾了1周就没能继续，经验不足知识不够，于是SDL学了一点入门基础，看书学了学lua的用法跟一些trick，数据结构方面再看了点基础的，被推荐了解了一下TinyXml这个轻巧...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2008/08/07/58197.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/58197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-08-07 02:30 <a href="http://www.cppblog.com/gohan/archive/2008/08/07/58197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>for循环在条件语句中遍历字符串常量</title><link>http://www.cppblog.com/gohan/archive/2008/06/30/54941.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Mon, 30 Jun 2008 02:40:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/06/30/54941.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/54941.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/06/30/54941.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/54941.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/54941.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp; 这样利用字符串常量的方法我还是第一次见到，有点意思吧。最初的程序源自<a href="http://discuss.joelonsoftware.com/default.asp?interview.11.648182" target="_blank">这里</a>，那个程序中不同的字符表示putchar循环执行的次数不同，下标奇偶决定了打印!还是空格。可以根据这样的方法构造一个打印几种字符组成的像素图形。</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">#include &lt;cstdio&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">int</span> main()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">int</span> a,b,c;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">for</span> (c=b=10;a=<span style="color: #006080;">"VAMSI PERI,TFy!QJu ROo TNn(ROo)SLq SLq ULo+ UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^ NBELPeHBFHT}TnALVlBLOFAkHFOuFETp HCStHAUFAgcEAelclcn^r^r\\tZvYxXy T|S~Pn SPm SOn TNn ULo0ULo#ULo-W Hq!WFs XDt!"</span> [b++];)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">for</span>(; a-- &gt; 64 ; )</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            putchar ( ++c==90 ? c=10:33^b&amp;1);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">}</pre>
</div>
</div>
<p>&nbsp;&nbsp; 照着这样的方法写了个打印字符串的东西，可以按照指定长度换行。</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">#include &lt;cstdio&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">int</span> main()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">int</span> a,b,c;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">for</span> (c=b=0;a=<span style="color: #006080;">"www.cppblog.com/gohan        this is a test"</span>[b++];)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">if</span>(a!=<span style="color: #006080;">'\0'</span>)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            putchar ( ++c==30 ? c=0,b--,10:a);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    putchar(10);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">}</pre>
</div>
</div>
<p>&nbsp;&nbsp; 最后这个是打印一个自己构造的ASC字符，这里构造的是我的名字 </p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">#include &lt;cstdio&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">int</span> main()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">int</span> a,b,c;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">for</span> (c=0,b=0;a=<span style="color: #006080;">"@u@GFLB[@DBJDDFEDEFD@CBBDBBDBBBDBBBCBCBDBC@BBDBBBDBBBDBBBCBCBDBD@CFDDDBDBDGABDBE@v"</span>[b++];)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">for</span>(; a-- &gt; 64 ; )</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            putchar ( ++c==54 ? c=0,10:33^b&amp;1);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">}</pre>
</div>
</div>
<p>&nbsp;</p>
<br>
<p>执行效果如图<img style="border: 0px none ;" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/for_8AB1/image_fa684c31-8888-411d-a5f3-8b78be7c54c2.png" align="left" border="0" height="137" width="509"></p>
<br>
<p><br></p>
<br>
<p><br></p>
<br>
<p><br></p>
<p><br></p><img src ="http://www.cppblog.com/gohan/aggbug/54941.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-06-30 10:40 <a href="http://www.cppblog.com/gohan/archive/2008/06/30/54941.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Win32命令行应用，ReadConsoleInput()得到键盘VK_CODE</title><link>http://www.cppblog.com/gohan/archive/2008/05/23/50817.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 22 May 2008 16:08:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/23/50817.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/50817.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/23/50817.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/50817.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/50817.html</trackback:ping><description><![CDATA[<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="212" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/ea02b9b086ac_14D84/image_ac262c63-9d15-4cce-9682-be9aa7bb922f.png" width="269" align="right" border="0"></p> <p>&nbsp;&nbsp;&nbsp; ReadConsoleInput是一个Win32 API，&nbsp; 声明如下：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 54%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; height: 142px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">BOOL ReadConsoleInput(</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">  HANDLE hConsoleInput, <span style="color: #008000">//输入句柄</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">  PINPUT_RECORD lpBuffer, <span style="color: #008000">//指向INPUT_RECORD结构体(数组)的指针</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">  DWORD nLength, <span style="color: #008000">//上面那个结构体的大小</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">  LPDWORD lpNumberOfEventsRead <span style="color: #008000">//实际读入输入内容的个数</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">);</pre></div></div>
<p>&nbsp;&nbsp;&nbsp; 我把读入的功能写在这个助手类中，ReadConsoleInput的得到VK_CODE的方法可以看ReadKeyDown和ReadKeyPush两个函数，它们的效果略有点不同。右图是效果截图，按ESC跳出循环。助手类以后还可以添加颜色控制位置控制等功能，只要你想，目的就是为了简化API调用。</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #cc6633">#pragma</span> once</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">#include &lt;Windows.h&gt;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">class</span> GohanConsoleHelper</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    HANDLE _hIn;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    HANDLE _hOut;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    INPUT_RECORD _InRec;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    DWORD _NumRead;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">public</span>:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    WORD VKey;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    GohanConsoleHelper(<span style="color: #0000ff">void</span>){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        _hIn = GetStdHandle(STD_INPUT_HANDLE);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        _hOut = GetStdHandle(STD_OUTPUT_HANDLE);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        VKey=0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">bool</span> ReadOneInput()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">return</span> 0!=ReadConsoleInput(_hIn,&amp;_InRec,1,&amp;_NumRead);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">bool</span> ReadOneInput(INPUT_RECORD&amp; InRec)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">return</span> 0!=ReadConsoleInput(_hIn,&amp;InRec,1,&amp;_NumRead);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    DWORD ReadKeyDown()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">if</span>(!ReadConsoleInput(_hIn,&amp;_InRec,1,&amp;_NumRead))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">if</span>(_InRec.EventType!=KEY_EVENT)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">if</span>(_InRec.Event.KeyEvent.bKeyDown &gt; 0)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        VKey = _InRec.Event.KeyEvent.wVirtualKeyCode;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">return</span> VKey;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    DWORD ReadKeyPush()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">if</span>(!ReadConsoleInput(_hIn,&amp;_InRec,1,&amp;_NumRead))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">if</span>(_InRec.EventType!=KEY_EVENT)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">if</span>(_InRec.Event.KeyEvent.bKeyDown == 0)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        VKey = _InRec.Event.KeyEvent.wVirtualKeyCode;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">return</span> VKey;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span>:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    ~GohanConsoleHelper(<span style="color: #0000ff">void</span>){}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">};</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre></div></div>
<p>&nbsp;</p>
<p>main所在文件内容</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">#include &lt;windows.h&gt;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">#include &lt;iostream&gt;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">#include <span style="color: #006080">"GohanConsoleHelper.h"</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">int</span> main()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    GohanConsoleHelper gch;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">if</span>(gch.ReadKeyPush()!=0) <span style="color: #008000">//使用ReadKeyDown()捕获按键弹起的VK_CODE</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">if</span>(gch.VKey != VK_ESCAPE)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                cout&lt;&lt;<span style="color: #006080">"VK_CODE == "</span>&lt;&lt;gch.VKey&lt;&lt;endl;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">else</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                cout&lt;&lt;<span style="color: #006080">"Bye~~"</span>&lt;&lt;endl;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; 在命令行得到VK_CODE可以干许多事情了，可以写个在Win32命令行下的小游戏，俄罗斯方块啊什么的，呵呵，不过画面稍微好点的就搞不了了，因为毕竟win32命令行分辨率太低了。</p>
<p>&nbsp;&nbsp; 忘了放出参考的资料：</p>
<p><a title="http://adrianxw.dk/" href="http://adrianxw.dk/">http://adrianxw.dk/</a> 比较全面的Win32命令行教程</p><img src ="http://www.cppblog.com/gohan/aggbug/50817.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-23 00:08 <a href="http://www.cppblog.com/gohan/archive/2008/05/23/50817.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>向Vista学习，实现XP下重命名文件忽略选取扩展名</title><link>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 16 May 2008 18:05:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/50122.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/50122.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/50122.html</trackback:ping><description><![CDATA[<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="129" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VistaXP_105A/image_1bf4b754-9e02-4945-9552-b70650bc5dbe.png" width="124" align="right" border="0">&nbsp;&nbsp; 这两天对于HOOK的技术有了一个入门的学习，用过vista的同学会发现vista重命名一个文件比如vista.exe，他会自动选中vista忽略掉扩展名，带来比较方便的用户体验，学了一些hook我也想试试xp下能不能做这样的事情。于是参考一些文章，勉强实现了，有一点儿缺陷（请看最后）。</p> <p>&nbsp;&nbsp; 经过观察我发现重命名时，资源管理器会向他的子窗口listview发送一个LVM_EDITLABELA的控制消息，所以我使用了WH_CALLWNDPROCRET类型的全局挂钩，这个挂钩可以在sendmessage结束以后处理传送和返回的数据。发送了LVM_EDITLABELA消息后，会在lParam得到一个编辑窗口的句柄，只需之后对这个窗口发送EM_SETSEL控制消息就能够改变重命名时候的高亮区域。hook回调函数如下：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">static</span> LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">if</span>(nCode &lt; 0)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         CallNextHookEx(hook,nCode,wParam,lParam);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     LPCWPRETSTRUCT msg = (LPCWPRETSTRUCT) lParam;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">if</span>(msg-&gt;message == LVM_EDITLABELA || msg-&gt;message == LVM_EDITLABELW)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         GetClassName(msg-&gt;hwnd,className,255);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>         GetWindowText(msg-&gt;hwnd,wndName,255);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>         <span style="color: #0000ff">if</span>(0==_tcscmp(className,_TEXT(<span style="color: #006080">"SysListView32"</span>)))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>             <span style="color: #0000ff">if</span>(0==_tcscmp(wndName,_TEXT(<span style="color: #006080">"FolderView"</span>)))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>             {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>                 hEditWnd = (HWND)msg-&gt;lResult;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>                 GetWindowText(hEditWnd,className,255);<span style="color: #008000">//暂时放入className</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>                 SendMessage(hEditWnd,EM_SETSEL,0,findDot(className));</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>             }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>     <span style="color: #0000ff">return</span> CallNextHookEx(hook,nCode,wParam,lParam);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span> }</pre></div></div>
<p>&nbsp;</p>
<p>className与wndName是两个TCHAR数组，从hwnd获取信息存在那里进行判断是否为Shell中的listview，避免在其它使用listview的应用程序里会进行之后的处理。</p>
<p>&nbsp;&nbsp; 工程文件下载，<a href="http://www.cppblog.com/Files/gohan/HookDemoSrc.rar" target="_blank">点这里</a></p>
<p>&nbsp;&nbsp; 程序下载，<a href="http://www.cppblog.com/Files/gohan/GRenamer.rar" target="_blank">点这里</a></p>
<p>&nbsp;&nbsp; 使用方法，编译以后直接运行GRnamer就可以，如果不想用了，从任务管理器把它关闭，没有做trayicon之类的东西，因为只是个demo。</p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="48" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VistaXP_105A/image_11463743-357a-4d42-ac50-b9eeb0b9fa1d.png" width="165" align="left" border="0">&nbsp;&nbsp; 最后说一下缺陷，缺陷就是这样做没有办法判断文件与文件夹的区别，所以会有如图的效果，我自己没有想到解决的方法，请达人们指点。：） </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; 参考的文章：</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms632589(VS.85).aspx" target="_blank">msdn Hooks</a> hook的全部参考</p>
<p><a href="http://www.codeproject.com/KB/DLL/hooks.aspx" target="_blank">codeproject Hooks and DLLs</a> 我的hook dll都是照着它写的。</p><img src ="http://www.cppblog.com/gohan/aggbug/50122.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-17 02:05 <a href="http://www.cppblog.com/gohan/archive/2008/05/17/50122.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让VS2005中的fstream支持中文路径文件打开</title><link>http://www.cppblog.com/gohan/archive/2008/05/11/49488.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 10 May 2008 17:30:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/11/49488.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/49488.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/11/49488.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/49488.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/49488.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp; 前几天发了这篇《<a href="http://www.cppblog.com/gohan/archive/2008/05/09/49303.html" target="_blank">用fstream对二进制文件的读写</a>》，有朋友指出了VS2005的fstream对于中文路径支持不好的bug。我想大概是因为VS2005更加重视了对字符串的全球化支持，所以鼓励我们使用unicode编码的字符串，对于MBCS之类的支持可能就疏忽了吧。</p>
<p>&nbsp;&nbsp; 我搜索了一下这个问题的解决，参考了如下资料写了演示代码。</p>
<ul>
    <li><a href="http://www.cppblog.com/mythma/archive/2006/06/09/8349.html" target="_blank">fstream 和 中文路径</a>&nbsp; c++博客 </li>
    <li><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=371229&amp;SiteID=1" target="_blank">About unicode settings in visual studio 2005, it really puzzled me a lot</a> ms forum  </li>
    <li><a href="http://msdn.microsoft.com/en-us/library/9dzxxx2c(VS.80).aspx" target="_blank">MSDN</a></li>
</ul>
<p>&nbsp;&nbsp; 我综合了以上的内容，总结了3种方法，能够较好解决大家的困扰，包括可能无法使用cout的问题。</p>
<div>
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   1:</span> <span style="color: #008000;">/********************************************************************</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   2:</span> <span style="color: #008000;">    created:    2008/05/10</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   3:</span> <span style="color: #008000;">    created:    10:5:2008   23:56</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   4:</span> <span style="color: #008000;">    filename:     k:\sj\fstreamTest\fstreamTest\main.cpp</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   5:</span> <span style="color: #008000;">    file path:    k:\sj\fstreamTest\fstreamTest</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   6:</span> <span style="color: #008000;">    file base:    main</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   7:</span> <span style="color: #008000;">    file ext:    cpp</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   8:</span> <span style="color: #008000;">    author:        Gohan</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   9:</span> <span style="color: #008000;">*********************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  10:</span> #include &lt;tchar.h&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  11:</span> #include &lt;fstream&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  12:</span> #include &lt;iostream&gt;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  13:</span> <span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  14:</span> <span style="color: #0000ff;">int</span> main()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  15:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  16:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  17:</span>     <span style="color: #008000;">/* 方法1，使用_TEXT()宏定义将字符串常量指定为TCHAR*类型                 */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  18:</span>     <span style="color: #008000;">/* 如果是我，首选此类型                                                 */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  19:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  20:</span>     fstream file;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  21:</span>     file.open(_TEXT(<span style="color: #006080;">"c:\\测试\\测试文本.txt"</span>));</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  22:</span>     cout&lt;&lt;file.rdbuf();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  23:</span>     file.close();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  24:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  25:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  26:</span>     <span style="color: #008000;">/* 方法2，使用STL中的locale类的静态方法指定全局locale                   */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  27:</span>     <span style="color: #008000;">/* 使用该方法以后,cout可能不能正常输出中文，十分蹊跷                    */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  28:</span>     <span style="color: #008000;">/* 我发现了勉强解决的方法：不要在还原区域设定前用cout或wcout 输出中文   */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  29:</span>     <span style="color: #008000;">/* 否则后果就是还原区域设定后无法使用cout wcout输出中文                 */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  30:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  31:</span>     locale::global(locale(<span style="color: #006080;">""</span>));<span style="color: #008000;">//将全局区域设为操作系统默认区域</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  32:</span>     file.open(<span style="color: #006080;">"c:\\测试\\测试文本2.txt"</span>);<span style="color: #008000;">//可以顺利打开文件了</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  33:</span>     locale::global(locale(<span style="color: #006080;">"C"</span>));<span style="color: #008000;">//还原全局区域设定</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  34:</span>     cout&lt;&lt;file.rdbuf();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  35:</span>     file.close();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  36:</span>&nbsp; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  37:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  38:</span>     <span style="color: #008000;">/* 方法3，使用C函数setlocale，不能用cout输出中文的问题解决方法同上      */</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  39:</span>     <span style="color: #008000;">/************************************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  40:</span>     setlocale(LC_ALL,<span style="color: #006080;">"Chinese-simplified"</span>);<span style="color: #008000;">//设置中文环境</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  41:</span>     file.open(<span style="color: #006080;">"c:\\测试\\测试文本3.txt"</span>);<span style="color: #008000;">//可以顺利打开文件了</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  42:</span>     setlocale(LC_ALL,<span style="color: #006080;">"C"</span>);<span style="color: #008000;">//还原</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  43:</span>     cout&lt;&lt;file.rdbuf();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">  44:</span>     file.close();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">  45:</span> }</pre>
</div>
</div>
<div>&nbsp; 补充一下，第一种方法，如果不是静态字符串当作路径的话，记得传入TCHAR*类型字符串作为路径，应该就没问题了。<a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VS2005fstream_10ED/image_7.png"><img style="border: 0px none ;" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VS2005fstream_10ED/image_thumb_2.png" border="0" height="131" width="429"></a> </div>
<div>&nbsp;</div><img src ="http://www.cppblog.com/gohan/aggbug/49488.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-11 01:30 <a href="http://www.cppblog.com/gohan/archive/2008/05/11/49488.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用fstream对二进制文件的读写</title><link>http://www.cppblog.com/gohan/archive/2008/05/09/49303.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 09 May 2008 06:41:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/09/49303.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/49303.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/09/49303.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/49303.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/49303.html</trackback:ping><description><![CDATA[<p>这里介绍使用fstream这个类完成这个任务，fstream在输入输出方面比较全能。 </p>
<p>操作系统通过二进制文件格式存储大量文件。一般不指定二进制文件操作的I/O操作是面向文本的，用来读写特定编码的文本。本文介绍用C++的fstream类读写二进制文件。 </p>
<p>读写数据以这个WebSite结构体为例  </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Struct for C++ File I/O binary file sample</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">struct</span> WebSites</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   3:</span>      <span style="color: #0000ff;">char</span> SiteName[100];</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   4:</span>      <span style="color: #0000ff;">int</span> Rank;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   5:</span> };</pre>
</div>
</div>
<h4>写操作</h4>
<p>&nbsp;&nbsp;&nbsp; 注意事项
</p>
<ul>
    <li>要写的文件需要用到输出模式标志 ios::out和二进制操作模式标志ios::binary。
    </li>
    <li>write()函数需要两个参数.第一个参数是char*类型用来指定需要写入的数据， 第二个参数是int类型指定写入多少个字节.
    </li>
    <li>最后记得要用close()结束. </li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Sample for C++ File I/O binary file write </p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">void</span> write_to_binary_file(WebSites p_Data)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   3:</span>     fstream binary_file(<span style="color: #006080;">"c:\\test.dat"</span>,ios::<span style="color: #0000ff;">out</span>|ios::binary|ios::app); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   4:</span>     binary_file.write(reinterpret_cast&lt;<span style="color: #0000ff;">char</span> *&gt;(&amp;p_Data),<span style="color: #0000ff;">sizeof</span>(WebSites));</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   5:</span>     binary_file.close();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   6:</span> } </pre>
</div>
</div>
<p>上面的例子把一个WebSites的对象追加进了c:\test.dat之中，ios::app是追加方式操作文件的标志。
</p>
<p>上面的write函数，需要第一个参数为char*类型，所以用 reinterpret_cast转换将这个对象地址转换成char*类型.
</p>
<p>读操作
</p>
<p>&nbsp;&nbsp; 跟上面的操作流程类似. 唯一不同在于使用输入模式标志ios::in, 使用read()方法.
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Sample for C++ File I/O binary file read </p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">void</span> read_from_binary_file()</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   3:</span>     WebSites p_Data;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   4:</span>     fstream binary_file(<span style="color: #006080;">"c:\\test.dat"</span>,ios::binary|ios::<span style="color: #0000ff;">in</span>);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   5:</span>     binary_file.read(reinterpret_cast&lt;<span style="color: #0000ff;">char</span> *&gt;(&amp;p_Data),<span style="color: #0000ff;">sizeof</span>(WebSites));</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   6:</span>     binary_file.close();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   7:</span>     cout&lt;&lt;p_Data.SiteName&lt;&lt;endl;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #606060;">   8:</span>     cout&lt;&lt;<span style="color: #006080;">"Rank :"</span>&lt;&lt; p_Data.Rank&lt;&lt;endl;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #606060;">   9:</span> } </pre>
</div>
</div>
<p>本文只是关于文件io流的一些基础介绍，一些高级操作比如seek，检查文件指针的有效性等等，也是需要学习的，这里就不多说了。
</p>
<p><a href="http://www.codersource.net/cpp_file_io_binary.html" target="_blank">文章来源</a>&nbsp; 我只是做一个简短的翻译</p><img src ="http://www.cppblog.com/gohan/aggbug/49303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-09 14:41 <a href="http://www.cppblog.com/gohan/archive/2008/05/09/49303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>获取给定路径的图标，演示SHGetFileInfo用法</title><link>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 01 May 2008 20:54:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/48617.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/48617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/48617.html</trackback:ping><description><![CDATA[<div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000"><font color="#000000">基于上次那个</font><a href="http://www.cppblog.com/gohan/archive/2008/04/24/47993.html" target="_blank"><font color="#000000">SHBrowseForFolder用法的演示代码</font></a></span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000"><font color="#000000">建立的仍然是Win32 命令行的工程，所以入口点为main(),需要手动获取HINSTANCE结构。程序在WINXP+VS2005测试通过</font><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="145" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHGetFileInfo_3B22/image_3.png" width="199" align="right" border="0"></span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">/********************************************************************<br>&nbsp; created:&nbsp; 2008/05/02<br>&nbsp; created:&nbsp; 2:5:2008&nbsp;&nbsp; 3:40</span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; main.cpp<br>&nbsp; author:&nbsp;&nbsp;&nbsp; Gohan <br>&nbsp; purpose:&nbsp; 演示SHBrowseForFolder用法<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 演示SHGetFileInfo获取路径图标&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 演示Picture Box在SDK里的使用方法</span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">*********************************************************************/<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">&lt;Windows.h&gt;<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">&lt;ShlObj.h&gt;<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"resource.h"<br></span><span style="color: #000000">HICON</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_icon</span><span style="color: #000000">; <br></span><span style="color: #000000">RECT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">;<br></span><span style="color: #000000">TCHAR</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_path</span><span style="color: #000000">[</span><span style="color: #000000">MAX_PATH</span><span style="color: #000000">];<br></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">OnInitDlg</span><span style="color: #000000">(</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hwnd</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">GetWindowRect</span><span style="color: #000000">(</span><span style="color: #000000">GetDlgItem</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, </span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">), &amp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">MapWindowPoints</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">, </span><span style="color: #000000">hwnd</span><span style="color: #000000">, (</span><span style="color: #000000">LPPOINT</span><span style="color: #000000">) &amp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">, 2);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DestroyWindow</span><span style="color: #000000">(</span><span style="color: #000000">GetDlgItem</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, </span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SetDlgItemText</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">,</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">,</span><span style="color: #000000">g_path</span><span style="color: #000000">);<br>}<br></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">OnPaint</span><span style="color: #000000">(</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hwnd</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">PAINTSTRUCT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">ps</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">HDC</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hdc</span><span style="color: #000000"> = </span><span style="color: #000000">BeginPaint</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, &amp;</span><span style="color: #000000">ps</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DrawIcon</span><span style="color: #000000">(</span><span style="color: #000000">hdc</span><span style="color: #000000">,</span><span style="color: #000000">g_rect</span><span style="color: #000000">.</span><span style="color: #000000">left</span><span style="color: #000000">,</span><span style="color: #000000">g_rect</span><span style="color: #000000">.</span><span style="color: #000000">left</span><span style="color: #000000">,</span><span style="color: #000000">g_icon</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">EndPaint</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">,&amp;</span><span style="color: #000000">ps</span><span style="color: #000000">);<br>}<br></span><span style="color: #000000">BOOL</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">CALLBACK</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DlgProc</span><span style="color: #000000"> (</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hDlg</span><span style="color: #000000">, </span><span style="color: #000000">UINT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">message</span><span style="color: #000000">, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">WPARAM</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">wParam</span><span style="color: #000000">, </span><span style="color: #000000">LPARAM</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">lParam</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (</span><span style="color: #000000">message</span><span style="color: #000000">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_INITDIALOG</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">OnInitDlg</span><span style="color: #000000">(</span><span style="color: #000000">hDlg</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">TRUE</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_PAINT</span><span style="color: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">OnPaint</span><span style="color: #000000">(</span><span style="color: #000000">hDlg</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">TRUE</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_COMMAND</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (</span><span style="color: #000000">LOWORD</span><span style="color: #000000"> (</span><span style="color: #000000">wParam</span><span style="color: #000000">))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDOK</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDCANCEL</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">EndDialog</span><span style="color: #000000"> (</span><span style="color: #000000">hDlg</span><span style="color: #000000">, 0) ;<br>&nbsp;&nbsp;&nbsp;&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">TRUE</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">break</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">FALSE</span><span style="color: #000000"> ;<br>}<br></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">main</span><span style="color: #000000">()<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">HINSTANCE</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hInstance</span><span style="color: #000000"> = (</span><span style="color: #000000">HINSTANCE</span><span style="color: #000000">)</span><span style="color: #000000">GetModuleHandle</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">BROWSEINFO</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">bi</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">ZeroMemory</span><span style="color: #000000">(&amp;</span><span style="color: #000000">bi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">BROWSEINFO</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LPMALLOC</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">pMalloc</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LPITEMIDLIST</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">pidl</span><span style="color: #000000"> = </span><span style="color: #000000">SHBrowseForFolder</span><span style="color: #000000">(&amp;</span><span style="color: #000000">bi</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000"> != </span><span style="color: #000000">NULL</span><span style="color: #000000">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHGetPathFromIDList</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000">,</span><span style="color: #000000">g_path</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">sfi</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">ZeroMemory</span><span style="color: #000000">(&amp;</span><span style="color: #000000">sfi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHGetFileInfo</span><span style="color: #000000">(</span><span style="color: #000000">g_path</span><span style="color: #000000">,0,&amp;</span><span style="color: #000000">sfi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">),</span><span style="color: #000000">SHGFI_ICON</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">g_icon</span><span style="color: #000000"> = </span><span style="color: #000000">sfi</span><span style="color: #000000">.</span><span style="color: #000000">hIcon</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DialogBox</span><span style="color: #000000"> (</span><span style="color: #000000">hInstance</span><span style="color: #000000">, </span><span style="color: #000000">MAKEINTRESOURCE</span><span style="color: #000000">(</span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">), 0, </span><span style="color: #000000">DlgProc</span><span style="color: #000000">) ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #008000">//MessageBox(NULL,path,TEXT("Choose"),MB_OK);<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">SUCCEEDED</span><span style="color: #000000">(</span><span style="color: #000000">SHGetMalloc</span><span style="color: #000000">(&amp;</span><span style="color: #000000">pMalloc</span><span style="color: #000000">)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">pMalloc</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Free</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">pMalloc</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Release</span><span style="color: #000000">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">else<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">MessageBox</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">,</span><span style="color: #000000">TEXT</span><span style="color: #000000">(</span><span style="color: #800000">"</span><span style="color: #000000">),</span><span style="color: #000000">TEXT</span><span style="color: #000000">(</span><span style="color: #800000">"Choose"</span><span style="color: #000000">),</span><span style="color: #000000">MB_OK</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; }<br>}<br><span style="color: #008000">/************************************************************************/<br>/* resource.h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>/************************************************************************/<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 101<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1001<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1002<br></span><span style="color: #008000">/************************************************************************/<br>/* demo.rc Microsoft Visual C++ generated resource script.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>/************************************************************************/<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"resource.h"<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"afxres.h"<br></span><span style="color: #008000">/////////////////////////////////////////////////////////////////////////////<br>//<br>// Dialog<br>//<br><br></span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DIALOGEX</span><span style="color: #000000"> 0, 0, 126, 83<br></span><span style="color: #000000">STYLE</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DS_SETFONT</span><span style="color: #000000"> | </span><span style="color: #000000">DS_MODALFRAME</span><span style="color: #000000"> | </span><span style="color: #000000">DS_FIXEDSYS</span><span style="color: #000000"> | </span><span style="color: #000000">DS_CENTER</span><span style="color: #000000"> | </span><span style="color: #000000">WS_POPUP<br>FONT</span><span style="color: #000000"> 8, </span><span style="color: #800000">"MS Shell Dlg"</span><span style="color: #000000">, 400, 0, 0x1<br></span><span style="color: #000000">BEGIN<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DEFPUSHBUTTON</span><span style="color: #000000">&nbsp;&nbsp; </span><span style="color: #800000">"确定"</span><span style="color: #000000">,</span><span style="color: #000000">IDOK</span><span style="color: #000000">,69,7,50,14<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">PUSHBUTTON</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">"取消"</span><span style="color: #000000">,</span><span style="color: #000000">IDCANCEL</span><span style="color: #000000">,69,24,50,14<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">CONTROL</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">""</span><span style="color: #000000">,</span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">,</span><span style="color: #800000">"Static"</span><span style="color: #000000">,</span><span style="color: #000000">SS_WHITEFRAME</span><span style="color: #000000"> | </span><span style="color: #000000">SS_REALSIZEIMAGE</span><span style="color: #000000">,13,10,20,20,</span><span style="color: #000000">WS_EX_TRANSPARENT<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LTEXT</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">"静态"</span><span style="color: #000000">,</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">,14,44,89,21,0,</span><span style="color: #000000">WS_EX_CLIENTEDGE<br>END<br><br><br></span><span style="color: #008000">/////////////////////////////////////////////////////////////////////////////<br></span></div><img src ="http://www.cppblog.com/gohan/aggbug/48617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-02 04:54 <a href="http://www.cppblog.com/gohan/archive/2008/05/02/48617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浏览文件夹对话框，演示SHBrowseForFolder用法</title><link>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 24 Apr 2008 05:15:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/47993.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/47993.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/47993.html</trackback:ping><description><![CDATA[<div class="code" style="font-size: 9pt; font-family: consolas;"><a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHBrowseForFolder_BA3A/image_2.png"><img style="border: 0px none ;" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHBrowseForFolder_BA3A/image_thumb.png" align="right" border="0" height="240" width="244"></a> </div>
<div class="code" style="font-size: 9pt; font-family: consolas;"><span style="color: #008000;">/********************************************************************<br>&nbsp; created:&nbsp; 2008/04/24<br>&nbsp; created:&nbsp; 24:4:2008&nbsp;&nbsp; 12:47<br>&nbsp; author:&nbsp;&nbsp;&nbsp; Gohan <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://feed.feedsky.com/gohan<br>&nbsp; purpose:&nbsp; 演示SHBrowseForFolder用法<br>*********************************************************************/<br></span><span style="color: #0000ff;">#include</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">&lt;Windows.h&gt;<br></span><span style="color: #0000ff;">#include</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">&lt;ShlObj.h&gt;<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">main</span><span style="color: #000000;">()<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">BROWSEINFO</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">ZeroMemory</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(</span><span style="color: #000000;">BROWSEINFO</span><span style="color: #000000;">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">LPMALLOC</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">LPITEMIDLIST</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">pidl</span><span style="color: #000000;"> = </span><span style="color: #000000;">SHBrowseForFolder</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">TCHAR</span><span style="color: #000000;"> * </span><span style="color: #000000;">path</span><span style="color: #000000;"> = </span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">TCHAR</span><span style="color: #000000;">[</span><span style="color: #000000;">MAX_PATH</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;"> != </span><span style="color: #000000;">NULL</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">SHGetPathFromIDList</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;">,</span><span style="color: #000000;">path</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">MessageBox</span><span style="color: #000000;">(</span><span style="color: #000000;">NULL</span><span style="color: #000000;">,</span><span style="color: #000000;">path</span><span style="color: #000000;">,</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"Choose"</span><span style="color: #000000;">),</span><span style="color: #000000;">MB_OK</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">SUCCEEDED</span><span style="color: #000000;">(</span><span style="color: #000000;">SHGetMalloc</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">)))</span><span style="color: #008000;">//pidl指向的对象用完应该释放，之前忽略了<br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Free</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Release</span><span style="color: #000000;">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">else<br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">MessageBox</span><span style="color: #000000;">(</span><span style="color: #000000;">NULL</span><span style="color: #000000;">,</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">选择为空"</span><span style="color: #000000;">),</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"Choose"</span><span style="color: #000000;">),</span><span style="color: #000000;">MB_OK</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">delete</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">path</span><span style="color: #000000;">;</span><span style="color: #008000;">//谢谢true的提醒，以后我一定会更加慎重<br></span><span style="color: #000000;">}<br></span></div>
<div class="code" style="font-size: 9pt; font-family: consolas;"><span style="color: #008000;"></span><span style="color: #000000;"><br></span></div><img src ="http://www.cppblog.com/gohan/aggbug/47993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-04-24 13:15 <a href="http://www.cppblog.com/gohan/archive/2008/04/24/47993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让cout打印出16色字符</title><link>http://www.cppblog.com/gohan/archive/2008/04/19/47561.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 18 Apr 2008 20:24:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/04/19/47561.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/47561.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/04/19/47561.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/47561.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/47561.html</trackback:ping><description><![CDATA[<p><a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/cout16_3DD2/image_4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="99" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/cout16_3DD2/image_thumb_1.png" width="671" border="0"></a> </p> <p>Win32命令行应用程序是可以加颜色的，使用<font color="#0000ff">SetConsoleTextAttribute</font><font color="#000000">就可以实现了，记得前年小学期做的程序作业就用了它。</font></p> <p><font color="#000000">这篇文章很简单，你可以当作是一个<font color="#0000ff">cout &lt;&lt;运算符重载</font>的一个简单例子。本文章来源与<a href="http://www.codeproject.com/KB/cpp/cout_color.aspx" target="_blank">这里</a>，我只是做一个很不专业解释。</font></p> <p>本文章提供的库可以如下使用，上面是显示效果，想起小时候玩的Mud了吧。</p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">#include</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> </font><span style="color: maroon"><font face="Courier New" size="2">"ConsoleColor.h"<br></font></span></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; color: black; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">std</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">::<span style="color: black">cout</span> &lt;&lt; <span style="color: black">green</span> &lt;&lt; <span style="color: maroon">"This text is written in green"</span> </span></font></font><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">&lt;&lt; <span style="color: black">white</span> &lt;&lt; <span style="color: black">std</span>::<span style="color: black">endl</span>;<br></span><span lang="EN-US" style="font-size: 9pt; color: black; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">std</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">::<span style="color: black">cout</span> &lt;&lt; <span style="color: black">color</span>(<span style="color: black">FOREGROUND_RED</span>|<span style="color: black">FOREGROUND_GREEN</span>) </span></font></font><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">&lt;&lt; <span style="color: maroon">"This text has a really exiting color !"</span> <br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">&lt;&lt; <span style="color: black">white</span> &lt;&lt; <span style="color: black">std</span>::<span style="color: black">endl</span>;</span></font></font></p> <p><font face="Courier New" size="2">ConsoleColor.h的内容</font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">#pragma</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> </font><span style="color: blue"><font face="Courier New" size="2">once<br></font></span></span><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">#include</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> </font><span style="color: maroon"><font face="Courier New" size="2">&lt;iostream&gt;<br></font></span></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">#include</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"> <span style="color: maroon">&lt;windows.h&gt;<?xml:namespace prefix = o /><o:p></o:p></span></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">inline</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">std</span>::<span style="color: black">ostream</span>&amp; <span style="color: black">blue</span>(<span style="color: black">std</span>::<span style="color: black">ostream</span> &amp;<span style="color: black">s</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span> = <span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>, </font></font><span style="color: black"><font face="Courier New" size="2">FOREGROUND_BLUE<br></font></span></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>|<span style="color: black">FOREGROUND_GREEN</span>|<span style="color: black">FOREGROUND_INTENSITY</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">s</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">inline</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">std</span>::<span style="color: black">ostream</span>&amp; <span style="color: black">red</span>(<span style="color: black">std</span>::<span style="color: black">ostream</span> &amp;<span style="color: black">s</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span> = <span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>, <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: black">FOREGROUND_RED</span>|<span style="color: black">FOREGROUND_INTENSITY</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">s</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">inline</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">std</span>::<span style="color: black">ostream</span>&amp; <span style="color: black">green</span>(<span style="color: black">std</span>::<span style="color: black">ostream</span> &amp;<span style="color: black">s</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span> = <span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>, <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: black">FOREGROUND_GREEN</span>|<span style="color: black">FOREGROUND_INTENSITY</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">s</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">inline</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">std</span>::<span style="color: black">ostream</span>&amp; <span style="color: black">yellow</span>(<span style="color: black">std</span>::<span style="color: black">ostream</span> &amp;<span style="color: black">s</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span> = <span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>, <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: black">FOREGROUND_GREEN</span>|<span style="color: black">FOREGROUND_RED</span>|<span style="color: black">FOREGROUND_INTENSITY</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">s</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">inline</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">std</span>::<span style="color: black">ostream</span>&amp; <span style="color: black">white</span>(<span style="color: black">std</span>::<span style="color: black">ostream</span> &amp;<span style="color: black">s</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp; </span><span style="mso-spacerun: yes">&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span> = <span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>, <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: black">FOREGROUND_RED</span>|<span style="color: black">FOREGROUND_GREEN</span>|<span style="color: black">FOREGROUND_BLUE</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">s</span>;<br></span></font><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">}//以上这些函数定义本身就是cout的&lt;&lt;操作符的一种参数重载形式,即：<br></font></span></font><font face="Courier New" size="2">//basic_ostream&amp; operator&lt;&lt;( basic_ostream&amp; (*_Pfn)(basic_ostream&amp;) );</font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"></span><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">struct</font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2"> <span style="color: black">color</span> {<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">color</span>(<span style="color: black">WORD</span> <span style="color: black">attribute</span>):<span style="color: black">m_color</span>(<span style="color: black">attribute</span>){};<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">WORD</span> <span style="color: black">m_color</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">};</span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">template</font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"> &lt;<span style="color: blue">class</span> <span style="color: black">_Elem</span>, <span style="color: blue">class</span> <span style="color: black">_Traits</span>&gt;<br></span><span lang="EN-US" style="font-size: 9pt; color: black; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">std</span></font></font><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">::<span style="color: black">basic_ostream</span>&lt;<span style="color: black">_Elem</span>,<span style="color: black">_Traits</span>&gt;&amp; <br></span><span lang="EN-US" style="font-size: 9pt; color: blue; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">operator</span></font></font><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">&lt;&lt;(<span style="color: black">std</span>::<span style="color: black">basic_ostream</span>&lt;<span style="color: black">_Elem</span>,<span style="color: black">_Traits</span>&gt;&amp; <span style="color: black">i</span>, <span style="color: black">color</span>&amp; <span style="color: black">c</span>)<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Courier New" size="2">{<br></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">HANDLE</span> <span style="color: black">hStdout</span>=<span style="color: black">GetStdHandle</span>(<span style="color: black">STD_OUTPUT_HANDLE</span>); <br></font></font></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><font size="2"><font face="Courier New"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: black">SetConsoleTextAttribute</span>(<span style="color: black">hStdout</span>,<span style="color: black">c</span>.<span style="color: black">m_color</span>);<br></font></font></span><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> <span style="color: black">i</span>;<br></span><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}</span></font></font></p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"></span></font></font>&nbsp;</p> <p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><font size="2"><font face="Courier New"><span lang="EN-US" style="font-size: 9pt; font-family: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">最后这个是对于&lt;&lt;操作符的重载，形式类似于如下</span></font></font></p><pre>template&lt;class _Tr&gt;
   basic_ostream&lt;char, _Tr&gt;&amp; operator&lt;&lt;(
      basic_ostream&lt;char, _Tr&gt;&amp; _Ostr,
      const unsigned char *_Str);</pre><pre>OK，发挥你的想象力，让c++变得更有趣吧。</pre>
<p class="MsoNormal"><span lang="EN-US"><o:p> 参考链接：</o:p></span></p>
<h3><a href="http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles4.html" target="_blank">Win32 Console Applications - Part 4.</a> 这个就是最初我使用命令行色彩的参考，有兴趣可以看看。今天做了一个归并排序演示程序，还要继续完善，我MFC很烂，完了放出烂烂的代码。<a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/cout16_3DD2/image_8.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="122" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/cout16_3DD2/image_thumb_3.png" width="244" border="0"></a>  </h3>
<p class="MsoNormal"></p><img src ="http://www.cppblog.com/gohan/aggbug/47561.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-04-19 04:24 <a href="http://www.cppblog.com/gohan/archive/2008/04/19/47561.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>error PRJ0002 不用重装的解决方法</title><link>http://www.cppblog.com/gohan/archive/2007/09/13/32157.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 13 Sep 2007 10:55:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/09/13/32157.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/32157.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/09/13/32157.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/32157.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/32157.html</trackback:ping><description><![CDATA[上周帮北邮同学写了个MFC小学期制作,事情告一段落,今天他问我一些具体细节,我给他演示时候第一次打开vs2005没有响应,重新打开发现编译就出现了这个尴尬的错误<br>今天遇到一个尴尬问题:error PRJ0002,cl.exe 在命令行也无法正常运转,解决方法<br>Ronan THOMAS:&nbsp; disinstalled windows update patch KB925902 <br>我卸了KB925902,ok了<br>如果不行估计还是要reinstall vs2005...
<img src ="http://www.cppblog.com/gohan/aggbug/32157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-09-13 18:55 <a href="http://www.cppblog.com/gohan/archive/2007/09/13/32157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>zju1942解题报告</title><link>http://www.cppblog.com/gohan/archive/2007/07/28/28907.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 28 Jul 2007 13:04:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/07/28/28907.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/28907.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/07/28/28907.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/28907.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/28907.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 这道题我用了Kruscal+并查集算的之前并查集用的不对,所以一直WA并查集代码来自我的那本写数据结构与算法分析c++版 knuth的徒孙的网站#include&nbsp;&lt;cstdio&gt;#include&nbsp;&lt;vector&gt;#include&nbsp;&lt;cmath&gt;#include&nbsp;&lt;algorithm&gt;using&nbsp;n...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2007/07/28/28907.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/28907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-07-28 21:04 <a href="http://www.cppblog.com/gohan/archive/2007/07/28/28907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku3297解题报告</title><link>http://www.cppblog.com/gohan/archive/2007/07/28/28898.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 28 Jul 2007 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/07/28/28898.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/28898.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/07/28/28898.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/28898.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/28898.html</trackback:ping><description><![CDATA[<p>这道题我用的方法很麻烦,使用一个结构体vector保存结果,使用一个map判断是不是一个人报了两个工程.使用set判断一个工程是不是有人重复报名<br>于是就有了下面的笨拙代码<br><br></p>
<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">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">memory.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;Project<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_144_260_Open_Image onclick="this.style.display='none'; Codehighlighter1_144_260_Open_Text.style.display='none'; Codehighlighter1_144_260_Closed_Image.style.display='inline'; Codehighlighter1_144_260_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_144_260_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_144_260_Closed_Text.style.display='none'; Codehighlighter1_144_260_Open_Image.style.display='inline'; Codehighlighter1_144_260_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_144_260_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_144_260_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;name;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;studentcount;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Project()<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img id=Codehighlighter1_203_258_Open_Image onclick="this.style.display='none'; Codehighlighter1_203_258_Open_Text.style.display='none'; Codehighlighter1_203_258_Closed_Image.style.display='inline'; Codehighlighter1_203_258_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_203_258_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_203_258_Closed_Text.style.display='none'; Codehighlighter1_203_258_Open_Image.style.display='inline'; Codehighlighter1_203_258_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_203_258_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_203_258_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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentcount</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name.assign(</span><span style="COLOR: #000000">""</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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></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/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;studentmap;<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;studentset;<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">Project</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;prov;<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img id=Codehighlighter1_358_360_Open_Image onclick="this.style.display='none'; Codehighlighter1_358_360_Open_Text.style.display='none'; Codehighlighter1_358_360_Closed_Image.style.display='inline'; Codehighlighter1_358_360_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_358_360_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_358_360_Closed_Text.style.display='none'; Codehighlighter1_358_360_Open_Image.style.display='inline'; Codehighlighter1_358_360_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;countarray[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_358_360_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_358_360_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;strtemp[</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>Project&nbsp;project;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>inline&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;comp(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Project&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p1,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Project&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p2)<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img id=Codehighlighter1_457_503_Open_Image onclick="this.style.display='none'; Codehighlighter1_457_503_Open_Text.style.display='none'; Codehighlighter1_457_503_Closed_Image.style.display='inline'; Codehighlighter1_457_503_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_457_503_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_457_503_Closed_Text.style.display='none'; Codehighlighter1_457_503_Open_Image.style.display='inline'; Codehighlighter1_457_503_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_457_503_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_457_503_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;p1.studentcount</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">p2.studentcount;<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>inline&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;comp2(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Project&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p1,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Project&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p2)<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img id=Codehighlighter1_560_601_Open_Image onclick="this.style.display='none'; Codehighlighter1_560_601_Open_Text.style.display='none'; Codehighlighter1_560_601_Closed_Image.style.display='inline'; Codehighlighter1_560_601_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_560_601_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_560_601_Closed_Text.style.display='none'; Codehighlighter1_560_601_Open_Image.style.display='inline'; Codehighlighter1_560_601_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_560_601_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_560_601_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;p1.name.compare(p2.name)</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img id=Codehighlighter1_615_2293_Open_Image onclick="this.style.display='none'; Codehighlighter1_615_2293_Open_Text.style.display='none'; Codehighlighter1_615_2293_Closed_Image.style.display='inline'; Codehighlighter1_615_2293_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_615_2293_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_615_2293_Closed_Text.style.display='none'; Codehighlighter1_615_2293_Open_Image.style.display='inline'; Codehighlighter1_615_2293_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_615_2293_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_615_2293_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img id=Codehighlighter1_642_2291_Open_Image onclick="this.style.display='none'; Codehighlighter1_642_2291_Open_Text.style.display='none'; Codehighlighter1_642_2291_Closed_Image.style.display='inline'; Codehighlighter1_642_2291_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_642_2291_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_642_2291_Closed_Text.style.display='none'; Codehighlighter1_642_2291_Open_Image.style.display='inline'; Codehighlighter1_642_2291_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_642_2291_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_642_2291_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;projcount</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov.push_back(project);<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img id=Codehighlighter1_730_1907_Open_Image onclick="this.style.display='none'; Codehighlighter1_730_1907_Open_Text.style.display='none'; Codehighlighter1_730_1907_Closed_Image.style.display='inline'; Codehighlighter1_730_1907_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_730_1907_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_730_1907_Closed_Text.style.display='none'; Codehighlighter1_730_1907_Open_Image.style.display='inline'; Codehighlighter1_730_1907_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_730_1907_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_730_1907_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gets(strtemp);<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;project.name.assign(strtemp);<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">break</span><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)exit(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img id=Codehighlighter1_960_1080_Open_Image onclick="this.style.display='none'; Codehighlighter1_960_1080_Open_Text.style.display='none'; Codehighlighter1_960_1080_Closed_Image.style.display='inline'; Codehighlighter1_960_1080_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_960_1080_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_960_1080_Closed_Text.style.display='none'; Codehighlighter1_960_1080_Open_Image.style.display='inline'; Codehighlighter1_960_1080_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_960_1080_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_960_1080_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov.push_back(project);<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentset.clear();<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;projcount</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">project.name[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img id=Codehighlighter1_1153_1873_Open_Image onclick="this.style.display='none'; Codehighlighter1_1153_1873_Open_Text.style.display='none'; Codehighlighter1_1153_1873_Closed_Image.style.display='inline'; Codehighlighter1_1153_1873_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1153_1873_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1153_1873_Closed_Text.style.display='none'; Codehighlighter1_1153_1873_Open_Image.style.display='inline'; Codehighlighter1_1153_1873_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1153_1873_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_1153_1873_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(studentmap[strtemp]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img id=Codehighlighter1_1214_1283_Open_Image onclick="this.style.display='none'; Codehighlighter1_1214_1283_Open_Text.style.display='none'; Codehighlighter1_1214_1283_Closed_Image.style.display='inline'; Codehighlighter1_1214_1283_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1214_1283_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1214_1283_Closed_Text.style.display='none'; Codehighlighter1_1214_1283_Open_Image.style.display='inline'; Codehighlighter1_1214_1283_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1214_1283_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_1214_1283_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentmap[strtemp]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">projcount;<br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(studentmap[strtemp]</span><span style="COLOR: #000000">==-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img id=Codehighlighter1_1350_1398_Open_Image onclick="this.style.display='none'; Codehighlighter1_1350_1398_Open_Text.style.display='none'; Codehighlighter1_1350_1398_Closed_Image.style.display='inline'; Codehighlighter1_1350_1398_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1350_1398_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1350_1398_Closed_Text.style.display='none'; Codehighlighter1_1350_1398_Open_Image.style.display='inline'; Codehighlighter1_1350_1398_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1350_1398_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_1350_1398_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(studentmap[strtemp]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">projcount)<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img id=Codehighlighter1_1472_1626_Open_Image onclick="this.style.display='none'; Codehighlighter1_1472_1626_Open_Text.style.display='none'; Codehighlighter1_1472_1626_Closed_Image.style.display='inline'; Codehighlighter1_1472_1626_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1472_1626_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1472_1626_Closed_Text.style.display='none'; Codehighlighter1_1472_1626_Open_Image.style.display='inline'; Codehighlighter1_1472_1626_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1472_1626_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_1472_1626_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov[studentmap[strtemp]].studentcount</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentmap[strtemp]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(studentset.count(strtemp))<br></span><span style="COLOR: #008080">72</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">73</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">74</span><span style="COLOR: #000000"><img id=Codehighlighter1_1741_1859_Open_Image onclick="this.style.display='none'; Codehighlighter1_1741_1859_Open_Text.style.display='none'; Codehighlighter1_1741_1859_Closed_Image.style.display='inline'; Codehighlighter1_1741_1859_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1741_1859_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1741_1859_Closed_Text.style.display='none'; Codehighlighter1_1741_1859_Open_Image.style.display='inline'; Codehighlighter1_1741_1859_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1741_1859_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_1741_1859_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">75</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentset.insert(strtemp);<br></span><span style="COLOR: #008080">76</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov[projcount].studentcount</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">77</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">78</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">79</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">80</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov.erase(prov.begin());<br></span><span style="COLOR: #008080">81</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stable_sort(prov.begin(),prov.end(),comp2);<br></span><span style="COLOR: #008080">82</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stable_sort(prov.begin(),prov.end(),comp);<br></span><span style="COLOR: #008080">83</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">prov.size();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">84</span><span style="COLOR: #000000"><img id=Codehighlighter1_2093_2177_Open_Image onclick="this.style.display='none'; Codehighlighter1_2093_2177_Open_Text.style.display='none'; Codehighlighter1_2093_2177_Closed_Image.style.display='inline'; Codehighlighter1_2093_2177_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_2093_2177_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2093_2177_Closed_Text.style.display='none'; Codehighlighter1_2093_2177_Open_Image.style.display='inline'; Codehighlighter1_2093_2177_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_2093_2177_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_2093_2177_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">85</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s&nbsp;%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,prov[i].name.c_str(),prov[i].studentcount);<br></span><span style="COLOR: #008080">86</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">87</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(countarray,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(countarray));<br></span><span style="COLOR: #008080">88</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;studentmap.clear();<br></span><span style="COLOR: #008080">89</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prov.clear();<br></span><span style="COLOR: #008080">90</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">91</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">92</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">93</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">94</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/gohan/aggbug/28898.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-07-28 16:37 <a href="http://www.cppblog.com/gohan/archive/2007/07/28/28898.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3286解题报告</title><link>http://www.cppblog.com/gohan/archive/2007/07/25/pku3286.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Wed, 25 Jul 2007 00:20:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/07/25/pku3286.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/28736.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/07/25/pku3286.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/28736.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/28736.html</trackback:ping><description><![CDATA[<p>我的做法可能很弱智<br>给定一个数x&gt;0算通过每一位零出现次数的统计,算出所有的0的次数(从1到X)<br><br>举一个例子<br>2508这个数<br>首先考虑个位数<br>250X&nbsp; X=0;一共有250-1+1个<br>25X8&nbsp; X=0;一共有258-10+1个<br>2X08 X=0;注意并不只有208-100+1中可能,我之前就错在这里了,因为最大2508,所以2099-2009这百位的零我就没有考虑到,所以这里的0有299-100+1个<br><br>于是题目就做出来了<br><br>输入一个a b<br>a&lt;b<br>a==0时<br>b统计出零的个数然后加1(0)的个数<br>否则从a 到 b的0的个数则是从1到b的0个数减去从1到a-1的零的个数<br>a&lt;10的情况我害怕出错就分开写了,所以整个程序有些长<br><br>下面就是我笨拙的代码<br></p>
<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">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cmath</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img id=Codehighlighter1_134_136_Open_Image onclick="this.style.display='none'; Codehighlighter1_134_136_Open_Text.style.display='none'; Codehighlighter1_134_136_Closed_Image.style.display='inline'; Codehighlighter1_134_136_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_134_136_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_134_136_Closed_Text.style.display='none'; Codehighlighter1_134_136_Open_Image.style.display='inline'; Codehighlighter1_134_136_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;aarray[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_134_136_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_134_136_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_160_162_Open_Image onclick="this.style.display='none'; Codehighlighter1_160_162_Open_Text.style.display='none'; Codehighlighter1_160_162_Closed_Image.style.display='inline'; Codehighlighter1_160_162_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_160_162_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_160_162_Closed_Text.style.display='none'; Codehighlighter1_160_162_Open_Image.style.display='inline'; Codehighlighter1_160_162_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;barray[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_160_162_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_160_162_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img id=Codehighlighter1_184_186_Open_Image onclick="this.style.display='none'; Codehighlighter1_184_186_Open_Text.style.display='none'; Codehighlighter1_184_186_Closed_Image.style.display='inline'; Codehighlighter1_184_186_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_184_186_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_184_186_Closed_Text.style.display='none'; Codehighlighter1_184_186_Open_Image.style.display='inline'; Codehighlighter1_184_186_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;diff[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_184_186_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_184_186_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;tempstr[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;calc(std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;str,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i)<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img id=Codehighlighter1_246_704_Open_Image onclick="this.style.display='none'; Codehighlighter1_246_704_Open_Text.style.display='none'; Codehighlighter1_246_704_Closed_Image.style.display='inline'; Codehighlighter1_246_704_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_246_704_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_246_704_Closed_Text.style.display='none'; Codehighlighter1_246_704_Open_Image.style.display='inline'; Codehighlighter1_246_704_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_246_704_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_246_704_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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">str.erase()</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">16</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">(str.size()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">))&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">str.size();<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;needminus&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">(pow(</span><span style="COLOR: #000000">10.0</span><span style="COLOR: #000000">,i));<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">if(i!=0)str[len-i-2]+=(str[len-i-1]-'0');</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">new&nbsp;add</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">20</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img id=Codehighlighter1_463_495_Open_Image onclick="this.style.display='none'; Codehighlighter1_463_495_Open_Text.style.display='none'; Codehighlighter1_463_495_Closed_Image.style.display='inline'; Codehighlighter1_463_495_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_463_495_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_463_495_Closed_Text.style.display='none'; Codehighlighter1_463_495_Open_Image.style.display='inline'; Codehighlighter1_463_495_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_463_495_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_463_495_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;str.erase(len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</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">23</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img id=Codehighlighter1_510_575_Open_Image onclick="this.style.display='none'; Codehighlighter1_510_575_Open_Text.style.display='none'; Codehighlighter1_510_575_Closed_Image.style.display='inline'; Codehighlighter1_510_575_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_510_575_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_510_575_Closed_Text.style.display='none'; Codehighlighter1_510_575_Open_Image.style.display='inline'; Codehighlighter1_510_575_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_510_575_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_510_575_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str.erase(len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str.append(i,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">str.size();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img id=Codehighlighter1_615_654_Open_Image onclick="this.style.display='none'; Codehighlighter1_615_654_Open_Text.style.display='none'; Codehighlighter1_615_654_Closed_Image.style.display='inline'; Codehighlighter1_615_654_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_615_654_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_615_654_Closed_Text.style.display='none'; Codehighlighter1_615_654_Open_Image.style.display='inline'; Codehighlighter1_615_654_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_615_654_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_615_654_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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(str[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></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>&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">needminus;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;sum;<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img id=Codehighlighter1_718_1882_Open_Image onclick="this.style.display='none'; Codehighlighter1_718_1882_Open_Text.style.display='none'; Codehighlighter1_718_1882_Closed_Image.style.display='inline'; Codehighlighter1_718_1882_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_718_1882_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_718_1882_Closed_Text.style.display='none'; Codehighlighter1_718_1882_Open_Image.style.display='inline'; Codehighlighter1_718_1882_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_718_1882_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_718_1882_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,b;<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;tempstring;<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;add;<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%u&nbsp;%u</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b))<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img id=Codehighlighter1_819_1880_Open_Image onclick="this.style.display='none'; Codehighlighter1_819_1880_Open_Text.style.display='none'; Codehighlighter1_819_1880_Closed_Image.style.display='inline'; Codehighlighter1_819_1880_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_819_1880_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_819_1880_Closed_Text.style.display='none'; Codehighlighter1_819_1880_Open_Image.style.display='inline'; Codehighlighter1_819_1880_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_819_1880_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_819_1880_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img id=Codehighlighter1_886_932_Open_Image onclick="this.style.display='none'; Codehighlighter1_886_932_Open_Text.style.display='none'; Codehighlighter1_886_932_Closed_Image.style.display='inline'; Codehighlighter1_886_932_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_886_932_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_886_932_Closed_Text.style.display='none'; Codehighlighter1_886_932_Open_Image.style.display='inline'; Codehighlighter1_886_932_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_886_932_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_886_932_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;alen,blen;<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img id=Codehighlighter1_1019_1054_Open_Image onclick="this.style.display='none'; Codehighlighter1_1019_1054_Open_Text.style.display='none'; Codehighlighter1_1019_1054_Closed_Image.style.display='inline'; Codehighlighter1_1019_1054_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1019_1054_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1019_1054_Closed_Text.style.display='none'; Codehighlighter1_1019_1054_Open_Image.style.display='inline'; Codehighlighter1_1019_1054_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1019_1054_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_1019_1054_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aarray[</span><span style="COLOR: #000000">0</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">59</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img id=Codehighlighter1_1077_1308_Open_Image onclick="this.style.display='none'; Codehighlighter1_1077_1308_Open_Text.style.display='none'; Codehighlighter1_1077_1308_Closed_Image.style.display='inline'; Codehighlighter1_1077_1308_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1077_1308_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1077_1308_Closed_Text.style.display='none'; Codehighlighter1_1077_1308_Open_Image.style.display='inline'; Codehighlighter1_1077_1308_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1077_1308_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_1077_1308_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_i64toa(a,tempstr,</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alen&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;strlen(tempstr);<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempstring.assign(tempstr);<br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">alen;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img id=Codehighlighter1_1238_1298_Open_Image onclick="this.style.display='none'; Codehighlighter1_1238_1298_Open_Text.style.display='none'; Codehighlighter1_1238_1298_Closed_Image.style.display='inline'; Codehighlighter1_1238_1298_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1238_1298_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1238_1298_Closed_Text.style.display='none'; Codehighlighter1_1238_1298_Open_Image.style.display='inline'; Codehighlighter1_1238_1298_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1238_1298_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_1238_1298_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aarray[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">calc(tempstring,i);<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_i64toa(b,tempstr,</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blen&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;strlen(tempstr);<br></span><span style="COLOR: #008080">72</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempstring.assign(tempstr);<br></span><span style="COLOR: #008080">73</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">blen;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">74</span><span style="COLOR: #000000"><img id=Codehighlighter1_1449_1501_Open_Image onclick="this.style.display='none'; Codehighlighter1_1449_1501_Open_Text.style.display='none'; Codehighlighter1_1449_1501_Closed_Image.style.display='inline'; Codehighlighter1_1449_1501_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1449_1501_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1449_1501_Closed_Text.style.display='none'; Codehighlighter1_1449_1501_Open_Image.style.display='inline'; Codehighlighter1_1449_1501_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1449_1501_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_1449_1501_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">75</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;barray[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">calc(tempstring,i);<br></span><span style="COLOR: #008080">76</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">77</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">blen;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">78</span><span style="COLOR: #000000"><img id=Codehighlighter1_1543_1594_Open_Image onclick="this.style.display='none'; Codehighlighter1_1543_1594_Open_Text.style.display='none'; Codehighlighter1_1543_1594_Closed_Image.style.display='inline'; Codehighlighter1_1543_1594_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1543_1594_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1543_1594_Closed_Text.style.display='none'; Codehighlighter1_1543_1594_Open_Image.style.display='inline'; Codehighlighter1_1543_1594_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1543_1594_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_1543_1594_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">79</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;diff[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">barray[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">aarray[i];<br></span><span style="COLOR: #008080">80</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">81</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">82</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">blen;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">83</span><span style="COLOR: #000000"><img id=Codehighlighter1_1661_1697_Open_Image onclick="this.style.display='none'; Codehighlighter1_1661_1697_Open_Text.style.display='none'; Codehighlighter1_1661_1697_Closed_Image.style.display='inline'; Codehighlighter1_1661_1697_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1661_1697_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1661_1697_Closed_Text.style.display='none'; Codehighlighter1_1661_1697_Open_Image.style.display='inline'; Codehighlighter1_1661_1697_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1661_1697_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_1661_1697_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">84</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">diff[i];<br></span><span style="COLOR: #008080">85</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">86</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">87</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">add</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">88</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(aarray,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">89</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(barray,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">90</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(diff,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">91</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">92</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<p><br>&nbsp;</p>
<img src ="http://www.cppblog.com/gohan/aggbug/28736.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-07-25 08:20 <a href="http://www.cppblog.com/gohan/archive/2007/07/25/pku3286.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>今天发现vs2005fstream不能用中文路径</title><link>http://www.cppblog.com/gohan/archive/2007/06/19/26592.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Mon, 18 Jun 2007 16:19:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/06/19/26592.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/26592.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/06/19/26592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/26592.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/26592.html</trackback:ping><description><![CDATA[<p>具体解决如下<br><br>vs2005 fstream 不能打开中文路径名文件的问题!<a id=viewpost1_TitleUrl href="http://www.cppblog.com/danoyang/archive/2006/05/23/7523.html"><u><font color=#800080><strong></strong></font></u></a></p>
<p><a href="http://www.cppblog.com/danoyang/archive/2006/05/23/7523.html">http://www.cppblog.com/danoyang/archive/2006/05/23/7523.html</a></p>
<a class=postTitle2 id=viewpost1_TitleUrl href="http://www.cppblog.com/mythma/archive/2006/06/09/8349.html"><font color=#4371a6>fstream 和 中文路径</font></a> <br><a href="http://www.cppblog.com/mythma/archive/2006/06/09/8349.html">http://www.cppblog.com/mythma/archive/2006/06/09/8349.html<br></a><br><br>Trackback: <a href="http://www.cppblog.com/danoyang/services/trackbacks/7523.aspx">http://www.cppblog.com/danoyang/services/trackbacks/7523.aspx</a><br>Trackback: <a href="http://www.cppblog.com/mythma/services/trackbacks/8349.aspx">http://www.cppblog.com/mythma/services/trackbacks/8349.aspx</a><br>
<img src ="http://www.cppblog.com/gohan/aggbug/26592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-06-19 00:19 <a href="http://www.cppblog.com/gohan/archive/2007/06/19/26592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一些关于Win32 Programming的体会--读毕第6章WindowsShellProgramming</title><link>http://www.cppblog.com/gohan/archive/2007/05/27/24914.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 26 May 2007 16:50:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/05/27/24914.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/24914.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/05/27/24914.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/24914.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/24914.html</trackback:ping><description><![CDATA[<p>这章用到比较多的两个接口<br>IShellLink IPersistFile<br>两个COM接口,一个ShellLink提供对于快捷方式信息存取的方法,但是如果要载入或保存快捷方式,需要通过ShellLink Query一个IPersistFile接口,使用IPersistFile的载入保存方法.<br>贴载入与读取的这段<br></p>
<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">&nbsp;1</span><img id=Codehighlighter1_29_31_Open_Image onclick="this.style.display='none'; Codehighlighter1_29_31_Open_Text.style.display='none'; Codehighlighter1_29_31_Closed_Image.style.display='inline'; Codehighlighter1_29_31_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_29_31_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_29_31_Closed_Text.style.display='none'; Codehighlighter1_29_31_Open_Image.style.display='inline'; Codehighlighter1_29_31_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><span style="COLOR: #000000">WCHAR&nbsp;wszLnkFile[MAX_PATH]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_29_31_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_29_31_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>IShellLink</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pShellLink&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;IPersistFile</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pPF&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Create&nbsp;the&nbsp;appropriate&nbsp;COM&nbsp;server</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;HRESULT&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;CoCreateInstance(CLSID_ShellLink,&nbsp;NULL,<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLSCTX_INPROC_SERVER,&nbsp;IID_IShellLink,<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reinterpret_cast</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">LPVOID</span><span style="COLOR: #000000">*&gt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pShellLink));<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(FAILED(hr))<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;hr;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Get&nbsp;the&nbsp;IPersistFile&nbsp;interface&nbsp;to&nbsp;load&nbsp;the&nbsp;LNK&nbsp;file</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pShellLink</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">QueryInterface(IID_IPersistFile,&nbsp;reinterpret_cast</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">LPVOID</span><span style="COLOR: #000000">*&gt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pPF));<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(FAILED(hr))<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img id=Codehighlighter1_538_589_Open_Image onclick="this.style.display='none'; Codehighlighter1_538_589_Open_Text.style.display='none'; Codehighlighter1_538_589_Closed_Image.style.display='inline'; Codehighlighter1_538_589_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_538_589_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_538_589_Closed_Text.style.display='none'; Codehighlighter1_538_589_Open_Image.style.display='inline'; Codehighlighter1_538_589_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_538_589_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_538_589_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pShellLink</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;hr;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;MultiByteToWideChar(CP_ACP,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;szLnkFile,&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;wszLnkFile,&nbsp;MAX_PATH);<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pPF</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Load(wszLnkFile,&nbsp;STGM_READ);<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(FAILED(hr))<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img id=Codehighlighter1_724_797_Open_Image onclick="this.style.display='none'; Codehighlighter1_724_797_Open_Text.style.display='none'; Codehighlighter1_724_797_Closed_Image.style.display='inline'; Codehighlighter1_724_797_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_724_797_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_724_797_Closed_Text.style.display='none'; Codehighlighter1_724_797_Open_Image.style.display='inline'; Codehighlighter1_724_797_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_724_797_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_724_797_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPF</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pShellLink</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;hr;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">现在可以用pShellLink了</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">29</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pPF</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Save(wszLnkFile,&nbsp;TRUE);<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Clean&nbsp;up</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">32</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;pPF</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;pShellLink</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<p>下面这段是一个Drag的例子<br>&nbsp;WindowFromPoint(pt)感觉很强,可以获取pt点(屏幕坐标系)的窗体对象<br>DragQueryFile来分析hDrop<br>hDrop是WM_DROPFILES事件的(wParam)参数,类型为HDROP<br>一般都用reinterpret_cast转换<br></p>
<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"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;POINT&nbsp;pt;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;DragQueryPoint(hDrop,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pt);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;ClientToScreen(hDlg,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pt);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;HWND&nbsp;hwndDrop&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;WindowFromPoint(pt);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(hwndDrop&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;GetDlgItem(hDlg,&nbsp;IDC_VIEW))<br><img id=Codehighlighter1_166_259_Open_Image onclick="this.style.display='none'; Codehighlighter1_166_259_Open_Text.style.display='none'; Codehighlighter1_166_259_Closed_Image.style.display='inline'; Codehighlighter1_166_259_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_166_259_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_166_259_Closed_Text.style.display='none'; Codehighlighter1_166_259_Open_Image.style.display='inline'; Codehighlighter1_166_259_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_166_259_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_166_259_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Msg(__TEXT(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sorry,&nbsp;you&nbsp;have&nbsp;to&nbsp;drop&nbsp;over&nbsp;the&nbsp;list&nbsp;view&nbsp;control!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Now&nbsp;check&nbsp;the&nbsp;files</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;iNumOfFiles&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;DragQueryFile(hDrop,&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;NULL,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</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">0</span><span style="COLOR: #000000">&nbsp;;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;iNumOfFiles;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_388_510_Open_Image onclick="this.style.display='none'; Codehighlighter1_388_510_Open_Text.style.display='none'; Codehighlighter1_388_510_Closed_Image.style.display='inline'; Codehighlighter1_388_510_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_388_510_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_388_510_Closed_Text.style.display='none'; Codehighlighter1_388_510_Open_Image.style.display='inline'; Codehighlighter1_388_510_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_388_510_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_388_510_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_425_427_Open_Image onclick="this.style.display='none'; Codehighlighter1_425_427_Open_Text.style.display='none'; Codehighlighter1_425_427_Closed_Image.style.display='inline'; Codehighlighter1_425_427_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_425_427_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_425_427_Closed_Text.style.display='none'; Codehighlighter1_425_427_Open_Image.style.display='inline'; Codehighlighter1_425_427_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TCHAR&nbsp;szFileName[MAX_PATH]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_425_427_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_425_427_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DragQueryFile(hDrop,&nbsp;i,&nbsp;szFileName,&nbsp;MAX_PATH);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">获得了文件名,index为i的</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;DragFinish(hDrop);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/gohan/aggbug/24914.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-05-27 00:50 <a href="http://www.cppblog.com/gohan/archive/2007/05/27/24914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>这两天看书体会</title><link>http://www.cppblog.com/gohan/archive/2007/05/20/24415.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 19 May 2007 17:14:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/05/20/24415.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/24415.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/05/20/24415.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/24415.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/24415.html</trackback:ping><description><![CDATA[看 VC++Win Shell Programming<br><br>对win32 编程有点体会<br>了解了一些HIMAGELIST 这个win32结构<br>很多ImageList_XXX函数<br>还有就是IShellFolder这个接口<br>LPSHELLFOLDER <br>有很多SHXX函数用 <br><br>今天来再更新一点<br>
<h1>IShellFolder Interface 接口的成员</h1>
<hr SIZE=1>
</hr>
<p>The <strong>IShellFolder</strong> interface is used to manage folders. It is exposed by all Shell namespace folder objects.</p>
<p class=clsRef>IShellFolder Members</p>
<blockquote>
<table class=clsStd>
    <tbody>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_BindToObject_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>BindToObject</font></u></mshelp:link></td>
            <td>Retrieves an <strong>IShellFolder</strong> object for a subfolder.书上有讲</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_BindToStorage_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>BindToStorage</font></u></mshelp:link></td>
            <td>Requests a pointer to an object's storage interface.</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_CompareIDs_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>CompareIDs</font></u></mshelp:link></td>
            <td>Determines the relative order of two file objects or folders, given their item identifier lists.</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_CreateViewObject_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>CreateViewObject</font></u></mshelp:link></td>
            <td>Requests an object that can be used to obtain information from or interact with a folder object.</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_EnumObjects_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>EnumObjects</font></u></mshelp:link></td>
            <td>Allows a client to determine the contents of a folder by creating an item identifier enumeration object and returning its <mshelp:link tabIndex=0 keywords="_win32_IEnumIDList_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>IEnumIDList</font></u></mshelp:link> interface. The methods supported by that interface can then be used to enumerate the folder's contents.下面有IEnumIDList的成员</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_GetAttributesOf_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>GetAttributesOf</font></u></mshelp:link></td>
            <td>Retrieves the attributes of one or more file or folder objects contained in the object represented by <strong>IShellFolder</strong>.</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_GetDisplayNameOf_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>GetDisplayNameOf</font></u></mshelp:link></td>
            <td>Retrieves the display name for the specified file object or subfolder.<br>书上有讲</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_GetUIObjectOf_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>GetUIObjectOf</font></u></mshelp:link></td>
            <td>Retrieves an OLE interface that can be used to carry out actions on the specified file objects or folders.书上有讲</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_ParseDisplayName_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>ParseDisplayName</font></u></mshelp:link></td>
            <td>Translates a file object's or folder's display name into an item identifier list.书上有讲</td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_SetNameOf_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>SetNameOf</font></u></mshelp:link></td>
            <td>Sets the display name of a file object or subfolder, changing the item identifier in the process.</td>
        </tr>
    </tbody>
</table>
<p>&nbsp;</p>
<h1>IEnumIDList Interface</h1>
<hr SIZE=1>
</hr>
<p>The <strong>IEnumIDList</strong> interface provides a standard set of methods that can be used to enumerate the pointers to item identifier lists (PIDLs) of the items in a Shell folder. When a folder's <mshelp:link tabIndex=0 keywords="_win32_IShellFolder_win32_IShellFolder_EnumObjects_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>IShellFolder::EnumObjects</font></u></mshelp:link> method is called, it creates an enumeration object and passes a pointer to the object's <strong>IEnumIDList</strong> interface back to the caller.</p>
<p class=clsRef>IEnumIDList Members</p>
<blockquote>
<table class=clsStd>
    <tbody>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IEnumIDList_win32_IEnumIDList_Clone_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>Clone</font></u></mshelp:link></td>
            <td>Creates a new item enumeration object with the same contents and state as the current one. </td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IEnumIDList_win32_IEnumIDList_Next_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>Next</font></u></mshelp:link></td>
            <td>Retrieves the specified number of item identifiers in the enumeration sequence and advances the current position by the number of items retrieved. </td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IEnumIDList_win32_IEnumIDList_Reset_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>Reset</font></u></mshelp:link></td>
            <td>Returns to the beginning of the enumeration sequence. </td>
        </tr>
        <tr>
            <td><mshelp:link tabIndex=0 keywords="_win32_IEnumIDList_win32_IEnumIDList_Skip_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>Skip</font></u></mshelp:link></td>
            <td>Skips over the specified number of elements in the enumeration sequence. </td>
        </tr>
    </tbody>
</table>
</blockquote></blockquote>
<img src ="http://www.cppblog.com/gohan/aggbug/24415.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-05-20 01:14 <a href="http://www.cppblog.com/gohan/archive/2007/05/20/24415.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ATL初学小记</title><link>http://www.cppblog.com/gohan/archive/2007/05/16/24250.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Wed, 16 May 2007 15:03:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/05/16/24250.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/24250.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/05/16/24250.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/24250.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/24250.html</trackback:ping><description><![CDATA[<p>&nbsp;初学ATL...从头开始吧<br></p>
<br>&lt;B&gt;#include &lt;shlobj.h&gt;<br>#include &lt;comdef.h&gt;&lt;/B&gt;<br>&nbsp;<br>class ATL_NO_VTABLE CDLLRegShlExt :<br>&nbsp; public CComObjectRootEx&lt;CComSingleThreadModel&gt;,<br>&nbsp; public CComCoClass&lt;CDLLRegShlExt, &amp;CLSID_DllRegShlExt&gt;,<br>&nbsp; &lt;STRIKE&gt;public IDllRegShlExt,&lt;/STRIKE&gt;<br>&nbsp; &lt;B&gt;public IShellExtInit&lt;/B&gt;<br>{<br>&nbsp; BEGIN_COM_MAP(CDLLRegShlExt)<br>&nbsp;&nbsp;&nbsp; &lt;STRIKE&gt;COM_INTERFACE_ENTRY(IDllRegShlExt)&lt;/STRIKE&gt;<br>&nbsp;&nbsp;&nbsp; &lt;B&gt;COM_INTERFACE_ENTRY(IShellExtInit)&lt;/B&gt;<br>&nbsp; END_COM_MAP()<br><span id=Codehighlighter1_264_415_Open_Text><br><br>
<pre class=code id=ctl00_LibFrame_ctl08other space="preserve">
<pre class=code id=ctl00_LibFrame_ctl08other space="preserve">template&lt;
class ThreadModel
&gt;
class CComObjectRootEx : public CComObjectRootBase</pre>
</pre>
<br>这里CComObjectRootEx是一个ATL的类<br>我看来大概是管理Com对象的一个类,是搞计数的吧,一个实现COM的类必须要继承它的<br>它还是个模板类,模板参数是ThreadModel:<br><a onclick="javascript:Track('ctl00_LibFrame_ctl07|ctl00_LibFrame_ctl09',this);" href="http://msdn2.microsoft.com/en-us/library/42z03ek8(VS.80).aspx">CComSingleThreadModel</a>, <a onclick="javascript:Track('ctl00_LibFrame_ctl07|ctl00_LibFrame_ctl10',this);" href="http://msdn2.microsoft.com/en-us/library/w412ebfa(VS.80).aspx">CComMultiThreadModel</a>, or <a onclick="javascript:Track('ctl00_LibFrame_ctl07|ctl00_LibFrame_ctl11',this);" href="http://msdn2.microsoft.com/en-us/library/fce3e3ab(VS.80).aspx">CComMultiThreadModelNoCS</a>. You can accept the server's default thread model by setting <span class=parameter>ThreadModel</span> to <a onclick="javascript:Track('ctl00_LibFrame_ctl07|ctl00_LibFrame_ctl12',this);" href="http://msdn2.microsoft.com/en-us/library/at420k5c(VS.80).aspx">CComObjectThreadModel</a> or <a onclick="javascript:Track('ctl00_LibFrame_ctl07|ctl00_LibFrame_ctl13',this);" href="http://msdn2.microsoft.com/en-us/library/4k39yeac(VS.80).aspx">CComGlobalsThreadModel</a><br>
<p>A class that implements a COM server must inherit from <strong>CComObjectRootEx</strong> or <a onclick="javascript:Track('ctl00_LibFrame_ctl14|ctl00_LibFrame_ctl15',this);" href="http://msdn2.microsoft.com/en-us/library/a05f3yh8(VS.80).aspx">CComObjectRoot</a>. </p>
<br>
<pre class=code id=ctl00_LibFrame_ctl08other space="preserve">template&lt;
class T,
const CLSID* pclsid = &amp;CLSID_NULL
&gt;
class CComCoClass</pre>
<p>CComCoClass的类应该之前</p>
<p>&nbsp;</p>
<p><br>&nbsp;继续加一些新的东西 看MSDN Magzine 关于COM的东西,提到一些对于rgs注册脚本的使用前提<br>Way back in the November and December 1999 issues of <em>Microsoft Systems Journal</em> (now known as <em>MSDN</em><sup class=clsSmall>&#174;</sup><em>Magazine</em>), I showed how to build a Band Object for Internet Explorer using the Active Template Library (ATL) IRegistrar interface. (Band Objects need to register a special category CATID_DeskBand.) IRegistrar is a really cool tool that lets you write a registration script (.RGS file) to add your registry entries, instead of calling registry functions like RegOpenKey, RegSetValue, and the rest. <a class=clsFigs href="mk:@MSITStore:C:\Downloads\Driver\MSDNMagazine2006_10.chm::/CAtWork/default.htm#fig1"><u><font color=#800080>Figure 1</font></u></a> shows a typical script. <br><br>这一段讲IRegistrar接口的作用,hoho</p>
<pre class=code id=ctl00_LibFrame_ctl08other space="preserve">&nbsp;</pre>
</span>
<img src ="http://www.cppblog.com/gohan/aggbug/24250.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-05-16 23:03 <a href="http://www.cppblog.com/gohan/archive/2007/05/16/24250.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>结束与Winpcap的学习,有机会可以学DX</title><link>http://www.cppblog.com/gohan/archive/2007/05/14/24100.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Mon, 14 May 2007 09:01:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/05/14/24100.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/24100.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/05/14/24100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/24100.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/24100.html</trackback:ping><description><![CDATA[<p>MFC的问题就是在XP下占内存比较大,我不知道怎么优化,以后有空可以用win32 sdk完成一些事情.<br>最近在学关于FTP 协议的一些相关文档,准备在网络应用方面再学习一点.<br><a href="http://cr.yp.to/ftp.html">http://cr.yp.to/ftp.html</a><br>一个ftp协议的介绍...个人觉得很全面</p>
<img src ="http://www.cppblog.com/gohan/aggbug/24100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-05-14 17:01 <a href="http://www.cppblog.com/gohan/archive/2007/05/14/24100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>winpcap学了点</title><link>http://www.cppblog.com/gohan/archive/2007/05/05/23422.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 04 May 2007 17:19:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/05/05/23422.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/23422.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/05/05/23422.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/23422.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/23422.html</trackback:ping><description><![CDATA[东西这几天就能弄个大概了winpcap弄差不多，socket用mfc的就能弄好了。<br>mfc程序真的占用内存好多，做好这个以后决定用sdk /c 重写这个东西
<img src ="http://www.cppblog.com/gohan/aggbug/23422.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-05-05 01:19 <a href="http://www.cppblog.com/gohan/archive/2007/05/05/23422.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++的Unicode编程</title><link>http://www.cppblog.com/gohan/archive/2007/03/11/19564.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sun, 11 Mar 2007 02:16:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/03/11/19564.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/19564.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/03/11/19564.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/19564.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/19564.html</trackback:ping><description><![CDATA[
		<div align="center">
				<br />
				<table cellspacing="0" cellpadding="0" width="100%" border="0">
						<tbody>
								<tr>
										<td background="/image/dotline2.gif" height="1">
										</td>
								</tr>
						</tbody>
				</table>
				<table cellspacing="0" cellpadding="0" width="100%" border="0">
						<tbody>
								<tr>
										<td width="40" height="74"></td>
										<td valign="top" width="*" height="74">
												<form name="form2" action="/SYS/script/find.asp" method="post">
														<table cellspacing="0" cellpadding="0" width="100%" border="0">
																<tbody>
																		<tr>
																				<td>
																						<span id="docinfo">
																						</span>
																				</td>
																				<td align="right">   </td>
																		</tr>
																</tbody>
														</table>
												</form>
												<table cellspacing="0" cellpadding="0" border="0">
														<!-- MSTableType="layout" -->
														<tbody>
																<tr>
																		<td>
																				<p align="center">
																						<b>VC++的Unicode编程</b>
																						<br />来自 vckbase  我最近在使用VS2005做VC++/MFC方面的制作遇到了一些问题，这篇文章能够解决很多关于宽字符的周边。。呵呵，直接贴过来了，虽然很多贴图是VC6的<br />作者：<a href="mailto:han_yao_xu@163.com">韩耀旭</a></p>
																				<p>
																						<a href="http://www.vckbase.com/code/downcode.asp?id=3001">下载源代码</a>
																				</p>
																				<p>一、什么是Unicode</p>
																				<p>　　先从ASCII说起，ASCII是用来表示英文字符的一种编码规范。每个ASCII字符占用1个字节，因此，ASCII编码可以表示的最大字符数是255（00H—FFH）。其实，英文字符并没有那么多，一般只用前128个（00H—7FH，最高位为0），其中包括了控制字符、数字、大小写字母和其它一些符号。而最高位为1的另128个字符（80H—FFH）被称为“扩展ASCII”，一般用来存放英文的制表符、部分音标字符等等的一些其它符号。<br />　　这种字符编码规则显然用来处理英文没有什么问题。但是面对中文、阿拉伯文等复杂的文字，255个字符显然不够用。<br />于是，各个国家纷纷制定了自己的文字编码规范，其中中文的文字编码规范叫做“GB2312—80”，它是和ASCII兼容的一种编码规范，其实就是利用扩展ASCII没有真正标准化这一点，把一个中文字符用两个扩展ASCII字符来表示，以区分ASCII码部分。<br />　　但是这个方法有问题，最大的问题就是中文的文字编码和扩展ASCII码有重叠。而很多软件利用扩展ASCII码的英文制表符来画表格，这样的软件用到中文系统中，这些表格就会被误认作中文字符，出现乱码。<br />　　另外，由于各国和各地区都有自己的文字编码规则，它们互相冲突，这给各国和各地区交换信息带来了很大的麻烦。<br />要真正解决这个问题，不能从扩展ASCII的角度入手，而必须有一个全新的编码系统，这个系统要可以将中文、法文、德文……等等所有的文字统一起来考虑，为每一个文字都分配一个单独的编码。</p>
																				<p>于是，Unicode诞生了。</p>
																				<p>　　Unicode也是一种字符编码方法，它占用两个字节（0000H—FFFFH）,容纳65536个字符，这完全可以容纳全世界所有语言文字的编码。<br />在Unicode里，所有的字符被一视同仁，汉字不再使用“两个扩展ASCII”，而是使用“1个Unicode”，也就是说，所有的文字都按一个字符来处理，它们都有一个唯一的Unicode码。</p>
																				<p>二、使用Unicode编码的好处</p>
																				<p>　　使用Unicode编码可以使您的工程同时支持多种语言，使您的工程国际化。<br />　　另外，Windows NT是使用Unicode进行开发的，整个系统都是基于Unicode的。如果调用一个API函数并给它传递一个ANSI（ASCII字符集以及由此派生并兼容的字符集，如：GB2312，通常称为ANSI字符集）字符串，那么系统首先要将字符串转换成Unicode，然后将Unicode字符串传递给操作系统。如果希望函数返回ANSI字符串，系统就会首先将Unicode字符串转换成ANSI字符串，然后将结果返回给您的应用程序。进行这些字符串的转换需要占用系统的时间和内存。如果用Unicode来开发应用程序，就能够使您的应用程序更加有效地运行。<br /><br />下面例举几个字符的编码以简单演示ANSI和Unicode的区别：</p>
																				<table id="table1" width="52%" border="1">
																						<tbody>
																								<tr>
																										<td align="middle">字符</td>
																										<td align="middle"> A</td>
																										<td align="middle"> N</td>
																										<td align="middle"> 和</td>
																								</tr>
																								<tr>
																										<td align="middle">ANSI码</td>
																										<td align="middle"> 41H</td>
																										<td align="middle"> 4eH</td>
																										<td align="middle"> cdbaH</td>
																								</tr>
																								<tr>
																										<td align="middle" height="20">Unicode码</td>
																										<td align="middle" height="20"> 0041H</td>
																										<td align="middle" height="20"> 004eH</td>
																										<td align="middle" height="20"> 548cH</td>
																								</tr>
																						</tbody>
																				</table>
																				<p>三、使用C++进行Unicode编程</p>
																				<p>　　对宽字符的支持其实是ANSI C标准的一部分，用以支持多字节表示一个字符。宽字符和Unicode并不完全等同，Unicode只是宽字符的一种编码方式。</p>
																				<p>1、宽字符的定义</p>
																				<p>　　在ANSI中，一个字符（char）的长度为一个字节（Byte）。使用Unicode时，一个字符占据一个字，C++在wchar.h头文件中定义了最基本的宽字符类型wchar_t：</p>
																				<pre>typedef unsigned short wchar_t;</pre>
																				<p>从这里我们可以清楚地看到，所谓的宽字符就是无符号短整数。</p>
																				<p>2、常量宽字符串</p>
																				<p>　　对C++程序员而言，构造字符串常量是一项经常性的工作。那么，如何构造宽字符字符串常量呢？很简单，只要在字符串常量前加上一个大写的L就可以了，比如：</p>
																				<pre>wchar_t *str1=L" Hello";</pre>
																				<p>这个L非常重要，只有带上它，编译器才知道你要将字符串存成一个字符一个字。还要注意，在L和字符串之间不能有空格。</p>
																				<p>3、宽字符串库函数</p>
																				<p>为了操作宽字符串，C++专门定义了一套函数，比如求宽字符串长度的函数是</p>
																				<pre>size_t __cdel wchlen(const wchar_t*);</pre>
																				<p>　　为什么要专门定义这些函数呢？最根本的原因是，ANSI下的字符串都是以’\0’来标识字符串尾的（Unicode字符串以“\0\0”结束），许多字符串函数的正确操作均是以此为基础进行。而我们知道，在宽字符的情况下，一个字符在内存中要占据一个字的空间，这就会使操作ANSI字符的字符串函数无法正确操作。以”Hello”字符串为例，在宽字符下，它的五个字符是：<br />0x0048 0x0065 0x006c 0x006c 0x006f<br />在内存中，实际的排列是：</p>
																				<pre>48 00 65 00 6c 00 6c 00 6f 00</pre>
																				<p>　　于是，ANSI字符串函数，如strlen，在碰到第一个48后的00时，就会认为字符串到尾了，用strlen对宽字符串求长度的结果就永远会是1！</p>
																				<p>4、用宏实现对ANSI和Unicode通用的编程</p>
																				<p>　　可见，C++有一整套的数据类型和函数实现Unicode编程，也就是说，您完全可以使用C++实现Unicode编程。<br />如果我们想要我们的程序有两个版本：ANSI版本和Unicode版本。当然，编写两套代码分别实现ANSI版本和Unicode版本完全是行得通的。但是，针对ANSI字符和Unicode字符维护两套代码是非常麻烦的事情。为了减轻编程的负担，C++定义了一系列的宏，帮助您实现对ANSI和Unicode的通用编程。<br />　　C++宏实现ANSI和Unicode的通用编程的本质是根据”_UNICODE”（注意，有下划线）定义与否，这些宏展开为ANSI或Unicode字符（字符串）。</p>
																				<p>如下是tchar.h头文件中部分代码摘抄： </p>
																				<pre>#ifdef  _UNICODE
typedef wchar_t     TCHAR;
#define __T(x)      L##x
#define _T(x)       __T(x)
#else
#define __T(x)      x
typedef char            TCHAR;
#endif 
</pre>　　可见，这些宏根据”_UNICODE” 定义与否，分别展开为ANSI或Unicode字符。 tchar.h头文件中定义的宏可以分为两类： 
<p>A、实现字符和常量字符串定义的宏我们只列出两个最常用的宏： </p><table id="table2" width="52%" border="1"><tbody><tr><td align="middle" width="64">宏 </td><td align="middle">未定义_UNICODE(ANSI字符) </td><td align="middle">定义了_UNICODE(Unicode字符)</td></tr><tr><td align="middle" width="64">TCHAR</td><td align="middle"> char</td><td align="middle"> wchar_t</td></tr><tr><td align="middle" width="64" height="22">_T(x)</td><td align="middle" height="22"> x</td><td align="middle" height="22"> L##x</td></tr></tbody></table><p><b>注意：<br />　　</b>“##”是ANSI C标准的预处理语法，它叫做“粘贴符号”，表示将前面的L添加到宏参数上。也就是说，如果我们写_T(“Hello”)，展开后即为L“Hello”</p><p>B、实现字符串函数调用的宏</p><p>C++为字符串函数也定义了一系列宏，同样，我们只例举几个常用的宏：</p><table id="table3" width="56%" border="1"><tbody><tr><td align="middle" width="72">宏 </td><td align="middle">未定义_UNICODE(ANSI字符) </td><td align="middle">定义了_UNICODE(Unicode字符)</td></tr><tr><td align="middle" width="72">_tcschr</td><td align="middle"> strchr</td><td align="middle"> wcschr</td></tr><tr><td align="middle" width="72">_tcscmp</td><td align="middle"> strcmp</td><td align="middle"> wcscmp</td></tr><tr><td align="middle" width="72">_tcslen</td><td align="middle"> strlen</td><td align="middle"> wcslen</td></tr></tbody></table><p>四、使用Win32 API进行Unicode编程 
</p><p>Win32 API中定义了一些自己的字符数据类型。这些数据类型的定义在winnt.h头文件中。例如： </p><pre>typedef char CHAR; 
typedef unsigned short WCHAR;    // wc,   16-bit UNICODE character 
typedef CONST CHAR *LPCSTR, *PCSTR; 
</pre>Win32 API在winnt.h头文件中定义了一些实现字符和常量字符串的宏进行ANSI/Unicode通用编程。同样，只例举几个最常用的： <pre>#ifdef  UNICODE 
typedef WCHAR TCHAR, *PTCHAR;
typedef LPWSTR LPTCH, PTCH;
typedef LPWSTR PTSTR, LPTSTR;
typedef LPCWSTR LPCTSTR;
#define __TEXT(quote) L##quote      // r_winnt
#else   /* UNICODE */               // r_winnt
typedef char TCHAR, *PTCHAR;
typedef LPSTR LPTCH, PTCH;
typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR LPCTSTR;
#define __TEXT(quote) quote         // r_winnt
#endif /* UNICODE */                // r_winnt
</pre>　　从以上头文件可以看出，winnt.h根据是否定义了UNICODE（没有下划线），进行条件编译。<br />　　 Win32 API也定义了一套字符串函数，它们根据是否定义了“UNICODE”分别展开为ANSI和Unicode字符串函数。如：lstrlen。API的字符串操作函数和C++的操作函数可以实现相同的功能，所以，如果需要的话，建议您尽可能使用C++的字符串函数，没必要去花太多精力再去学习API的这些东西。<br />　　也许您从来没有注意到，Win32 API实际上有两个版本。一个版本接受MBCS字符串，另一个接受Unicode字符串。例如：其实根本没有SetWindowText()这个API函数，相反，有SetWindowTextA()和SetWindowTextW()。后缀A表明这是MBCS函数，后缀W表示这是Unicode版本的函数。这些API函数的头文件在winuser.h中声明，下面例举winuser.h中的SetWindowText()函数的声明部分： <pre>#ifdef UNICODE
#define SetWindowText  SetWindowTextW
#else
#define SetWindowText  SetWindowTextA
#endif // !UNICODE
</pre>　　可见，API函数根据定义UNICODE与否决定指向Unicode版本还是MBCS版本。<br />　　细心的读者可能已经注意到了UNICODE和_UNICODE的区别，前者没有下划线，专门用于Windows头文件；后者有一个前缀下划线，专门用于C运行时头文件。换句话说，也就是在ANSI C++语言里面根据_UNICODE（有下划线）定义与否，各宏分别展开为Unicode或ANSI字符，在Windows里面根据UNICODE（无下划线）定义与否，各宏分别展开为Unicode或ANSI字符。<br />　　在后面我们将会看到，实际使用中我们不加严格区分，同时定义_UNICODE和UNICODE，以实现UNICODE版本编程。 
<p>五、VC++6.0中编写Unicode编码的应用程序 </p><p>　　VC++ 6.0支持Unicode编程，但默认的是ANSI，所以开发人员只需要稍微改变一下编写代码的习惯便可以轻松编写支持UNICODE的应用程序。<br />　　使用VC++ 6.0进行Unicode编程主要做以下几项工作：</p><p>1、为工程添加UNICODE和_UNICODE预处理选项。 </p><p>　　具体步骤：打开[工程]-&gt;[设置…]对话框，如图1所示，在C/C++标签对话框的“预处理程序定义”中去除_MBCS，加上_UNICODE,UNICODE。（注意中间用逗号隔开）改动后如图2：</p><p><img height="452" src="http://www.vckbase.com/document/journal/vckbase50/images/unicodeproimg1.gif" width="676" border="0" /><br />图一</p><p><img height="454" src="http://www.vckbase.com/document/journal/vckbase50/images/unicodeproimg2.gif" width="676" border="0" /><br />图二</p><p>　　在没有定义UNICODE和_UNICODE时，所有函数和类型都默认使用ANSI的版本；在定义了UNICODE和_UNICODE之后，所有的MFC类和Windows API都变成了宽字节版本了。<br /><br />2、设置程序入口点</p><p>　　因为MFC应用程序有针对Unicode专用的程序入口点，我们要设置entry point。否则就会出现连接错误。<br />　　设置entry point的方法是：打开[工程]-&gt;[设置…]对话框，在Link页的Output类别的Entry Point里填上wWinMainCRTStartup。</p><p><img height="450" src="http://www.vckbase.com/document/journal/vckbase50/images/unicodeproimg3.gif" width="676" border="0" /><br />图三</p><p>3、使用ANSI/Unicode通用数据类型 
</p><p>　　微软提供了一些ANSI和Unicode兼容的通用数据类型，我们最常用的数据类型有_T ，TCHAR，LPTSTR,LPCTSTR。<br />　　顺便说一下，LPCTSTR和const TCHAR*是完全等同的。其中L表示long指针，这是为了兼容Windows 3.1等16位操作系统遗留下来的，在Win32 中以及其它的32位操作系统中，long指针和near指针及far修饰符都是为了兼容的作用，没有实际意义。P（pointer）表示这是一个指针；C（const）表示是一个常量；T(_T宏)表示兼容ANSI和Unicode，STR（string）表示这个变量是一个字符串。综上可以看出，LPCTSTR表示一个指向常固定地址的可以根据一些宏定义改变语义的字符串。比如： </p><pre>TCHAR* szText=_T(“Hello!”);
TCHAR szText[]=_T(“I Love You”);
LPCTSTR lpszText=_T(“大家好！”);
</pre>使用函数中的参数最好也要有变化，比如：<pre>MessageBox(_T(“你好”));</pre><p>　　其实，在上面的语句中，即使您不加_T宏，MessageBox函数也会自动把“你好”字符串进行强制转换。但我还是推荐您使用_T宏，以表示您有Unicode编码意识。 </p><p>4、修改字符串运算问题</p><p>　　一些字符串操作函数需要获取字符串的字符数(sizeof(szBuffer)/sizeof(TCHAR))，而另一些函数可能需要获取字符串的字节数sizeof(szBuffer)。您应该注意该问题并仔细分析字符串操作函数，以确定能够得到正确的结果。<br />ANSI操作函数以str开头，如strcpy()，strcat()，strlen()；<br />Unicode操作函数以wcs开头，如wcscpy，wcscpy()，wcslen()；<br />ANSI/Unicode操作函数以_tcs开头 _tcscpy(C运行期库)；<br />ANSI/Unicode操作函数以lstr开头 lstrcpy(Windows函数)；<br />考虑ANSI和Unicode的兼容，我们需要使用以_tcs开头或lstr开头的通用字符串操作函数。</p><p>六、举个Unicode编程的例子</p><p>第一步：<br />　　打开VC++6.0，新建基于对话框的工程Unicode，主对话框IDD_UNICODE_DIALOG中加入一个按钮控件，双击该控件并添加该控件的响应函数：</p><pre>void CUnicodeDlg::OnButton1() 
{
	TCHAR* str1=_T("ANSI和UNICODE编码试验");
	m_disp=str1;
	UpdateData(FALSE);
}
</pre>　　添加静态文本框IDC_DISP，使用ClassWizard给该控件添加CString类型变量m_disp。使用默认ANSI编码环境编译该工程，生成Unicode.exe。 
<p>第二步：<br />　　打开“控制面板”，单击“日期、时间、语言和区域设置”选项，在“日期、时间、语言和区域设置”窗口中继续单击“区域和语言选项”选项，弹出“区域和语言选项”对话框。在该对话框中，单击“高级”标签，将“非Unicode的程序的语言”选项改为“日语”，单击“应用”按钮，如图四：</p><p><img height="446" src="http://www.vckbase.com/document/journal/vckbase50/images/unicodeproimg4.gif" width="397" border="0" /><br />图四</p><p>弹出的对话框单击“是”，重新启动计算机使设置生效。<br />运行Unicode.exe程序并单击“Button1”按钮，看，静态文本框出现了乱码。</p><p>第三步：<br />　　改为Unicode编码环境编译该工程，生成Unicode.exe。再次运行Unicode.exe程序并单击“Button1”按钮。看到Unicode编码的优势了吧。</p><p>就说这些吧，祝您好运。<br /></p></td>
																</tr>
														</tbody>
												</table>
										</td>
								</tr>
						</tbody>
				</table>
				<br />
		</div>
		<div align="center">
				<script type="text/javascript">
						<!--
google_ad_client = "pub-4159669282587342";
google_alternate_color = "FFFFFF";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "B4D0DC";
google_color_bg = "ECF8FF";
google_color_link = "0000CC";
google_color_url = "008000";
google_color_text = "6F6F6F";
//-->
				</script>
				<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
				</script>
				<br />
				<br />
				<table class="small" height="18" cellspacing="0" cellpadding="0" width="98%" border="0">
						<tbody>
								<tr valign="center">
										<td width="47%" bgcolor="#a0d39b">
												<img height="10" src="http://www.vckbase.com/SYS/script/image/toplogo.gif" width="10" />最新评论 <a href="http://www.vckbase.com/SYS/script/viewcomment.asp?gclsid=100&amp;itemid=1733" target="_blank"><span class="small">[发表评论]</span></a><a href="http://www.vckbase.com/support/contribute.html" target="_blank"><span class="small">[文章投稿]</span></a></td>
										<td align="right" width="53%" bgcolor="#a0d39b">
												<img height="9" src="http://www.vckbase.com/document/viewdoc/image/rec1.gif" width="9" />
												<a href="http://www.vckbase.com/SYS/script/viewcomment.asp?gclsid=100&amp;itemid=1733" target="_blank">
														<span class="small">查看所有评论</span>
												</a>
												<img height="9" src="http://www.vckbase.com/document/viewdoc/image/rec1.gif" width="9" />
												<a href="http://www.vckbase.com/SYS/script/writemail.asp?gclsid=100&amp;itemid=1733&amp;title=VC%2b%2b%b5%c4Unicode%b1%e0%b3%cc" target="_blank">
														<span class="small">推荐给好友</span>
												</a>
												<img height="9" src="http://www.vckbase.com/document/viewdoc/image/rec1.gif" width="9" />
												<a href="javascript:window.print();">
														<span class="small">打印</span>
												</a>
										</td>
								</tr>
						</tbody>
				</table>
				<table class="small" cellspacing="1" cellpadding="0" width="98%" bgcolor="#ffffff" border="0">
						<tbody>
								<tr>
										<td bgcolor="#ffffff">
												<br />
												<img height="11" src="http://www.vckbase.com/document/image/doc2.gif" width="11" align="absMiddle" /> 还有那个转换函数没有说，记得有个参数是表示区域码的<br />  中文是936 日语932，记得要用，测的时候中日英下面都跑一下，不是单单改内码跑，最好是在各自语言版本的操作系统下面跑。 ( iv3ljf 发表于 2007-2-1 12:27:00)<br /> <br /><img height="11" src="http://www.vckbase.com/document/image/doc2.gif" width="11" align="absMiddle" /> 楼主说的没多大用,关键的Unicode在98下的问题没有说<br />Dll和EXE在98下使用Unicode的问题没有说<br /><br />等于没说 ( sheds 发表于 2007-1-4 20:18:00)<br /> <br /><img height="11" src="http://www.vckbase.com/document/image/doc2.gif" width="11" align="absMiddle" /> 好文章，谢谢。最近正为这个苦恼呢 ( freewind2000 发表于 2007-1-3 22:14:00)<br /> <br />.......................................................<br /><a href="http://www.vckbase.com/SYS/script/viewcomment.asp?gclsid=100&amp;itemid=1733" target="_blank"><span class="small">More...</span></a></td>
								</tr>
						</tbody>
				</table>
		</div>
		<br />
		<div align="right">
				<br />
				<span class="small">版权所有 © 2006 VC知识库  <br /><br /></span>
		</div>
<img src ="http://www.cppblog.com/gohan/aggbug/19564.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-03-11 10:16 <a href="http://www.cppblog.com/gohan/archive/2007/03/11/19564.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[一篇VC小文章]VC++制作一个最小化最小托盘的8步骤（Minimize your app to systray in 8 easy steps）翻译完</title><link>http://www.cppblog.com/gohan/archive/2007/03/06/19080.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Tue, 06 Mar 2007 11:06:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/03/06/19080.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/19080.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/03/06/19080.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/19080.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/19080.html</trackback:ping><description><![CDATA[
		<div style="FONT-WEIGHT: bold; FONT-SIZE: 16pt">Minimize your app to systray in 8 easy steps</div>
		<p>
				<b>By <a href="http://www.codeproject.com/script/Articles/list_articles.asp?userid=39987">Yasar Arslan</a></b>. From codeproject</p>
		<p>
				<img src="http://www.codeproject.com/shell/YaTrayMin/TrayMin1.gif" />
				<br />
				<br />
				<img src="http://www.codeproject.com/shell/YaTrayMin/TrayMin2.gif" />
				<br />这篇文章内容比较基础，最近看到觉得有用，顺便翻译一下<br />有空可以写一个自己的TrayIcon类，化简这些原始的操作。<br /></p>
		<h2>Introduction</h2>
		<p nd="1">这篇文章解析了 <code nd="2">Shell_NotifyIcon</code> 这个函数用法--用来建立你自己的应用程序的系统托盘图标. <br />这篇文章给了基本的缩小到托盘的操作过程并让你从中了解.<br />这篇文章提供8个简单的步骤让你成功的实现在你的程序中建立系统托盘图标. <br />源代码提供了一个基于对话框的演示程序. </p>
		<h2>Tray Icons</h2>
		<p nd="3">为了用托盘图标你需要用一个shell函数 :) </p>
		<pre nd="4">BOOL Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid );
</pre>
		<p nd="5">The <code nd="6">dwMessage</code> 可选的参数包括 the <code nd="7">NIM_ADD,NIM_DELETE and NIM_MODIFY</code>功能分别是添加删除以及修改图标于系统图标.</p>
		<p nd="9">
				<code nd="8">PNOTIFYICONDATA</code> 结构包括这些系统需要处理的任务图标状态区域消息等信息. <br /><span class="cpp-keyword">typedef</span>  <span class="cpp-keyword">struct</span> _NOTIFYICONDATA { <br />    DWORD cbSize; <br />    HWND hWnd; <br />    UINT uID; <br />    UINT uFlags; <br />    UINT uCallbackMessage; <br />    HICON hIcon; <br /><span class="cpp-preprocessor" nd="11">    #if (_WIN32_IE &lt; 0x0500)</span><br />        TCHAR szTip[<span class="cpp-literal">64</span>];<br /><span class="cpp-preprocessor" nd="12">    #else</span><br />        TCHAR szTip[<span class="cpp-literal">128</span>];<br /><span class="cpp-preprocessor" nd="13">    #endif</span><span class="cpp-preprocessor" nd="14">    #if (_WIN32_IE &gt;= 0x0500)</span><br />        DWORD dwState; <br />        DWORD dwStateMask; <br />        TCHAR szInfo[<span class="cpp-literal">256</span>]; <br />        <span class="cpp-keyword">union</span> {<br />            UINT  uTimeout; <br />            UINT  uVersion; <br />        } DUMMYUNIONNAME;<br />        TCHAR szInfoTitle[<span class="cpp-literal">64</span>]; <br />        DWORD dwInfoFlags; <br /><span class="cpp-preprocessor" nd="15">    #endif</span><span class="cpp-preprocessor" nd="16">    #if (_WIN32_IE &gt;= 0x600)</span><br />        GUID guidItem;<br /><span class="cpp-preprocessor" nd="17">    #endif</span><br />} NOTIFYICONDATA, *PNOTIFYICONDATA; <br /><br /></p>
		<p nd="18">*Note: 更完全的信息可以去参考MSDN </p>
		<h2>Creating the Application</h2>
		<p nd="19">Create a new VC++ dialog based project and call it TrayMin. <br />创建一个名叫TrayMin的基于对话框的VC++工程<br /></p>
		<p>
		</p>
		<h3>Step: 1</h3>
		<p nd="20">自定义消息于 <em>TrayMinDlg.h </em>头文件. </p>
		<pre>
				<span class="cpp-preprocessor" nd="21">#define WM_TRAY_MESSAGE (WM_USER + 1)</span>
		</pre>
		<p nd="22">The <code nd="23">WM_USER</code> 常量用来帮助用户定义自己的消息被用来建立个人的窗口类, 定义时通常用这种格式 <code nd="24">WM_USER+X</code>, 这里 X 是一个整形变量. </p>
		<p nd="25">*更详细的看MSDN </p>
		<h3>Step: 2</h3>
		<p nd="26">现在在Now add the <font face="Courier New">DECLARE_MESSAGE_MAP()</font> 之前添加下面的用户函数吧（ <i>TrayMinDlg.h</i> file）   afx_msg <span class="cpp-keyword">void</span> OnTrayNotify(WPARAM wParam, LPARAM lParam);<br />  </p>
		<p nd="29">
				<br />当添加一个图标到托盘时这有一个图标的回调消息，注意到 <code nd="31">NOTIFYICONDATA</code> 结构中有<font face="Courier New"><font size="2">uCallbackMessage</font>成员是回调消息识别的关键，它会被传给NIM_ADD（我们之后将会见到更详细的）。当添加托盘图标这个事件发生时，系统发送一个回调函数到由hWnd成员对象指定的窗口过程（winproc），wParam 参数可以用来被识别究竟发生了什么操作。lParam参数存放发生事件相关的鼠标或者键盘消息。举个例子，当一个鼠标指针指向一个托盘图标，lParam将包括WM_MOUSEMOVE</font></p>
		<p>
		</p>
		<h3>Step: 3</h3>
		<p nd="38">
				<br />现在添加下面的这行在消息宏中（MessageMap）在TrayMinDlg.cpp<br /><br />ON_MESSAGE(WM_TRAY_MESSAGE,OnTrayNotify)<br />  </p>
		<p nd="40">现在应该是这样的. </p>
		<pre nd="41">    BEGIN_MESSAGE_MAP(CTrayMinDlg, CDialog)
      <span class="cpp-comment">//{{AFX_MSG_MAP(CTrayMinDlg)</span>
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify)
      <span class="cpp-comment">//}}AFX_MSG_MAP</span>
    END_MESSAGE_MAP()

  </pre>
		<h3>Step: 4</h3>
		<p>现在在TrayMinDlg.cpp 定义OnTrayNotify函数，不要忘记在函数头部添加afx_msg。</p>
		<pre nd="45">  afx_msg <span class="cpp-keyword">void</span> CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam)
  {
    UINT uID; 
    UINT uMsg; 
 
    uID = (UINT) wParam;
    uMsg = (UINT) lParam; 
 
  
    <span class="cpp-keyword">if</span> (uID != <span class="cpp-literal">1</span>)
      <span class="cpp-keyword">return</span>;
  
    CPoint pt;  
  
  
    <span class="cpp-keyword">switch</span> (uMsg ) 
    { 

    <span class="cpp-keyword">case</span> WM_LBUTTONDOWN:
      GetCursorPos(&amp;pt);
      ClientToScreen(&amp;pt);
      OnTrayLButtonDown(pt);
      <span class="cpp-keyword">break</span>;
  
    <span class="cpp-keyword">case</span> WM_RBUTTONDOWN:
    <span class="cpp-keyword">case</span> WM_CONTEXTMENU:
      GetCursorPos(&amp;pt);
      OnTrayRButtonDown(pt);
      <span class="cpp-keyword">break</span>;

    } 
    <span class="cpp-keyword">return</span>; 
  }
  </pre>
		<h3>Step: 5</h3>
		<p nd="46">现在在TrayMinDlg类添加两个成员函数来相应鼠标事件。<br /></p>
		<p nd="48">实现鼠标左键单击的相应</p>
		<ul>
				<li nd="49">
						<code>
								<span class="cpp-keyword">函数类型：void</span>
						</code>  
</li>
				<li nd="50">
						<code nd="51">函数声明：</code> <font face="Courier New">OnTrayLButtonDown(CPoint pt)</font></li>
		</ul>
		<p nd="52">实现鼠标右键单击的相应</p>
		<ul>
				<li nd="53">函数类型: <code><span class="cpp-keyword">void</span></code></li>
				<li nd="54">函数声明: <code nd="55">OnTrayRButtonDown(CPoint pt)</code></li>
		</ul>
		<p nd="56">
				<code nd="57">OnTrayLButtonDown(CPoint pt)的定义如下</code>. </p>
		<pre nd="58">
				<span class="cpp-keyword">void</span> CTrayMinDlg::OnTrayLButtonDown(CPoint pt)
    {  
      MessageBox(<span class="cpp-string" nd="59">"You have clicked Left mouse Button "</span>);
    }
  </pre>
		<p nd="60">The Declaration of <code nd="61">OnTrayRButtonDown(CPoint pt)</code> is as following. </p>
		<pre nd="62">
				<span class="cpp-keyword">void</span> CTrayMinDlg::OnTrayRButtonDown(CPoint pt)
    {  
      <span class="cpp-comment">//m_menu is the member of CTrayMinDlg as CMenu m_menu;</span>
      m_menu.GetSubMenu(<span class="cpp-literal">0</span>)-&gt;TrackPopupMenu(TPM_BOTTOMALIGN|
       TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,<span class="cpp-keyword">this</span>);      
    }
  </pre>
		<h3>Step: 6</h3>
		<p nd="63">Add two member variable to the <code nd="64">CTrayMinDlg</code>.<br />为CTrayMinDlg添加两个成员变量</p>
		<ul>
				<li nd="65">Variable Type: <code nd="66">NOTIFYICONDATA</code></li>
				<li nd="67">Variable Name: <code nd="68">m_TrayData</code>; 
</li>
				<li nd="69">Variable Type: <code nd="70">CMenu</code></li>
				<li nd="71">Variable Name: <code nd="72">m_menu</code>; </li>
		</ul>
		<p nd="73">
				<br />现在添加菜单资源<br /></p>
		<p>
		</p>
		<h3>Step: 7 <br /></h3>现在画一个最小化的按钮在对话框设计中<br />并且添加这个按钮的执行函数<br /><pre id="pre9" style="MARGIN-TOP: 0px" nd="76"><span class="cpp-keyword">void</span> CShellDlg::OnMinimize() 
  {
    m_TrayData.cbSize = <span class="cpp-keyword">sizeof</span>(NOTIFYICONDATA);
    <span class="cpp-comment">//Size of this structure, in bytes. </span>
    
    
    m_TrayData.hWnd  = <span class="cpp-keyword">this</span>-&gt;m_hWnd;
    <span class="cpp-comment">//Handle to the window that receives notification </span><span class="cpp-comment">//messages associated with an icon in the taskbar </span><span class="cpp-comment">//status area. The Shell uses hWnd and uID to </span><span class="cpp-comment">//identify which icon to operate on when </span><span class="cpp-comment">//Shell_NotifyIcon is invoked. </span>
  
    m_TrayData.uID = <span class="cpp-literal">1</span>;
    <span class="cpp-comment">//Application-defined identifier of the taskbar icon.</span><span class="cpp-comment">//The Shell uses hWnd and uID to identify which icon </span><span class="cpp-comment">//to operate on when Shell_NotifyIcon is invoked. You</span><span class="cpp-comment">// can have multiple icons associated with a single </span><span class="cpp-comment">//hWnd by assigning each a different uID. </span>

    m_TrayData.uCallbackMessage  = WM_TRAY_MESSAGE;
    <span class="cpp-comment">//Application-defined message identifier. The system </span><span class="cpp-comment">//uses this identifier to send notifications to the </span><span class="cpp-comment">//window identified in hWnd. These notifications are </span><span class="cpp-comment">//sent when a mouse event occurs in the bounding </span><span class="cpp-comment">//rectangle of the icon, or when the icon is selected </span><span class="cpp-comment">//or activated with the keyboard. The wParam parameter </span><span class="cpp-comment">//of the message contains the identifier of the taskbar </span><span class="cpp-comment">//icon in which the event occurred. The lParam parameter </span><span class="cpp-comment">//holds the mouse or keyboard message associated with the</span><span class="cpp-comment">// event. For example, when the pointer moves over a </span><span class="cpp-comment">//taskbar icon, lParam is set to WM_MOUSEMOVE. </span>
    


    m_TrayData.hIcon = <span class="cpp-keyword">this</span>-&gt;m_hIcon;
    <span class="cpp-comment">//Handle to the icon to be added, modified, or deleted</span>
    
    strcpy(m_TrayData.szTip,<span class="cpp-string" nd="77">"My Icon"</span>);
    <span class="cpp-comment">//Pointer to a null-terminated string with the text </span><span class="cpp-comment">//for a standard ToolTip. It can have a maximum of 64 </span><span class="cpp-comment">//characters including the terminating NULL. </span>
    
    
    m_TrayData.uFlags = NIF_ICON|NIF_MESSAGE;
    <span class="cpp-comment">//Flags that indicate which of the other members contain </span>
    valid data.  
  

    BOOL bSuccess = FALSE;
    BOOL BSus = FALSE;

    BSus = m_menu.LoadMenu(IDR_MENU1);
    <span class="cpp-keyword">if</span>(!(BSus))
      MessageBox(<span class="cpp-string" nd="78">"Unabled to Loa menu"</span>);

    bSuccess = Shell_NotifyIcon(NIM_ADD,&amp;m_TrayData);

    <span class="cpp-keyword">if</span>(!(bSuccess))
      MessageBox(<span class="cpp-string" nd="79">"Unable to Set Tary Icon"</span>);
    <span class="cpp-keyword">else</span>
    {
      <span class="cpp-keyword">this</span>-&gt;ShowWindow(SW_MINIMIZE);
      <span class="cpp-keyword">this</span>-&gt;ShowWindow(SW_HIDE);

    }
  }
  
  </pre><p></p><h3>Step: 8</h3><p nd="80"><br />在退出菜单的执行函数写下如下<br /><br />Shell_NotifyIcon(NIM_DELETE,&amp;m_TrayData);<br />  DestroyWindow();<br /></p><p nd="82"><br />现在可以运行程序，并且尝试最小化按钮的使用（他会最小化导系统托盘）。<br />现在尽情发挥，完善这些步骤，完成自己的系统托盘图标吧！<br /></p><!-- Article Ends --><script src="/script/togglePre.js" type="text/javascript"></script><h2>Yasar Arslan</h2><img src ="http://www.cppblog.com/gohan/aggbug/19080.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-03-06 19:06 <a href="http://www.cppblog.com/gohan/archive/2007/03/06/19080.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>翻译一篇文章Introduction to Multi-threaded Code 多线程编程的一些代码 已经全译好了</title><link>http://www.cppblog.com/gohan/archive/2007/02/16/18822.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 16 Feb 2007 06:06:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/02/16/18822.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/18822.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/02/16/18822.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/18822.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/18822.html</trackback:ping><description><![CDATA[
		<p nd="1">Someone recently asked me what I recommend for synchronizing worker threads and I suggested setting an event. This person's response was that you could not do that since worker threads do not support a message pump (UI threads are required to support messages). The confusion here is that events and messages are different animals under windows. </p>
		<p nd="2">我忘记了我从哪里copy的这些例子代码，他们可是非常简单而有趣的。如果有人知道这些代码的作者，我一定要好好感谢你和这位作者。<br /><br />注意这里有很多对于没有提及的MFC的支持。像_beginthread（一个C运行时库调用）的API可以在MFC应用程序中替换成AfxBeginThread</p>
		<h2>无同步（No Synchronization）</h2>
		<p nd="4">这第一个例子描述了两个互不同步的线程。进程中的首要线程--主函数循环，输出全局整形数组的内容。还有一个线程“Thread”不停的给数组每个元素+1。<br /> The thread called "Thread" continuously populates the global array of integers.</p>
		<pre nd="7">
				<span class="cpp-preprocessor" nd="5">  #include &lt;process.h&gt;</span>
				<span class="cpp-preprocessor" nd="6">  #include &lt;stdio.h&gt;</span>
				<span class="cpp-keyword">int</span> a[ <span class="cpp-literal">5</span> ];
  
  <span class="cpp-keyword">void</span> Thread( <span class="cpp-keyword">void</span>* pParams )
  { <span class="cpp-keyword">int</span> i, num = <span class="cpp-literal">0</span>;
  
    <span class="cpp-keyword">while</span> ( <span class="cpp-literal">1</span> )
    { 
       <span class="cpp-keyword">for</span> ( i = <span class="cpp-literal">0</span>; i &lt; <span class="cpp-literal">5</span>; i++ ) a[ i ] = num;
       num++;
    }
  }
  
  <span class="cpp-keyword">int</span> main( <span class="cpp-keyword">void</span> )
  { 
     _beginthread( Thread, <span class="cpp-literal">0</span>, NULL );
  
     <span class="cpp-keyword">while</span>( <span class="cpp-literal">1</span> )
        printf(<span class="cpp-string" nd="8">"%d %d %d %d %d\n"</span>, 
               a[ <span class="cpp-literal">0</span> ], a[ <span class="cpp-literal">1</span> ], a[ <span class="cpp-literal">2</span> ],
               a[ <span class="cpp-literal">3</span> ], a[ <span class="cpp-literal">4</span> ] );
  
   <span class="cpp-keyword">return</span><span class="cpp-literal">0</span>;
  }
</pre>
		<p nd="9">注意这个例子的输出，红色的数处在一个主线程抢先于Thread工作过程中执行的打印动作<br /></p>
		<p align="center" nd="10">81751652 <font color="#ff0000" nd="11">81751652</font> 81751651 81751651 81751651<br />81751652 <font color="#ff0000" nd="12">81751652</font> 81751651 81751651 81751651<br />83348630 83348630 <font color="#ff0000" nd="13">83348630</font> 83348629 83348629<br />83348630 83348630 <font color="#ff0000" nd="14">83348630</font> 83348629 83348629<br />83348630 83348630 <font color="#ff0000" nd="15">83348630</font> 83348629 83348629</p>
		<p nd="16"> </p>
		<h2>关键区域/临界区域 对象（Critical Section Objects）</h2>
		<p nd="17">如果你想让主线程等待Thread线程处理好全局数组再做打印，一种解决方法是使用关键区域对象。<br /><em>关键区域</em>对象提供同步于使用互斥器（Mutex）对象很相似, 除了关键区域对象之能在一个进程内发挥效用。Event, mutex, 以及 semaphore 对象也可以用在单进程的应用程序中, 但是关键区域对象提供一个相对快捷更加高效的同步机制. 就像互斥器一样, 一个关键区域对象只能同时被一个线程拥有, 这个关键区域能够在同时发生的数据存取时保护共享资源. 获取关键区域的先后顺序不定，可是不用太担心，系统对于每一个线程都是平等的。</p>
		<pre nd="22">     
  CRITICAL_SECTION cs;
  <span class="cpp-keyword">int</span> a[ <span class="cpp-literal">5</span> ];
  
  <span class="cpp-keyword">void</span> Thread( <span class="cpp-keyword">void</span>* pParams )
  {
    <span class="cpp-keyword">int</span> i, num = <span class="cpp-literal">0</span>;
  
    <span class="cpp-keyword">while</span> ( TRUE )
    {
       EnterCriticalSection( &amp;cs );
       <span class="cpp-keyword">for</span> ( i = <span class="cpp-literal">0</span>; i &lt; <span class="cpp-literal">5</span>; i++ ) a[ i ] = num;
       LeaveCriticalSection( &amp;cs );
       num++;
    }
  }
  
  <span class="cpp-keyword">int</span> main( <span class="cpp-keyword">void</span> )<br />
  { 
    InitializeCriticalSection( &amp;cs );
    _beginthread( Thread, <span class="cpp-literal">0</span>, NULL );
  
    <span class="cpp-keyword">while</span>( TRUE )
    {
       EnterCriticalSection( &amp;cs );
       printf( <span class="cpp-string" nd="23">"%d %d %d %d %d\n"</span>, 
               a[ <span class="cpp-literal">0</span> ], a[ <span class="cpp-literal">1</span> ], a[ <span class="cpp-literal">2</span> ],
               a[ <span class="cpp-literal">3</span> ], a[ <span class="cpp-literal">4</span> ] );
       LeaveCriticalSection( &amp;cs );
    }
    <span class="cpp-keyword">return </span><span class="cpp-literal">0</span>;
  }
</pre>
		<p nd="24">If you are running Windows 9x/NT/2000, you can run this program by clicking <a href="http://www.codeproject.com/threads/Sync/Sync2.zip">here</a>. </p>
		<h2>互斥器（Mutex Objects）</h2>
		<p nd="25">一个互斥器是一个信号状态的同步对象，当它不属于任何一个线程时就用信号来体现，当被拥有时他的信号状态就为None. 同一时刻只有一个线程可以拥有互斥器, 互斥器这个名字来自于他们对于并列的线程存取共享资源时表现出的行为。举个例子,避免两个线程同时写入一个共享内存，每一个线程当需要执行存取共享资源的代码时首先等待直到自己获得拥有权. 在存取共享资源之后，线程释放对互斥器的拥有权。</p>
		<p nd="26">两个或以上的进程可以调用<code nd="27">CreateMutex</code> 来建立同样名字的互斥器. 实际上第一个进程建立的这个互斥器, 随后的进程只是得到了那个存在的互斥器的句柄. 这能使多进程共用一个互斥器, 当然用户应该有确保建立互斥器的进程首先启动的责任. 使用这种技术,你应该将这个 <em>bInitialOwner</em>标记设置成FALSE; 否则, 它可以因不同的进程最初拥有它而带来困难. </p>
		<p nd="28">多进程可以有同一个mutex对象的句柄, 让mutex对象能够用于多进程间同步. 下面的对象共享机制是适用的: </p>
		<ul>
				<li nd="29">一个子进程通过<code nd="30">CreateProcess</code> 函数被建立，当<font face="Courier New">CreateMutex的</font><em>lpMutexAttributes</em> 参数给予相应的mutex对象指针它可以继承到一个mutex对象的句柄. 
</li>
				<li nd="32">一个进程可以在<code nd="33">DuplicateHandle</code> 函数中指定一个mutex对象句柄来建立一个句柄的拷贝由其他进程使用. 
</li>
				<li nd="34">一个继承可以指定一个mutex的名字通过 <code nd="36">CreateMutex</code> 函数得到这个mutex对象的句柄. </li>
		</ul>
		<p nd="37">总的来说, 如果你想要进行线程同步，临界区域更高效些.</p>
		<pre nd="41">
				<span class="cpp-preprocessor" nd="38">#include &lt;windows.h&gt;</span>
				<span class="cpp-preprocessor" nd="39">#include &lt;process.h&gt;</span>
				<span class="cpp-preprocessor" nd="40">#include &lt;stdio.h&gt;</span>
  
  HANDLE hMutex;
  <span class="cpp-keyword">int</span> a[ <span class="cpp-literal">5</span> ];
  
  <span class="cpp-keyword">void</span> Thread( <span class="cpp-keyword">void</span>* pParams )
  { 
     <span class="cpp-keyword">int</span> i, num = <span class="cpp-literal">0</span>;
  
     <span class="cpp-keyword">while</span> ( TRUE )
     { 
        WaitForSingleObject( hMutex, INFINITE );
        <span class="cpp-keyword">for</span> ( i = <span class="cpp-literal">0</span>; i &lt; <span class="cpp-literal">5</span>; i++ ) a[ i ] = num;
        ReleaseMutex( hMutex );
        num++;
     }
  }
  
  <span class="cpp-keyword">int</span> main( <span class="cpp-keyword">void</span> )
  {
     hMutex = CreateMutex( NULL, FALSE, NULL );
     _beginthread( Thread, <span class="cpp-literal">0</span>, NULL );
  
     <span class="cpp-keyword">while</span>( TRUE )<br />
     {
        WaitForSingleObject( hMutex, INFINITE );
        printf( "%d %d %d %d %d\n", 
                a[ <span class="cpp-literal">0</span> ], a[ <span class="cpp-literal">1</span> ], a[ <span class="cpp-literal">2</span> ],
                a[ <span class="cpp-literal">3</span> ], a[ <span class="cpp-literal">4</span> ] );
        ReleaseMutex( hMutex );
     }
     <span class="cpp-keyword">return</span><span class="cpp-literal">0</span>;
  }</pre>
		<p nd="42">If you are running Windows 9x/NT/2000, you can run this program by clicking <a href="http://www.codeproject.com/threads/Sync/Sync3.zip">here</a>. </p>
		<h2>Event Objects事件对象</h2>
		<p nd="43">若我们想要强制第二线程在主线程完成全局数组的内容输出时执行该如何？这样的话每行的输出就只是递增1。</p>
		<p nd="44">一个事件对象也是一个可以通过<font face="Courier New" size="2">SetEvent</font> or <code nd="46">PulseEvent</code> 函数设置像信号般的状态的同步对象. 下面是两种类型的事件对象. </p>
		<table cellspacing="4" cols="2">
				<tbody>
						<tr valign="top">
								<th align="left" width="129" nd="47">Object</th>
								<th align="left" width="336" nd="48">Description</th>
						</tr>
						<tr valign="top">
								<td width="129" nd="49">Manual-reset event<br />手动激发对象</td>
								<td width="336" nd="50">只有使用<code nd="51">ResetEvent</code> 函数才可以将其设置为无激发状态. 当它在激发状态时, 它会激发所有正在等待的线程, 执行对相同 event对象的线程会立即从wait函数返回.</td>
						</tr>
						<tr valign="top">
								<td width="129" nd="52">Auto-reset event<br />自动激发对象</td>
								<td width="336" nd="53">一个只相应一个线程的wait函数的事件对象（当这个对象是激发状态），wait函数返回同时事件对象自动变成无激发状态 ，当没有线程执行wait事件对象仍然是激发状态.</td>
						</tr>
				</tbody>
		</table>
		<p nd="54">event object的用处就在于它可以在它发生时向等待着的线程发出信号标志从而使其wait结束. 举个例子, 在overlapped I/O 操作时, 当异步操作完成时系统设置了那个由程序员指定（specified）的事件对象为信号状态. A 一个单一线程可以指定许多不同的事件对象在许多同时发生的overlapped 操作运作, 调用一个多对象的wait函数可以当任意一个event object激发时结束等待. </p>
		<p nd="55">在一个线程中可使用 <code nd="56">CreateEvent</code> 函数建立一个event object. 在这个线程中指定这个event object 的特性是manual-reset 或者 auto-reset . 在这个线程中也可以命名一个event object. 其他进程中的线程也可以使用 <code nd="57">OpenEvent</code> 通过event object的名字打开一个现存event object . 另外关于mutex, event, semaphore, 以及 timer objects的其他信息, 就参考《Interprocess Synchronization》的文章.</p>
		<p nd="58">一个线程能够用 <code nd="59">PulseEvent</code> 函数设置一个event object 为信号状态而后激发当前适当数量的wait线程，之后切换为无信号状态 . 对于一个manual-reset event object, 所有的等待线程被返回（release）. 对于一个auto-reset event object, 这个函数只能释放一个等待的线程, 即使有更多线程在等待. 如果没有线程在函数调用时等待, <code nd="60">PulseEvent</code> 只是简单的将事件状态设为无信号并且返回（个人注释，这应该是跟setevent最不相同的地方！）.</p>
		<div class="precollapse" id="premain3" style="WIDTH: 100%">
				<img id="preimg3" style="CURSOR: hand" height="9" src="http://www.codeproject.com/images/minus.gif" width="9" preid="3" />
				<span id="precollapse3" style="MARGIN-BOTTOM: 0px; CURSOR: hand" nd="61" preid="3">Collapse</span>
		</div>
		<pre id="pre3" style="MARGIN-TOP: 0px" nd="65">
				<span class="cpp-preprocessor" nd="62">  #include &lt;windows.h&gt;</span>
				<span class="cpp-preprocessor" nd="63">  #include &lt;process.h&gt;</span>
				<span class="cpp-preprocessor" nd="64">  #include &lt;stdio.h&gt;</span>
  
  HANDLE hEvent1, hEvent2;
  <span class="cpp-keyword">int</span> a[ <span class="cpp-literal">5</span> ];
  
  <span class="cpp-keyword">void</span> Thread( <span class="cpp-keyword">void</span>* pParams )
  {
     <span class="cpp-keyword">int</span> i, num = <span class="cpp-literal">0</span>;

     <span class="cpp-keyword">while</span> ( TRUE )
     {
        WaitForSingleObject( hEvent2, INFINITE );
        <span class="cpp-keyword">for</span> ( i = <span class="cpp-literal">0</span>; i &lt; <span class="cpp-literal">5</span>; i++ ) a[ i ] = num;
        SetEvent( hEvent1 );
        num++;
     }
  }
  
  <span class="cpp-keyword">int</span> main( <span class="cpp-keyword">void</span> )
  {
     hEvent1 = CreateEvent( NULL, FALSE, TRUE, NULL );
     hEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL );
  
     _beginthread( Thread, <span class="cpp-literal">0</span>, NULL );
  
     <span class="cpp-keyword">while</span>( TRUE )
     { 
        WaitForSingleObject( hEvent1, INFINITE );
        printf( <span class="cpp-string" nd="66">"%d %d %d %d %d\n"</span>, 
                a[ <span class="cpp-literal">0</span> ], a[ <span class="cpp-literal">1</span> ], a[ <span class="cpp-literal">2</span> ],
                a[ <span class="cpp-literal">3</span> ], a[ <span class="cpp-literal">4</span> ] );
        SetEvent( hEvent2 );
     }
     <span class="cpp-keyword">return</span><span class="cpp-literal">0</span>;
  }
</pre>
		<p nd="67">If you are running Windows 9x/NT/2000, you can run this program by clicking <a href="http://www.codeproject.com/threads/Sync/Sync4.zip">here</a>. </p>
		<h2>Summary of Synchronization Objects</h2>
		<p nd="68">The MSDN News for July/August 1998 has a front page article on Synchronization Objects. The following table is from that article:</p>
		<div align="left">
				<table cellspacing="5" border="0">
						<tbody>
								<tr>
										<td>
												<strong>Name</strong>
										</td>
										<td align="middle">
												<strong>Relative speed</strong>
										</td>
										<td align="middle">
												<strong>Cross process</strong>
										</td>
										<td align="middle">
												<strong>Resource counting</strong>
										</td>
										<td align="middle">
												<strong>Supported platforms</strong>
										</td>
								</tr>
								<tr>
										<td nd="69">Critical Section</td>
										<td align="middle" nd="70">Fast</td>
										<td align="middle" nd="71">No</td>
										<td align="middle" nd="72">No (exclusive access)</td>
										<td align="middle" nd="73">9x/NT/CE</td>
								</tr>
								<tr>
										<td nd="74">Mutex</td>
										<td align="middle" nd="75">Slow</td>
										<td align="middle" nd="76">Yes</td>
										<td align="middle" nd="77">No (exclusive access)</td>
										<td align="middle" nd="78">9x/NT/CE</td>
								</tr>
								<tr>
										<td nd="79">Semaphore</td>
										<td align="middle" nd="80">Slow</td>
										<td align="middle" nd="81">Yes</td>
										<td align="middle" nd="82">Automatic</td>
										<td align="middle" nd="83">9x/NT</td>
								</tr>
								<tr>
										<td nd="84">Event</td>
										<td align="middle" nd="85">Slow</td>
										<td align="middle" nd="86">Yes</td>
										<td align="middle" nd="87">Yes</td>
										<td align="middle" nd="88">9x/NT/CE</td>
								</tr>
								<tr>
										<td nd="89">Metered Section</td>
										<td align="middle" nd="90">Fast</td>
										<td align="middle" nd="91">Yes</td>
										<td align="middle" nd="92">Automatic</td>
										<td align="middle" nd="93">9x/NT/CE</td>
								</tr>
						</tbody>
				</table>
				<!-- Article Ends -->
		</div>
		<script src="/script/togglePre.js" type="text/javascript">
		</script>
		<h2>by William T. Block</h2>
		<p>
				<br />from codeproject<br /><br />谢谢回复的补充 ~~，上面拼错了个词，改过。。译完了</p>
<img src ="http://www.cppblog.com/gohan/aggbug/18822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-02-16 14:06 <a href="http://www.cppblog.com/gohan/archive/2007/02/16/18822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>These days work..</title><link>http://www.cppblog.com/gohan/archive/2007/02/06/18491.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Tue, 06 Feb 2007 13:56:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/02/06/18491.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/18491.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/02/06/18491.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/18491.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/18491.html</trackback:ping><description><![CDATA[玩太阁立志传比较堕落。。。<br />这两天学做了几个Win Socket几个demo，有点心得，在win32做网络编程基本了解，现在想知道怎么能做一个支持断点续传的下载软件。<br />那几个计划还在酝酿。<br />电子制作还是一无所知。。<br /><br />hostent *hp;<br />sockaddr_in server;<br /><br />下面这句话还是太生猛<br />server.sin_addr.s_addr=*((ULONG *)hp-&gt;h_addr);<br /><br />容我再学深入一点再说<img src ="http://www.cppblog.com/gohan/aggbug/18491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-02-06 21:56 <a href="http://www.cppblog.com/gohan/archive/2007/02/06/18491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>zju 1004 Anagrams by Stack 我的很不规范的程序</title><link>http://www.cppblog.com/gohan/archive/2006/09/04/12005.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Mon, 04 Sep 2006 03:39:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/09/04/12005.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/12005.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/09/04/12005.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/12005.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/12005.html</trackback:ping><description><![CDATA[
		<p>#include &lt;iostream&gt;<br />#include &lt;string&gt;<br />using namespace std;</p>
		<p>string stack,requare,start,newStr;<br />string table;<br />int num=0,i=0;<br />void check(string&amp; start,string&amp; stack);<br />void print(){<br />  if(newStr==requare)<br />  cout&lt;&lt;table&lt;&lt;endl;<br />}<br />void pushStack(char item,string&amp; start,string&amp; stack){<br /> table+='i';<br /> stack+=item;<br /> check(start,stack);</p>
		<p>}<br />void popStack(string&amp; start,string&amp; stack){<br /> table+='o';<br /> newStr+=stack[stack.size()-1];<br /> stack.erase(stack.size()-1);<br /> check(start,stack);<br />}<br />void delPush(){<br />  table.erase(table.size()-1);<br />  stack.erase(stack.size()-1);</p>
		<p>}<br />void delPop(){<br />  stack+=newStr[newStr.size()-1];<br />  table.erase(table.size()-1);<br />  newStr.erase(newStr.size()-1);<br />}</p>
		<p>void check(string&amp; start,string&amp; stack){<br /> if (num==start.size()*2) {<br />  print(); <br />  return;<br /> }<br />  <br />  <br />    if((newStr.size()+stack.size())!=start.size()){<br />    num++;<br />    pushStack(start[i++],start,stack);<br />    delPush();<br />    num--;<br />    i--;<br />    }<br />    if(stack.empty()&amp;&amp;i&lt;start.size()) return;<br />    num++;<br />    popStack(start,stack);<br />    delPop();<br />    num--;<br /> <br />  <br />}</p>
		<p>
				<br />int main(){</p>
		<p>
				<br /> cin&gt;&gt;start&gt;&gt;requare;</p>
		<p> check(start,stack);<br /> return 0;<br />}</p>
		<p> </p>
		<p>很不规范的地柜，还有好多个清理状态的函数。。。<br />什么时候才能改进阿！！！！！！！！</p>
<img src ="http://www.cppblog.com/gohan/aggbug/12005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-09-04 11:39 <a href="http://www.cppblog.com/gohan/archive/2006/09/04/12005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Win32 Console Applications - Part 4 of 6 from adrianxw.dk</title><link>http://www.cppblog.com/gohan/archive/2006/07/20/10279.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 20 Jul 2006 14:54:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/07/20/10279.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/10279.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/07/20/10279.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/10279.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/10279.html</trackback:ping><description><![CDATA[
		<h1>Win32 Console Applications - Part 4. </h1>
		<p>So far all of the console output I have shown have been in black and white. This part of the tutorial demonstrates how I did this! </p>
		<center>
				<img height="176" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Dannebrog.jpg" width="257" />
		</center>
		<p>Now, before you start getting all excited, let me say from the start, the range of colours available is not huge. You may want to compile and run these programs for yourself, the .jpg's I use on the web site show up fine on the monitor connected to the machine I am using now, but when viewed on my older machine, appear very dark and fuzzy. 
</p>
		<p>
		</p>
		<p>We will use the Win32 API function SetConsoleTextAttribute(). This function takes 2 arguments. The first is the standard output handle, we have covered that already. The second is a 16bit WORD bit mask containg 0 or more bits. </p>
		<p>It is not necessary to concern yourself over the values of the various bits. There are a series of constants defined in windows.h, (actually in wincon.h but that is included in windows.h), which symbolically allow you to build the required value, it is very easy. Look at this program and it's output. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED);
    cout &lt;&lt; "This text is red." &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN);
    cout &lt;&lt; "This text is green." &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE);
    cout &lt;&lt; "This text is blue." &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="104" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour1.jpg" width="265" />
		</center>
		<p>A dingy red green and blue. Being bits, they can be OR'd together to make combinations, the next program shows the result of OR'ing the bits together. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN);
    cout &lt;&lt; "This text is yellow." &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE);
    cout &lt;&lt; "This text is cyan." &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE | 
                            FOREGROUND_RED);
    cout &lt;&lt; "This text is magenta." &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE);
    cout &lt;&lt; "This text is white." &lt;&lt; endl;

    return 0;
}

</pre>
		<center>
				<img height="116" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour2.jpg" width="257" />
		</center>
		<p>The bitwise OR operator "|" combines the requested bits. Thus red | green gives yellow, green | blue gives cyan, blue | red gives magenta and all three combined gives white. The order is unimportant, red | blue gives the same result as blue | red. </p>
		<p>Another bit that can be OR'd in is FOREGROUND_INTENSITY. All the colours I've shown so far are a bit dim, adding the intensity bit brightens them up. This program shows the use and results of the intensity bit. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED);
    cout &lt;&lt; "Red     " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Red" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN);
    cout &lt;&lt; "Green   " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Green" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE);
    cout &lt;&lt; "Blue    " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Blue" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN);
    cout &lt;&lt; "Yellow  " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Yellow" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE);
    cout &lt;&lt; "Cyan    " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Cyan" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE | 
                            FOREGROUND_RED);
    cout &lt;&lt; "Magenta " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_BLUE | 
                            FOREGROUND_RED |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Magenta" &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE);
    cout &lt;&lt; "White   " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            FOREGROUND_RED | 
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "White" &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="152" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour3.jpg" width="241" />
		</center>
		<p>Black is also a colour, and is made by having no foreground colors set, no red and no green and no blue is nothing, is black. So in all we have 15 colours. I did warn you not to get excited. </p>
		<p>In addition to changing the foreground colour, we can also change the background colour. The same colours are available. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED);
    cout &lt;&lt; "Red     " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Red     " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN);
    cout &lt;&lt; "Green   " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Green   " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_BLUE);
    cout &lt;&lt; "Blue    " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_BLUE |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Blue    " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED | 
                            BACKGROUND_GREEN);
    cout &lt;&lt; "Yellow  " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED | 
                            BACKGROUND_GREEN |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Yellow  " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN | 
                            BACKGROUND_BLUE);
    cout &lt;&lt; "Cyan    " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN | 
                            BACKGROUND_BLUE |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Cyan    " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_BLUE | 
                            BACKGROUND_RED);
    cout &lt;&lt; "Magenta " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_BLUE | 
                            BACKGROUND_RED |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "Magenta " &lt;&lt; endl;

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED | 
                            BACKGROUND_GREEN | 
                            BACKGROUND_BLUE);
    cout &lt;&lt; "White   " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_RED | 
                            BACKGROUND_GREEN | 
                            BACKGROUND_BLUE |
                            BACKGROUND_INTENSITY);
    cout &lt;&lt; "White   " &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="152" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour4.jpg" width="241" />
		</center>
		<p>A space character will just show up as the coloured background. That is how I made the Danish flag at the top of this section. </p>
		<p>It is possible to set both the foreground and background colours, here for example, I set the background to low intensity yellow and the foreground to high intensity cyan. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN |
                            BACKGROUND_RED |
                            FOREGROUND_GREEN | 
                            FOREGROUND_BLUE |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Intense Cyan on yellow background." &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="80" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour5.jpg" width="313" />
		</center>
		<p>You can use any combination you like of the available colours, although obviously, setting the foreground and background colour to the same value is a little pointless. Remember also, that setting no foreground bits gives black text, and no background bits, a black background. </p>
		<p>A common "gotcha" is forgetting that both the foreground AND background must be set at each call. If you want to write first in green then in red on a yellow background you must set the background in both calls, otherwise the function assumes you want to return to a black background. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN |
                            BACKGROUND_RED |
                            FOREGROUND_GREEN | 
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Green " &lt;&lt; flush;
    SetConsoleTextAttribute(hOut,
                            BACKGROUND_GREEN |
                            BACKGROUND_RED |
                            FOREGROUND_RED |
                            FOREGROUND_INTENSITY);
    cout &lt;&lt; "Red" &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="80" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour6.jpg" width="241" />
		</center>
		<p>If you are going to do a lot of colour changes, rather than OR'ing everything together each time, you may prefer to do it once using a #define. Here, I #define FRI to be Foreground Red Intense, BC to be Background Cyan, FW to Foreground White and BNULL to Background "Nothing" i.e. black. Using these in a small test program does not really make much difference, but in large programs with many colour changes, the code can be much shorter using this technique. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

#define FRI FOREGROUND_RED |\
            FOREGROUND_INTENSITY
#define FW  FOREGROUND_RED |\
            FOREGROUND_GREEN |\
            FOREGROUND_BLUE
#define BC  BACKGROUND_GREEN |\
            BACKGROUND_BLUE
#define BNULL 0

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    cout &lt;&lt; "Normal " &lt;&lt; flush;

    SetConsoleTextAttribute(hOut,
                            FRI | BC);

    cout &lt;&lt;"coloured" &lt;&lt; flush;

    SetConsoleTextAttribute(hOut,
                            FW | BNULL);

    cout &lt;&lt; " and back." &lt;&lt; endl;

    return 0;
}
</pre>
		<center>
				<img height="80" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour7.jpg" width="241" />
		</center>
		<p>Note the backslashes in the #defines, this is necessary when extending a #define onto more than one line. You don't have to do this of course if you are happy with long lines/horizontal scrolling. Finally, in this section, here is a header file that contains a full set of #defines. To use it, copy the code and paste it into a file with a .h extension, say "ShortColours.h" for example. Put a copy of this file into the same directory as your code file, and include it into your program like this. </p>
		<pre>#include "ShortColours.h"
</pre>
		<p>Enclosing the header file name in quotes rather than a less than/greater than pair tells the compiler to look in the same directory as the code. </p>
		<pre>#ifndef SHORTCOLOURS_H
#define SHORTCOLOURS_H

#define FW FOREGROUND_RED | \
           FOREGROUND_GREEN | \
           FOREGROUND_BLUE
#define FR FOREGROUND_RED
#define FG FOREGROUND_GREEN
#define FB FOREGROUND_BLUE
#define FY FOREGROUND_RED | \
           FOREGROUND_GREEN
#define FC FOREGROUND_GREEN | \
           FOREGROUND_BLUE
#define FM FOREGROUND_BLUE | \
           FOREGROUND_RED 
#define FWI FOREGROUND_RED | \
            FOREGROUND_GREEN | \
            FOREGROUND_BLUE | \
            FOREGROUND_INTENSITY
#define FRI FOREGROUND_RED | \
            FOREGROUND_INTENSITY
#define FGI FOREGROUND_GREEN | \
            FOREGROUND_INTENSITY
#define FBI FOREGROUND_BLUE | \
            FOREGROUND_INTENSITY
#define FYI FOREGROUND_RED | \
            FOREGROUND_GREEN | \
            FOREGROUND_INTENSITY
#define FCI FOREGROUND_GREEN | \
            FOREGROUND_BLUE | \
            FOREGROUND_INTENSITY
#define FMI FOREGROUND_BLUE | \
            FOREGROUND_RED | \
            FOREGROUND_INTENSITY 
#define FNULL 0
 
#define BW BACKGROUND_RED | \
           BACKGROUND_GREEN | \
           BACKGROUND_BLUE
#define BR BACKGROUND_RED
#define BG BACKGROUND_GREEN
#define BB BACKGROUND_BLUE
#define BY BACKGROUND_RED | \
           BACKGROUND_GREEN
#define BC BACKGROUND_GREEN | \
           BACKGROUND_BLUE
#define BM BACKGROUND_BLUE | \
           BACKGROUND_RED 
#define BWI BACKGROUND_RED | \
            BACKGROUND_GREEN | \
            BACKGROUND_BLUE | \
            BACKGROUND_INTENSITY
#define BRI BACKGROUND_RED | \
            BACKGROUND_INTENSITY
#define BGI BACKGROUND_GREEN | \
            BACKGROUND_INTENSITY
#define BBI BACKGROUND_BLUE | \
            BACKGROUND_INTENSITY
#define BYI BACKGROUND_RED | \
            BACKGROUND_GREEN | \
            BACKGROUND_INTENSITY
#define BCI BACKGROUND_GREEN | \
            BACKGROUND_BLUE | \
            BACKGROUND_INTENSITY
#define BMI BACKGROUND_BLUE | \
            BACKGROUND_RED | \
            BACKGROUND_INTENSITY 
#define BNULL 0

#endif
</pre>
		<p>This program produces the same output as the last. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include "ShortColours.h"
using namespace std;

int main()
{
    HANDLE hOut;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    cout &lt;&lt; "Normal " &lt;&lt; flush;

    SetConsoleTextAttribute(hOut,
                            FRI | BC);

    cout &lt;&lt;"coloured" &lt;&lt; flush;

    SetConsoleTextAttribute(hOut,
                            FW | BNULL);

    cout &lt;&lt; " and back." &lt;&lt; endl;

    return 0;
}
</pre>
		<p>The colour support is not great, but at the end of the day, it can be good enough. Consider, there are probably many of you that have played, or at least seen "BattleChess", where the pieces animated battle when one captured another. I bet nobody played it for long, because after you've seen the animations, they simply slow the game down, and the AI behind the graphics was actually not very good. </p>
		<p>You build a really good chess playing AI and put it behind a simple interface like this, people will use it over and over, because, <i>it is good enough to get the job done.</i></p>
		<center>
				<img height="380" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Colour8.jpg" width="392" />
				<br />
				<br />
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>In part 2 of the tutorial, I showed you how to use ReadConsoleOutputCharacter() to retrieve the characters at one or more screen buffer locations. By itself, it is not capable of recovering the foreground and background attributes those characters were written with. This information is also available, the API routine used is ReadConsoleOutputAttribute(), and is really very similar to ReadConsoleOutputCharacter(). The prototype is shown here. </p>
		<pre>BOOL ReadConsoleOutputAttribute(
  HANDLE hConsoleOutput,
  LPWORD lpAttribute,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfAttrsRead
);
</pre>
		<p>This program sets the foreground colout to FOREGROUND_GREEN | FOREGROUND_RED and outputs a string. It then uses ReadConsoleOutputAttribute() to retrieve the attribute of the character at (4,0). The result is 6, this is because FOREGROUND_GREEN is defined to have the value 0x0002 and FOREGROUND_RED 0x0004. 2+4=6. It may be tempting to use the numerical values rather than the defined constants, but this is not a good idea. At some time in the future, MicroSoft may change the values associated with the constants, (unlikely, but a reserved possibility). Using the constants, the code will still work, use the values and the results may be unpredictable. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;

int main()
{
    HANDLE hOut;
    WORD Attribute;
    COORD Where;
    unsigned long NumRead;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hOut,
                            FOREGROUND_GREEN | 
                            FOREGROUND_RED);

    cout &lt;&lt; "This text is yellow." &lt;&lt; endl;

    Where.X = 4;
    Where.Y = 0;
    ReadConsoleOutputAttribute(hOut,
                               &amp;Attribute,
                               1,
                               Where,
                               &amp;NumRead);

    cout &lt;&lt; "Attribute is " &lt;&lt; Attribute &lt;&lt; endl;

    return 0;
}
</pre>
		<p>The output looks like this. </p>
		<center>
				<img height="104" alt="ReadConsoleOutputAttribute" src="http://www.adrianxw.dk/SoftwareSite/Consoles/ReadConsoleOutputAttribute.jpg" width="265" />
		</center>
		<p>In the next part of the tutorial, we'll investigate keyboard and mouse events. </p>
<img src ="http://www.cppblog.com/gohan/aggbug/10279.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-07-20 22:54 <a href="http://www.cppblog.com/gohan/archive/2006/07/20/10279.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Win32 Console Applications - Part 3 of 6 form adrianxw.dk</title><link>http://www.cppblog.com/gohan/archive/2006/07/20/10277.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 20 Jul 2006 14:49:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/07/20/10277.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/10277.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/07/20/10277.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/10277.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/10277.html</trackback:ping><description><![CDATA[
		<h1>Win32 Console Applications - Part 3. </h1>
		<p>I recommend you compile and run this program. It will display the printable characters available to your console. If your console is a different size from mine, you may need to adjust the values for x and y, but this should be trivial. The rest of the tutorial assumes your character map is the same as mine - it should be, but it is possible if you have a different language set loaded into your system the positions of some of these characters may be different, run this, check them and modify the values used later accordingly, (frankly, I've worked with several language settings and never seen the character map to be different, but I'm told it is possible!). </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    int i;
    int x = 0;
    int y = 0;
    COORD Position;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    for (i=32; i&lt;=255; i++)
    {
        Position.X = x;
        Position.Y = y;
        SetConsoleCursorPosition(hOut,
                                 Position);

        cout.width(3);
        cout &lt;&lt; i &lt;&lt; " " &lt;&lt; (unsigned char)i &lt;&lt; flush;

        ++y;
        if(y &gt; 20)
        {
            y = 0;
            x += 6;
        }
    }

    Position.X = 0;
    Position.Y = 22;
    SetConsoleCursorPosition(hOut,
                             Position);
    return 0;
}
</pre>
		<p>Of particular interest to this part of the tutorial are the values between 179 and 218. Shown below is the relevent part of the output from the program. </p>
		<center>
				<img height="259" alt="Char Map" src="http://www.adrianxw.dk/SoftwareSite/Consoles/CharMap.gif" width="101" />
		</center>
		<p>If you remember part 1 of this tutorial, I said the "normal" characters in the console font filled a 7x11 grid in a larger 8x12 character cell which had the top and row and right column blank to allow for spacing. As you can see from the picture above, these are not normal characters, some have already merged with those above and below them to give some strange glyphs that look like a cross between sanskrit and klingon! Here is the same character range more spread out and easier to see. </p>
		<center>
				<img height="262" alt="Char Map2" src="http://www.adrianxw.dk/SoftwareSite/Consoles/CharMap2.gif" width="245" />
		</center>
		<p>Unlike the normal alpha-numerics, (0-9, A-Z, a-z), and puntuation characters, where space between the individual characters is important for clarity, these characters do not have space above and to the right, they run all the way to the edge of their character cell and are designed to be merged. With these characters one can draw lines, boxes and grids. Have a look at this program output for some idea of what you can do. </p>
		<center>
				<img height="212" alt="Boxes" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Boxes.JPG" width="265" />
		</center>
		<p>The figures look a little stupid when drawn this size, but I have done this to keep the size of the image files down, so they load faster, you can make them any size, and if you inspect the character map, you will see that these are not the only possibilities. </p>
		<p>To draw these examples, I wrote a very crude function which draws a character at a specified location on the screen, it is shown here. </p>
		<pre>void At(int x, int y, unsigned char What)
{
    static HANDLE hOut;
    static bool First = TRUE;
    COORD Position;

    if(First)
    {
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        First = FALSE;
    }

    Position.X = x;
    Position.Y = y;
    
    SetConsoleCursorPosition(hOut,
                             Position);
    
    cout &lt;&lt; What &lt;&lt; flush;

    return;
}
</pre>
		<p>As you can see, there is no error or range checking, it simply assumes you know what you are doing. The function retrieves the standard output handle and stores it statically the first time the it is invoked. </p>
		<p>This code snippet shows the calls necessary to draw the first box. </p>
		<pre>    At(9, 0, (unsigned char) 218);
    At(10, 0, (unsigned char) 196);
    At(11, 0, (unsigned char) 191);
    At(9, 1, (unsigned char) 179);
    At(10, 1, (unsigned char) 32);
    At(11, 1, (unsigned char) 179);
    At(9, 2, (unsigned char) 192);
    At(10, 2, (unsigned char) 196);
    At(11, 2, (unsigned char) 217);
</pre>
		<p>Given the character table above and this simple example, (32 is the space character by the way), you should have enough information to create all kinds of boxes, grids, mazes, forms etc. The very playable adventure game "Caverns of Moria" known to many VAX/VMS and UNIX users had a user interface that could easily be copied using these simple graphics. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>Whilst drawing boxes or at any time it becomes appropriate, you may want to hide or modify the appearance of the cursor. You can do this with another API routine, SetConsoleCursorInfo(). This takes 2 parameters, the standard output handle, and a pointer to a CONSOLE_CURSOR_INFO structure. This is another relatively simple Windows defined structure. It is looks like this. </p>
		<pre>typedef struct _CONSOLE_CURSOR_INFO {
    DWORD  dwSize; 
    BOOL   bVisible; 
} CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO; 
</pre>
		<p>The first value is a simple integer in the range 1-100, it specifies how much of the character cell the cursor occupies is filled. The program here sets the cursor size to 50. The 3 pictures below show the sizes 1, 50 and 100, you can, of course, use any integer in the range. Note the use of the "&amp;" in front of the ConCurInf, remember, the routine expects a <i>pointer</i> to the structure you have declared. </p>
		<pre>#include &lt;windows.h&gt;

int main()
{
    HANDLE hOut;
    CONSOLE_CURSOR_INFO ConCurInf;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTitle("Size 50");

    ConCurInf.dwSize = 50;
    ConCurInf.bVisible = TRUE;

    SetConsoleCursorInfo(hOut,
                         &amp;ConCurInf);

    return 0;
}
</pre>
		<center>
				<img height="80" alt="Cursor1" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Cursor1.jpg" width="265" />
				<br />
				<br />
				<img height="80" alt="Cursor50" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Cursor50.jpg" width="265" />
				<br />
				<br />
				<img height="80" alt="Cursor100" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Cursor100.jpg" width="265" />
		</center>
		<p>The other value is a boolean field and indicates whether the cursor is visible or not. A value of TRUE, (the default), means the cursor is visible, FALSE and it is invisible. The followng program turns the cursor off. </p>
		<pre>#include &lt;windows.h&gt;

int main()
{
    HANDLE hOut;
    CONSOLE_CURSOR_INFO ConCurInf;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTitle("No Cursor");

    ConCurInf.dwSize = 10;
    ConCurInf.bVisible = FALSE;

    SetConsoleCursorInfo(hOut,
                         &amp;ConCurInf);

    return 0;
}
</pre>
		<center>
				<img height="80" alt="CursorOff" src="http://www.adrianxw.dk/SoftwareSite/Consoles/CursorOff.jpg" width="265" />
		</center>
		<p>To turn the cursor back on, call the function again with the bVisible member set TRUE. </p>
		<p>It is a good idea to set up both values, especially the first time you call the function. If you set up bVisible but leave dwSize uninitialised, the unspecified value may be zeroed, or contain a random value, in either case, it could be out of the range 1-100, and the routine will fail. Similaly, if you want to change the size of the cursor, and don't set bVisible to be TRUE, your compiler may have zeroed the uninitialised field and the cursor will disappear instead of changing size. As always, if you check the return value of the call, you will see if any errors have happened along the way. </p>
		<p>Remember, the cursor is there to show where the character insertion point is. Setting the cursor to invisible does not change that. Remember also, the cursor is very useful, it shows your user "where they are" on your screen, if you take it away, you must be sure you have other means available that enable your user to navigate the screen. </p>
		<p>In the next part of this tutorial, we'll explore the colour issues. </p>
<img src ="http://www.cppblog.com/gohan/aggbug/10277.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-07-20 22:49 <a href="http://www.cppblog.com/gohan/archive/2006/07/20/10277.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[基础]Win32 Console Applications - Part 2 of 6 from adrianxw.dk</title><link>http://www.cppblog.com/gohan/archive/2006/07/20/10276.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 20 Jul 2006 14:46:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/07/20/10276.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/10276.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/07/20/10276.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/10276.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/10276.html</trackback:ping><description><![CDATA[
		<h1>Win32 Console Applications - Part 2. </h1>
		<p>I started part 1 of this tutorial by showing the classic "Hello Worlrd!" program. The output looked like this. </p>
		<center>
				<img height="92" alt="Hello World" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Hello%20World.jpg" width="513" />
		</center>
		<p>By default, Windows places the path of the executable in the window title. You can change this to a word or phrase of your choice. Here is the Hello World! program modified to do this. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    SetConsoleTitle("Hello!");
    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
    return 0;
}
</pre>
		<p>Notice I've now added the windows.h header to the program, and a call to SetConsoleTitle(). The output now looks like this. </p>
		<center>
				<img height="92" alt="Hello World" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Console%20Name.jpg" width="249" />
		</center>
		<p>Later on, we'll see that knowing the name of your window can be useful, and setting it yourself is, of course, an easy way of knowing it! </p>
		<p>As an aside, almost all of the API routines return a status indicating success or failure. For clarity of the example code in these tutorials, I am not checking this value. To be more professional, you should check the return values of API routines you call. Even if you cannot recover from the error, it is often useful in debugging to know what routine failed, and if possible, why. This program shows the checking of the return status and aborts the program if the routine fails, (note the inclusion of process.h for the exit() API routine). You should refer to your compiler's help or <a href="http://msdn.microsoft.com/library/default.asp">MSDN</a> to see what the return values of a routine are. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;process.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    int Status;

    Status = SetConsoleTitle("Hello!");
    if (Status == 0)
    {
        Status = GetLastError();
        cout &lt;&lt; "SetConsoleTitle() failed! Reason : " &lt;&lt; Status &lt;&lt; endl;
        exit(Status);
    }

    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
    return 0;
}
</pre>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>All consoles have 3 "standard handles" and many of the console handling functions require a "handle" to perform I/O. </p>
		<p>A "handle" is simply a 32 bit integer. It is the way Windows differentiates between objects of the same type. Consider the console, it has a title bar, minimize, maximize and close buttons, one or more scroll bars, etc. It is, when you think about it, quite a complicated thing, and somewhere there must be a lot of data that the system is using to make it all work. Windows hides all of that complexity from you, you can play with all this data if you want to of course, but the point here is, <i>you don't <b>have</b> to</i> if you don't want to. Windows looks after it all for you, and all you have to do is tell it the handle of whatever it is you want to use. Once you get into full Windows programming, you'll find a lot of things are used by supplying a "handle". If you don't understand right now, don't worry about it, a handle is easy to get, and easy to use. </p>
		<p>To get the standard handles, declare variable of type HANDLE and initialise them with a call to GetStdHandle(). This program, (which doesn't actually do anything!), illustrates the process. We'll use the standard handles later. 
</p>
		<p>
		</p>
		<pre>#include &lt;windows.h&gt;

int main()
{
    HANDLE hIn;
    HANDLE hOut;
    HANDLE hError;

    hIn = GetStdHandle(STD_INPUT_HANDLE);
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    hError = GetStdHandle(STD_ERROR_HANDLE);

    return 0;
}
</pre>
		<p>The standard input handle is used with routines that read data from a console, the standard output handle with routines that send data to a console. The standard error handle also outputs to the console by default, and frankly is not used very much, just be aware of it. </p>
		<p>There are a couple of routines ReadConsole() and WriteConsole() that perform I/O using these handles, but for now at least, we'll continue with the standard C++ I/O functions. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>Now we've got the handles, lets do something with them, let's move the cursor around. To do this we'll need to use a COORD structure. This is a very simple structure containing an x and y coordinate. It is declared like this. </p>
		<pre>typedef struct _COORD {
    SHORT X;
    SHORT Y;
} COORD; 
</pre>
		<p>To move the cursor, you simply set up the COORD to the coordinates you want the cursor moved to and call the SetConsoleCursorPosition() API function. Here is a simple program which does just that. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    int i;
    COORD Position;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    for(i=0; i&lt;10; i+=2)
    {
        Position.X = i;
        Position.Y = i;
        SetConsoleCursorPosition(hOut,
                                 Position);
        cout &lt;&lt; "*" &lt;&lt; flush;
    }

    return 0;
}
</pre>
		<p>The output looks like this. </p>
		<center>
				<img height="176" alt="Move Cursor" src="http://www.adrianxw.dk/SoftwareSite/Consoles/MoveCursor.jpg" width="361" />
		</center>
		<p>As you see, each iteration of the loop moves the cursor two rows down and two columns right. To return the cursor to the "home" position, (top left corner), send it to (0,0). Creative use of this function can give pleasing effects. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>The next routine I want to show you is FillConsoleOutputCharacter(). This routine allows you to write a whole load of characters to the console in one go. The function prototype is shown here. </p>
		<pre>BOOL FillConsoleOutputCharacter(
  HANDLE hConsoleOutput,
  TCHAR cCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten
);
</pre>
		<p>A bit more complicated then any of the routines we've used so far, but really very easy to use. The first parameter is the handle to the output buffer, you know how to get that. The next is the character you want to write, easy enough. The next, is how many times you want it to write the character out, still easy. Next is a COORD telling it where to start, we've already covered that. Finally, the routine wants a place where it can tell you how many characters it actually wrote, this has to be therefore, the address of a variable in your program. You may be wondering why this argument is there at all, but consider the situation where your screen buffer is, for example, 5000 characters long. If you tell the routine to output 5100, it will not error, it will fill the 5000 characters, and then tell you that it did that by setting the value accordingly. If you're not interested, ignore it, but you must supply a place for the routine to use, in this case, I've passed the address of the "Written" variable like this &amp;Written. </p>
		<p>This program uses FillConsoleOutputCharacter() to draw a line of 15 "X" characters starting at (4,4), the unsuprising output of the program is also shown below. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    COORD Position;
    DWORD Written;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    Position.X = 4;
    Position.Y = 4;

    FillConsoleOutputCharacter(hOut,
                               'X',
                               15,
                               Position,
                               &amp;Written);

    return 0;
}
</pre>
		<center>
				<img height="116" alt="Fill Console" src="http://www.adrianxw.dk/SoftwareSite/Consoles/FillConsole1.jpg" width="289" />
		</center>
		<p>See what happens if I change the call to output 150 instead of 15 characters, (I've shrunk the picture to make it load faster - changing the call did not change the screen resolution!!!). </p>
		<center>
				<img height="166" alt="Fill Console" src="http://www.adrianxw.dk/SoftwareSite/Consoles/FillConsole2.jpg" width="332" />
		</center>
		<p>The point to note is that when the routine reached the end of the line, it continued at the beginning of the line below. Suppose, instead of line 5 column 5 I'd said (0,0), and suppose I'd used a space character instead of an 'X', and suppose I'd told it to draw enough characters to completely fill the screen buffer - hey - I've cleared the screen! Clearing the screen is <b>THE</b> most common console related question that comes up in the forums, there's the answer. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>It is also possible to read one or more characters from a specific position in the screen buffer. To do that, we use the ReadConsoleOutputCharacter() API routine. This routine has very similar parameters to the last, it's prototype is shown here. </p>
		<pre>BOOL ReadConsoleOutputCharacter(
  HANDLE hConsoleOutput,
  LPTSTR lpCharacter,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfCharsRead 
);
</pre>
		<p>As before, the first is the standard handle. Next, remember, we are reading now, so the routine wants somewhere to write the information to, so it needs a pointer to a place where it can store characters. The rest of the parameters are as before, the number of characters to process, the start point, and a pointer to a place it can write the actual number read. </p>
		<p>This program uses the routine twice, once to retrieve the single character at the (0,0) position, and a second time to retrieve 5 characters starting from position (4,0). If the number of characters requested is longer than the current line, reading continues from the first character of the line below as before. Again, as before, if the number requested is more than there are in the buffer, the characters up to the end of the buffer are returned, the actual number appearing in the final parameter. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    char Letter;
    char Letters[5];
    COORD Where;
    DWORD NumRead;
    int i;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    cout &lt;&lt; "A line of little consequence." &lt;&lt; endl;

    Where.X = 0;
    Where.Y = 0;
    ReadConsoleOutputCharacter(hOut,
                               &amp;Letter,
                               1,
                               Where,
                               &amp;NumRead);
    cout &lt;&lt; "Letter at (0,0) is " &lt;&lt; Letter &lt;&lt; endl;

    Where.X = 4;
    ReadConsoleOutputCharacter(hOut,
                               Letters,
                               5,
                               Where,
                               &amp;NumRead);
    cout &lt;&lt; "5 letters starting from (4,0) ";
    for (i=0; i&lt;5; i++)
    {
        cout &lt;&lt; Letters[i];
    }
    cout &lt;&lt; endl;

    return 0;
}
</pre>
		<p>The output from the program looks like this. </p>
		<center>
				<img height="104" alt="ReadConsoleOutputCharacter" src="http://www.adrianxw.dk/SoftwareSite/Consoles/ReadConsoleOutputCharacter.jpg" width="329" />
		</center>
		<p>It would have been quite permissable to dimension the Letters array to 6, read the 5 characters from the console then manually set the final character to NULL. In that way, the cout could have taken the name of the string, (as it is now NULL terminated), instead of writing the characters out individually in a loop. </p>
		<p>In the next part of the tutorial, we'll look at the limited graphical capabilities of consoles, drawing lines, boxes and grids. </p>
		<h1>Win32 Console Applications - Part 2. </h1>
		<p>I started part 1 of this tutorial by showing the classic "Hello Worlrd!" program. The output looked like this. </p>
		<center>
				<img height="92" alt="Hello World" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Hello%20World.jpg" width="513" />
		</center>
		<p>By default, Windows places the path of the executable in the window title. You can change this to a word or phrase of your choice. Here is the Hello World! program modified to do this. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    SetConsoleTitle("Hello!");
    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
    return 0;
}
</pre>
		<p>Notice I've now added the windows.h header to the program, and a call to SetConsoleTitle(). The output now looks like this. </p>
		<center>
				<img height="92" alt="Hello World" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Console%20Name.jpg" width="249" />
		</center>
		<p>Later on, we'll see that knowing the name of your window can be useful, and setting it yourself is, of course, an easy way of knowing it! </p>
		<p>As an aside, almost all of the API routines return a status indicating success or failure. For clarity of the example code in these tutorials, I am not checking this value. To be more professional, you should check the return values of API routines you call. Even if you cannot recover from the error, it is often useful in debugging to know what routine failed, and if possible, why. This program shows the checking of the return status and aborts the program if the routine fails, (note the inclusion of process.h for the exit() API routine). You should refer to your compiler's help or <a href="http://msdn.microsoft.com/library/default.asp">MSDN</a> to see what the return values of a routine are. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;process.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    int Status;

    Status = SetConsoleTitle("Hello!");
    if (Status == 0)
    {
        Status = GetLastError();
        cout &lt;&lt; "SetConsoleTitle() failed! Reason : " &lt;&lt; Status &lt;&lt; endl;
        exit(Status);
    }

    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
    return 0;
}
</pre>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>All consoles have 3 "standard handles" and many of the console handling functions require a "handle" to perform I/O. </p>
		<p>A "handle" is simply a 32 bit integer. It is the way Windows differentiates between objects of the same type. Consider the console, it has a title bar, minimize, maximize and close buttons, one or more scroll bars, etc. It is, when you think about it, quite a complicated thing, and somewhere there must be a lot of data that the system is using to make it all work. Windows hides all of that complexity from you, you can play with all this data if you want to of course, but the point here is, <i>you don't <b>have</b> to</i> if you don't want to. Windows looks after it all for you, and all you have to do is tell it the handle of whatever it is you want to use. Once you get into full Windows programming, you'll find a lot of things are used by supplying a "handle". If you don't understand right now, don't worry about it, a handle is easy to get, and easy to use. </p>
		<p>To get the standard handles, declare variable of type HANDLE and initialise them with a call to GetStdHandle(). This program, (which doesn't actually do anything!), illustrates the process. We'll use the standard handles later. 
</p>
		<p>
		</p>
		<pre>#include &lt;windows.h&gt;

int main()
{
    HANDLE hIn;
    HANDLE hOut;
    HANDLE hError;

    hIn = GetStdHandle(STD_INPUT_HANDLE);
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    hError = GetStdHandle(STD_ERROR_HANDLE);

    return 0;
}
</pre>
		<p>The standard input handle is used with routines that read data from a console, the standard output handle with routines that send data to a console. The standard error handle also outputs to the console by default, and frankly is not used very much, just be aware of it. </p>
		<p>There are a couple of routines ReadConsole() and WriteConsole() that perform I/O using these handles, but for now at least, we'll continue with the standard C++ I/O functions. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>Now we've got the handles, lets do something with them, let's move the cursor around. To do this we'll need to use a COORD structure. This is a very simple structure containing an x and y coordinate. It is declared like this. </p>
		<pre>typedef struct _COORD {
    SHORT X;
    SHORT Y;
} COORD; 
</pre>
		<p>To move the cursor, you simply set up the COORD to the coordinates you want the cursor moved to and call the SetConsoleCursorPosition() API function. Here is a simple program which does just that. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    int i;
    COORD Position;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    for(i=0; i&lt;10; i+=2)
    {
        Position.X = i;
        Position.Y = i;
        SetConsoleCursorPosition(hOut,
                                 Position);
        cout &lt;&lt; "*" &lt;&lt; flush;
    }

    return 0;
}
</pre>
		<p>The output looks like this. </p>
		<center>
				<img height="176" alt="Move Cursor" src="http://www.adrianxw.dk/SoftwareSite/Consoles/MoveCursor.jpg" width="361" />
		</center>
		<p>As you see, each iteration of the loop moves the cursor two rows down and two columns right. To return the cursor to the "home" position, (top left corner), send it to (0,0). Creative use of this function can give pleasing effects. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>The next routine I want to show you is FillConsoleOutputCharacter(). This routine allows you to write a whole load of characters to the console in one go. The function prototype is shown here. </p>
		<pre>BOOL FillConsoleOutputCharacter(
  HANDLE hConsoleOutput,
  TCHAR cCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten
);
</pre>
		<p>A bit more complicated then any of the routines we've used so far, but really very easy to use. The first parameter is the handle to the output buffer, you know how to get that. The next is the character you want to write, easy enough. The next, is how many times you want it to write the character out, still easy. Next is a COORD telling it where to start, we've already covered that. Finally, the routine wants a place where it can tell you how many characters it actually wrote, this has to be therefore, the address of a variable in your program. You may be wondering why this argument is there at all, but consider the situation where your screen buffer is, for example, 5000 characters long. If you tell the routine to output 5100, it will not error, it will fill the 5000 characters, and then tell you that it did that by setting the value accordingly. If you're not interested, ignore it, but you must supply a place for the routine to use, in this case, I've passed the address of the "Written" variable like this &amp;Written. </p>
		<p>This program uses FillConsoleOutputCharacter() to draw a line of 15 "X" characters starting at (4,4), the unsuprising output of the program is also shown below. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    COORD Position;
    DWORD Written;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    Position.X = 4;
    Position.Y = 4;

    FillConsoleOutputCharacter(hOut,
                               'X',
                               15,
                               Position,
                               &amp;Written);

    return 0;
}
</pre>
		<center>
				<img height="116" alt="Fill Console" src="http://www.adrianxw.dk/SoftwareSite/Consoles/FillConsole1.jpg" width="289" />
		</center>
		<p>See what happens if I change the call to output 150 instead of 15 characters, (I've shrunk the picture to make it load faster - changing the call did not change the screen resolution!!!). </p>
		<center>
				<img height="166" alt="Fill Console" src="http://www.adrianxw.dk/SoftwareSite/Consoles/FillConsole2.jpg" width="332" />
		</center>
		<p>The point to note is that when the routine reached the end of the line, it continued at the beginning of the line below. Suppose, instead of line 5 column 5 I'd said (0,0), and suppose I'd used a space character instead of an 'X', and suppose I'd told it to draw enough characters to completely fill the screen buffer - hey - I've cleared the screen! Clearing the screen is <b>THE</b> most common console related question that comes up in the forums, there's the answer. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>It is also possible to read one or more characters from a specific position in the screen buffer. To do that, we use the ReadConsoleOutputCharacter() API routine. This routine has very similar parameters to the last, it's prototype is shown here. </p>
		<pre>BOOL ReadConsoleOutputCharacter(
  HANDLE hConsoleOutput,
  LPTSTR lpCharacter,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfCharsRead 
);
</pre>
		<p>As before, the first is the standard handle. Next, remember, we are reading now, so the routine wants somewhere to write the information to, so it needs a pointer to a place where it can store characters. The rest of the parameters are as before, the number of characters to process, the start point, and a pointer to a place it can write the actual number read. </p>
		<p>This program uses the routine twice, once to retrieve the single character at the (0,0) position, and a second time to retrieve 5 characters starting from position (4,0). If the number of characters requested is longer than the current line, reading continues from the first character of the line below as before. Again, as before, if the number requested is more than there are in the buffer, the characters up to the end of the buffer are returned, the actual number appearing in the final parameter. </p>
		<pre>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
    HANDLE hOut;
    char Letter;
    char Letters[5];
    COORD Where;
    DWORD NumRead;
    int i;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    cout &lt;&lt; "A line of little consequence." &lt;&lt; endl;

    Where.X = 0;
    Where.Y = 0;
    ReadConsoleOutputCharacter(hOut,
                               &amp;Letter,
                               1,
                               Where,
                               &amp;NumRead);
    cout &lt;&lt; "Letter at (0,0) is " &lt;&lt; Letter &lt;&lt; endl;

    Where.X = 4;
    ReadConsoleOutputCharacter(hOut,
                               Letters,
                               5,
                               Where,
                               &amp;NumRead);
    cout &lt;&lt; "5 letters starting from (4,0) ";
    for (i=0; i&lt;5; i++)
    {
        cout &lt;&lt; Letters[i];
    }
    cout &lt;&lt; endl;

    return 0;
}
</pre>
		<p>The output from the program looks like this. </p>
		<center>
				<img height="104" alt="ReadConsoleOutputCharacter" src="http://www.adrianxw.dk/SoftwareSite/Consoles/ReadConsoleOutputCharacter.jpg" width="329" />
		</center>
		<p>It would have been quite permissable to dimension the Letters array to 6, read the 5 characters from the console then manually set the final character to NULL. In that way, the cout could have taken the name of the string, (as it is now NULL terminated), instead of writing the characters out individually in a loop. </p>
		<p>In the next part of the tutorial, we'll look at the limited graphical capabilities of consoles, drawing lines, boxes and grids. </p>
<img src ="http://www.cppblog.com/gohan/aggbug/10276.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-07-20 22:46 <a href="http://www.cppblog.com/gohan/archive/2006/07/20/10276.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[基础]Win32 Console Applications - Part 1. of 6</title><link>http://www.cppblog.com/gohan/archive/2006/07/20/10274.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 20 Jul 2006 14:39:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/07/20/10274.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/10274.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/07/20/10274.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/10274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/10274.html</trackback:ping><description><![CDATA[
		<h1>Win32 Console Applications - Part 1. </h1>
		<center>
				<img height="92" alt="Hello World" src="http://www.adrianxw.dk/SoftwareSite/Consoles/Hello%20World.JPG" width="513" />
		</center>
		<p>Okay, hands up, who here started out with something like this, possibly in another language, possibly on another OS, but whatever, with something like that. I'm willing to bet there are a good few people who can say "yes, that was me". You don't really want to see the source do you? Oh all right then. </p>
		<pre>#include &lt;iostream&gt;
using namespace std;

int main()
{
    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
    return 0;
}
</pre>
		<p>8 lines. Could be less, by why make things harder to read? This is really the great strength of a Windows Console Application, you really do not need to do much in order to make a working program. That is why I use consoles. If I want to test out a bit of non GUI code, and I don't have a suitable application I can use as a framework, I knock together a quick console application, and I'm sure just about every other Windows programmer does as well. The user interface only needs to be sophisticated enough <i>to get the job done</i>. </p>
		<p>Some of the other tutorials on the site demostrate powerful techniques, but do it in a Console App because that's all that was needed. </p>
		<p>Can you do anything else with a Console App? Of course, the answer is yes, you can, and these tutorials demostrate some of the things that can be done with a console. Believe it or not, a huge number of questions concerning consoles crop up in help forums every week, so people are interested. If you are, read on. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>What is a Console? It is a Window, a special kind, yes, but it is a Window. You will frequently hear these things called "DOS boxes" because DOS had a character based UI, but this term is incorrect. There is no DOS under the NT cored WIndows operating systems, (NT, 2000, XP), and yet you can use a console. Why? Because it is a Window. (There are actually DOS emulators for these platforms - but this is a totally unrelated topic.) </p>
		<p>What makes a Console window special is that it is character based rather than pixel based. A normal window, like this browser window for example, (unless you're using a REALLY basic browser), is measured in pixels, each pixel is individually addressable and modifiable. With a character based medium, <i>that is not the case</i>, the smallest unit that can be addressed and thus modified is a character <b><i>cell</i></b>. </p>
		<p>A console's display area consist of rows and columns of character cells. It is a grid <i>or</i> two dimensional array <i>or</i> matrix of cells, all these terms are in use - they amount ot the same thing. Traditionally, the character cell at the top left is the origin or "home" position, and is designated (0,0) in an imaginary (x,y) grid. The character cell to it's immediate right is (1,0), the next (2,0) and so on. The cell just below (0,0) is (0,1), the one below that (0,2) and so on. On a typical console there are 80 cell positions across the screen, and 25 down, thus on such a console, the bottom right cell will be (79,24) remembering the grid is zero based. The little picture below shows graphically the cell numbers of the upper left portion of a larger screen or the entire grid of a 4x4 console of course. </p>
		<center>
				<img height="69" alt="CellGrid" src="http://www.adrianxw.dk/SoftwareSite/Consoles/CellGrid.gif" width="93" />
		</center>
		<p>Incidently, the reason for chosing 80x25 is historical. In the days before graphical terminals were widely available, people used character based terminals called "Visual Display Units", or VDU's. These typically had an 80x25 screen layout. I was one of those who used these beasts. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>Each character cell can contain one and only one character. I'll illustrate an artifact of this below. I type 5 "w" characters, then on the line below, 5 "i" characters...<br /><br />wwwww<br />iiiii<br /><br />... notice the length of the lines. Assuming you are using a modern browser, you should see that the upper line is longer than the lower. Now I'll write a console app which does the same, here is the output... </p>
		<center>
				<img height="92" alt="FixedFont" src="http://www.adrianxw.dk/SoftwareSite/Consoles/FixedFont.jpg" width="305" />
		</center>
		<p>... as you see, since each cell can only hold a single character, the last "i" character is directly below the last "w". There can be no proportional spacing in a console with the default font, (it is possible to simulate a very crude form of proportional spacing if only a few letters are used - but forget it - it's not worth the hassle). </p>
		<p>Okay, so we've got a grid of cells, what is in a cell? Simply, a cell is another grid, each cell being 8 pixels wide and 12 high. The characters that make up the font must be represented within this grid <i>including</i> any spacing - that's right, the pixels of one cell lie directly adjacent to the pixels of the next. This is somewhat limiting, and accounts for the rather poor quality of the console font, but as we will see later, it does have some advantages. The pictures below show how the "w" and "i" characters are encoded into a cell. </p>
		<center>
				<img height="205" alt="w Grid" src="http://www.adrianxw.dk/SoftwareSite/Consoles/wGrid.gif" width="97" />
				<img height="205" alt="i Grid" src="http://www.adrianxw.dk/SoftwareSite/Consoles/iGrid.gif" width="97" />
		</center>
		<p>Notice the blank column on the right of the "w", this ensures that two adjacent "w" characters will have at least a single pixel space between them. If you look at the last picture, you will see that is the case. Also notice, the dot over the "i" does not go to the top of the cell, this ensures that any character on the line above an "i" that has a <i>descender</i>, an extension below the normal line, "y" for example, will still have at least a one pixel gap between the descender and a "high" character. Thus, <i>normal</i> characters are represented by 7x11 grids with a blank row at the top and a blank column on the right side. </p>
		<p>The pixels marked with a "X" in the pictures above are rendered in the foreground colour, those in the empty pixels positions, in the background colour. By default, the foreground is white, the background black. Later on in the tutorial, I will show you how to change these colours, within limits. </p>
		<center>
				<img height="16" alt="----------" src="http://www.adrianxw.dk/GreenSchema/HR.gif" width="122" />
		</center>
		<p>There is a one pixel wide gap around the outside edge of the consoles display area. This prevents the top, bottom and edge characters merging with the frame. You cannot write into this gap. Thus a console's display area is 2+(8x) pixels wide, where x is the number of character cells in a row, and 2+(12y) pixels high where y is the number of visible rows, (there may be more rows above or below the current view as determined by the position of the scroll bar). </p>
		<p>I'm afraid this first page has really been rather a lot of dry theory. A lot of what you can do with consoles assumes you understand this material though, so read it through, and if later on in this tutorial, you find something that sounds weird, try reading this page again! </p>
		<p>In the next part, I'll show you how to name your Console, obtain the consoles standard handles, move the cursor about, write blocks of characters and clear the screen. </p>
		<!-- End of Text +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<img src ="http://www.cppblog.com/gohan/aggbug/10274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-07-20 22:39 <a href="http://www.cppblog.com/gohan/archive/2006/07/20/10274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>昨天，今天，明天。</title><link>http://www.cppblog.com/gohan/archive/2006/07/11/9704.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Tue, 11 Jul 2006 12:42:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2006/07/11/9704.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/9704.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2006/07/11/9704.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/9704.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/9704.html</trackback:ping><description><![CDATA[
		<div>昨天早上回来的家。<br />大学一年中学到的东西没有太多。书...还是只消化了3本多点...<br />很多杂乱无章的东西需要学吧。<br />今天，仍然看看书，上上机。准备明天的实习生活。<br />我明天会去当地影响最大的IT公司进行业余实习，其实不能说实习，<br />算是学习。知道明天会用到cb,oracle,进行COM组件编程,我还一点都不会。<br />其实至于vc我也只是console coder...不过没事，当作去学习吧。<br />明天，期待是美好的一天，我会弥补大一知识的空白，实践，实践，实践。<br />希望早日变强。<br /></div>
<img src ="http://www.cppblog.com/gohan/aggbug/9704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2006-07-11 20:42 <a href="http://www.cppblog.com/gohan/archive/2006/07/11/9704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>