﻿<?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>BlogJava-神奇好望角 The Magical Cape of Good Hope-文章分类-C/C++</title><link>http://www.blogjava.net/shinzey/category/27552.html</link><description>Sic vis pacem para bellum.</description><language>zh-cn</language><lastBuildDate>Fri, 07 Dec 2007 09:21:29 GMT</lastBuildDate><pubDate>Fri, 07 Dec 2007 09:21:29 GMT</pubDate><ttl>60</ttl><item><title>C 库函数 feof(FILE*) 判断文件末尾的问题</title><link>http://www.blogjava.net/shinzey/articles/165906.html</link><dc:creator>暴风雨骑士</dc:creator><author>暴风雨骑士</author><pubDate>Thu, 06 Dec 2007 15:05:00 GMT</pubDate><guid>http://www.blogjava.net/shinzey/articles/165906.html</guid><wfw:comment>http://www.blogjava.net/shinzey/comments/165906.html</wfw:comment><comments>http://www.blogjava.net/shinzey/articles/165906.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shinzey/comments/commentRss/165906.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shinzey/services/trackbacks/165906.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
        <tr>
            <td width="50%"><strong style="font-size: 12pt; font-family: 微软雅黑">C 库函数 feof(FILE*) 判断文件末尾的问题</strong></td>
            <td style="border-left: #000000 thin solid"><strong style="font-size: 12pt; font-family: 微软雅黑">A Problem on Using C Library Function feof(FILE*) to Judge The End of A File</strong></td>
        </tr>
        <tr>
            <td width="50%">　　嘟嘟用 C 写了一个程序读取 32768 字节大小的文件，每次读&nbsp;16 个字节，应该是 2048 次读完。但结果读了 2049 次，并且最后两次的数据相同，似乎重复读取了最后 16 个字节。源代码如下：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Dudu wrote a program with C, which read a file of 32768 bytes, 16 bytes each time, and it should finish reading after 2048 times. But the reault was&nbsp;it read 2049 times, and the data of last two times are the same, which seemed the last 16 bytes were read twice. Here is the code:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px; font-family: Courier New">
                <li><span style="color: #0000ff">int</span> loop = 0;
                <li><span style="color: #0000ff">while</span> (!feof(file)) {
                <li>&nbsp;&nbsp;&nbsp; loop++;</font></font>
                <li>&nbsp;&nbsp;&nbsp; fread(buffer, 16, 1, file);</font>
                <li>&nbsp;&nbsp;&nbsp; ......
                <li>}
                <li>printf(<span style="color: #ff6600">"%d\n"</span>, loop);&nbsp;&nbsp;&nbsp; // 2049 </li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　我看了一阵，发现导致这个错误的原因是&nbsp;<span style="font-family: Courier New">feof(FILE*)</span> 判断文件末尾的机制：文件指针在文件末尾的时候，除非再读一次导致发生 I/O 错误，<span style="font-family: Courier New">feof(FILE*)</span> 依然返回 0。因此用 <span style="font-family: Courier New">feof(FILE*)</span> 作为判断条件的 while&nbsp;循环始终会多读一次，而最后一次的读取是失败的，buffer 也就没有改变，看起来就像是重复读了一次。</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; I reviewed it for a whil and found the reason that produced this error is the mechanism&nbsp;<span style="font-family: Courier New">feof(FILE*)</span> used to judge the end of a file: When the file pointer is at the end of a file, <span style="font-family: Courier New">feof(FILE*)</span> still returns 0 unless reads one more time&nbsp;to course a I/O error. Therefore, a while loop using <span style="font-family: Courier New">feof(FILE*)</span>&nbsp;as the judgment condition always reads one more time, and the last time of reading will fail, so buffer stayed unchanged which looked like it repeated reading once.</td>
        </tr>
        <tr>
            <td>　　用下面的代码就没问题了：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Use the code&nbsp;below to solve this problem:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px; font-family: Courier New">
                <li><span style="color: #0000ff">int</span> loop = 0;
                <li><span style="color: #0000ff">while</span> (fread(buffer, 16, 1, file) == 1) {
                <li>&nbsp;&nbsp;&nbsp; loop++;
                <li>&nbsp;&nbsp;&nbsp; ......
                <li>}
                <li>printf(<span style="color: #ff6600">"%d\n"</span>, loop); // 2048 </li>
            </ol>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/shinzey/aggbug/165906.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shinzey/" target="_blank">暴风雨骑士</a> 2007-12-06 23:05 <a href="http://www.blogjava.net/shinzey/articles/165906.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用 NetBeans 开发一个简单的 Windows XP 程序 - 其三</title><link>http://www.blogjava.net/shinzey/articles/163331.html</link><dc:creator>暴风雨骑士</dc:creator><author>暴风雨骑士</author><pubDate>Mon, 26 Nov 2007 13:25:00 GMT</pubDate><guid>http://www.blogjava.net/shinzey/articles/163331.html</guid><wfw:comment>http://www.blogjava.net/shinzey/comments/163331.html</wfw:comment><comments>http://www.blogjava.net/shinzey/articles/163331.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shinzey/comments/commentRss/163331.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shinzey/services/trackbacks/163331.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
        <tr>
            <td width="50%"><strong style="font-size: 12pt; font-family: 微软雅黑">用 NetBeans 开发一个简单的 Windows XP 程序 - 其三</strong></td>
            <td style="border-left: #000000 thin solid"><strong style="font-size: 12pt; font-family: 微软雅黑">Developing&nbsp;A&nbsp;simple Windows XP&nbsp;Application with NetBeans - Part 3</strong></td>
        </tr>
        <tr>
            <td>　　新建一个名为 <strong>MyMakefile.mk</strong> 的 Makefile，内容如下：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Create a new Makefile named <strong>MyMakefile.mk</strong> of the following content:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li>PRJ=dist/Release/WinHello.exe
                <li>OBJ=build/Release/WinHello.o build/Release/Resource.o
                <li>CC=gcc
                <li>CFLAGS=-mwindows -s
                <li>RES=windres
                <li>LIB=-lcomctl32
                <li>
                <li><span style="color: #800000">$(PRJ)</span>: <span style="color: #800000">$(OBJ)</span>
                <li>&nbsp;&nbsp;&nbsp; mkdir -p dist/Release
                <li>&nbsp;&nbsp;&nbsp; <span style="color: #800000">$(CC)</span> <span style="color: #800000">$(CFLAGS)</span> -o dist/Release/WinHello <span style="color: #800000">$(OBJ)</span> <span style="color: #800000">$(LIB)</span>
                <li>
                <li>build/Release/WinHello.o: WinHello.c
                <li>&nbsp;&nbsp;&nbsp; mkdir -p build/Release
                <li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000">$(CC)</span> <span style="color: #800000">$(CFLAGS)</span> -c -O4 -o build/Release/WinHello.o WinHello.c
                <li>
                <li>build/Release/Resource.o: Resource.rc
                <li>&nbsp;&nbsp; &nbsp;mkdir -p build/Release
                <li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000">$(RES)</span> -o build/Release/Resource.o Resource.rc
                <li>
                <li>.PHONY: clean
                <li>clean:
                <li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #800000">${RM}</span> <span style="color: #800000">$(OBJ)</span> <span style="color: #800000">$(PRJ)</span>
                <li></li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　注意由于排版问题，制表符被扩展成了空格。把这个 Makefile 添加进项目，在上面右键选择&#8220;make&#8221;，就能得到如下的预期效果了：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Note that because of typesetting, tabs are expanded to spaces. Add this Makefile to the project, right click and select "make", and the following result is shown as expected:</td>
        </tr>
        <tr>
            <td style="text-align: center" colspan="2"><img alt="" src="http://www.blogjava.net/images/blogjava_net/shinzey/WinHello.png" /></td>
        </tr>
    </tbody>
</table>  <img src ="http://www.blogjava.net/shinzey/aggbug/163331.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shinzey/" target="_blank">暴风雨骑士</a> 2007-11-26 21:25 <a href="http://www.blogjava.net/shinzey/articles/163331.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用 NetBeans 开发一个简单的 Windows XP 程序 - 其二</title><link>http://www.blogjava.net/shinzey/articles/163328.html</link><dc:creator>暴风雨骑士</dc:creator><author>暴风雨骑士</author><pubDate>Mon, 26 Nov 2007 13:14:00 GMT</pubDate><guid>http://www.blogjava.net/shinzey/articles/163328.html</guid><wfw:comment>http://www.blogjava.net/shinzey/comments/163328.html</wfw:comment><comments>http://www.blogjava.net/shinzey/articles/163328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shinzey/comments/commentRss/163328.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shinzey/services/trackbacks/163328.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
        <tr>
            <td width="50%"><strong style="font-size: 12pt; font-family: 微软雅黑">用 NetBeans 开发一个简单的 Windows XP 程序 - 其二</strong></td>
            <td style="border-left: #000000 thin solid"><strong style="font-size: 12pt; font-family: 微软雅黑">Developing&nbsp;A&nbsp;simple Windows XP&nbsp;Application with NetBeans - Part 2</strong></td>
        </tr>
        <tr>
            <td>　　在项目节点上右键转到&#8220;属性 &#8594;&nbsp;C/C++ &#8594;&nbsp;C 编译器&#8221;节点，在&#8220;命令行&#8221;中设置&#8220;其他选项&#8221;为&nbsp;<strong>-mwindows</strong>；再转到&#8220;链接器 &#8594; 库&#8221;，单击&#8220;库&#8221;右边的省略号按钮，接着单击&#8220;添加选项&#8221;，设置&#8220;其他选项&#8221;为 <strong>-lcomctl32</strong>。</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Right click the project node and&nbsp;go to&nbsp;"Properties &#8594;&nbsp;C/C++ &#8594;&nbsp;C Compiler" node,&nbsp;in "Command Line" set "Additonal Options" to <strong>-mwindows</strong>; then go to "Linker &#8594;&nbsp;Libraries", click the ellipsis&nbsp;button to the right of "Libraries", click "Add Option" and set "Other Option" to <strong>-lcomctl32</strong>.</td>
        </tr>
        <tr>
            <td>　　这时如果直接执行&#8220;生成项目&#8221;，则会输出以下错误：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; If we directly&nbsp;execute "Build Project" right now, the following errors will be complained:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li>WinHello.c:6: error: `INITCOMMONCONTROLSEX' undeclared (first use in this function)
                <li>WinHello.c:6: error: (Each undeclared identifier is reported only once
                <li>WinHello.c:6: error: for each function it appears in.)
                <li>WinHello.c:6: error: parse error before "init"
                <li>WinHello.c:7: error: `init' undeclared (first use in this function)
                <li>WinHello.c:8: error: `ICC_STANDARD_CLASSES' undeclared (first use in this function) </li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　结构体 <span style="font-family: Courier New">INITCOMMONCONTROLSEX</span> 在 <strong>commctrl.h</strong> 中声明，<strong>commctrl.h</strong> 位于 mingw\include。打开这个头文件，查找 <span style="font-family: Courier New">INITCOMMONCONTROLSEX</span>，发现它包含在一段预处理指令中：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp;&nbsp;Constuct <span style="font-family: Courier New">INITCOMMONCONTROLSEX</span>&nbsp;is decleared in&nbsp;<strong>commctrl.h</strong>, which is inside mingw\include.&nbsp;Open this header file and search&nbsp;<span style="font-family: Courier New">INITCOMMONCONTROLSEX</span>, and the following segment of preprocessed commands will be found:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee"><span style="color: #000000">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li><span style="color: #008000">#if</span></span><span style="color: #000000">&nbsp;(_WIN32_IE&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x0300</span><span style="color: #000000">)</span>
                <li><span style="color: #000000"><span style="color: #0000ff">typedef&nbsp;struct</span>&nbsp;tagINITCOMMONCONTROLSEX&nbsp;{</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;dwSize;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;dwICC;</span>
                <li><span style="color: #000000">}&nbsp;INITCOMMONCONTROLSEX,</span><span style="color: #000000">*</span><span style="color: #000000">LPINITCOMMONCONTROLSEX;</span>
                <li><span style="color: #000000"><span style="color: #008000">#endif</span></span> </li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　再查找 <span style="font-family: Courier New">_WIN32_IE</span>，找到：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Then search <span style="font-family: Courier New">_WIN32_IE</span> and find:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee"><span style="color: #000000">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li><span style="color: #008000">#if</span></span><span style="color: #000000">&nbsp;0</span>
                <li><span style="color: #000000"><span style="color: #008000">#define</span> _WIN32_IE 0x0300</span>
                <li><span style="color: #000000"><span style="color: #008000">#endif</span></span> </li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　<span style="font-family: Courier New">#if 0</span> 表示在默认情况下，永远不会定义 <span style="font-family: Courier New">_WIN32_IE</span>。注释掉行 1 和行 3，再编译，仍然出错：</td>
            <td style="border-left: #000000 thin solid"><span style="font-family: Courier New"><font face="Times New Roman">&nbsp;&nbsp;&nbsp; </font>#if 0</span> means <span style="font-family: Courier New">_WIN32_IE</span> would never be definded by default.&nbsp;Comment line 1 and line 3, compile and still gets errors:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li>WinHello.c:8: error: `ICC_STANDARD_CLASSES' undeclared (first use in this function)
                <li>WinHello.c:8: error: (Each undeclared identifier is reported only once
                <li>WinHello.c:8: error: for each function it appears in.) </li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　像上面一样去查找 <span style="font-family: Courier New">ICC_STANDARD_CLASSES</span>，这次要把 <strong>windef.h</strong> 中的 <span style="font-family: Courier New">WINVER</span> 改为 <span style="font-family: Courier New">0x0501</span>。我觉得不必担心改了这些会带来什么坏处。这些变量存在的意义是定义或不定义一些 API，以便为不同版本的 Windows 开发程序。如今 Windows Vista 已经出来了，世界进步很快，有新东西为什么不用呢？</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp;&nbsp;Search <span style="font-family: Courier New">ICC_STANDARD_CLASSES</span> as above, and this time modify <span style="font-family: Courier New">WINVER</span>&nbsp;in <strong>windef.h</strong> to <span style="font-family: Courier New">0x0501</span>. I don't think it necessary to warry that&nbsp;these modifications do any thing bad. The purpose of the&nbsp;existance of&nbsp;these variables is to define some APLs&nbsp;or not, for the sake of developing applications for various versions of Windows. Windows Vista has been present, and the world is rapidly progressing, so why not use new things?</td>
        </tr>
        <tr>
            <td>　　现在编译运行，不会出错了，但风格是 9x/2000 那种老土的，这是因为默认情况下 NetBeans 不知道如何编译 rc 文件。解决这一问题的办法是自定义一个 Makefile。</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Compile, run, and no error&nbsp;now, but the style is ugly as 9x/2000's, that's because by default NetBeans dosen't know how to compile rc files. The solution to this peoblem is to write a custom Makefile.</td>
        </tr>
        <tr>
            <td>　　好像差不多长了，下次继续。</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; This seems long enough and is to be continued next time.</td>
        </tr>
    </tbody>
</table>
  <img src ="http://www.blogjava.net/shinzey/aggbug/163328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shinzey/" target="_blank">暴风雨骑士</a> 2007-11-26 21:14 <a href="http://www.blogjava.net/shinzey/articles/163328.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用 NetBeans 开发一个简单的 Windows XP 程序 - 其一</title><link>http://www.blogjava.net/shinzey/articles/163013.html</link><dc:creator>暴风雨骑士</dc:creator><author>暴风雨骑士</author><pubDate>Sun, 25 Nov 2007 12:47:00 GMT</pubDate><guid>http://www.blogjava.net/shinzey/articles/163013.html</guid><wfw:comment>http://www.blogjava.net/shinzey/comments/163013.html</wfw:comment><comments>http://www.blogjava.net/shinzey/articles/163013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shinzey/comments/commentRss/163013.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shinzey/services/trackbacks/163013.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="5" width="100%" border="0">
    <tbody>
        <tr>
            <td width="50%"><strong style="font-size: 12pt; font-family: 微软雅黑">用 NetBeans 开发一个简单的 Windows XP 程序 - 其一</strong></td>
            <td style="border-left: #000000 thin solid"><strong style="font-size: 12pt; font-family: 微软雅黑">Developing&nbsp;A&nbsp;simple Windows XP&nbsp;Application with NetBeans - Part 1</strong></td>
        </tr>
        <tr>
            <td>　　首先创建一个名为 <strong>WinHello</strong> 的项目，在&#8220;源代码&#8221;节点下新建 <strong>WinHello.c</strong>，代码的内容如下：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; First create a project&nbsp;with the name <strong>WinHello</strong>, and then create a new <strong>WinHello.c</strong> under "Source Files" node with the following code:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li><span style="color: #000000"><span style="color: #008000">#include</span>&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">windows.h</span><span style="color: #000000">&gt;</span>
                <li><span style="color: #000000"><span style="color: #008000">#include</span>&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">commctrl.h</span><span style="color: #000000">&gt;</span>
                <li>
                <li><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;WINAPI&nbsp;WinMain(HINSTANCE&nbsp;hInstance,&nbsp;HINSTANCE&nbsp;hPrevInstance,</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PSTR&nbsp;szCmdLine,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;iCmdShow)&nbsp;{</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;INITCOMMONCONTROLSEX&nbsp;init;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;init.dwSize&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;<span style="color: #0000ff">sizeof</span>(init);</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;init.dwICC&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ICC_STANDARD_CLASSES;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;InitCommonControlsEx(</span><span style="color: #000000">&amp;</span><span style="color: #000000">init);</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;MessageBox(NULL,&nbsp;TEXT(</span><span style="color: #000000">"</span><span style="color: #000000">再来！</span><span style="color: #000000">"</span><span style="color: #000000">),&nbsp;TEXT(</span><span style="color: #000000">"哈哈~</span><span style="color: #000000">"</span><span style="color: #000000">),&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">);</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;</span>
                <li><span style="color: #000000">}</span>
                <li></li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　注意末尾处最好再加上一个回车符，因为我们将用 MinGW GCC 来编译，遵循 UNIX 的规矩总是好的。行 6~9 指明用 Windows XP 风格初始化程序，但这还不够，我们还需要一个资源脚本和一个清单文件来显示调用 Comctl32.dll 版本 6（默认状态下自动调用版本 5，也就是 Windows 9x/2000 风格）。在&#8220;资源文件&#8221;节点下新建资源脚本 <strong>resource.rc</strong> 和清单文件 <strong>WinHello.exe.manifest</strong>。<strong>resource.rc</strong> 的内容如下：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; Attention it's best to add a CR&nbsp;in the end, because we'll compile it with MinGW GCC, so it's always good to follow the&nbsp;UNIX conventions. Line 6~9 indicates Windows XP style will be used to initialize the application, but that's not enough. We still&nbsp;need a resource script and a manifest file to explicitly invoke Comctl32.dll version 6 (version 5 is automatically invoked by default which is Windows 9x/2000 style). Create a new resource script <strong>resource.rc</strong> and a&nbsp;manifest file <strong>WinHello.exe.manifest</strong>. The content of <strong>resource.rc</strong> is as below:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li><span style="color: #008000">#include</span> &lt;windows.h&gt;
                <li>
                <li>CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Winhello.exe.manifest"
                <li></li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　<strong>WinHello.exe.manifest</strong> 的内容如下：</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; The content of <strong>WinHello.exe.manifest</strong> is as below:</td>
        </tr>
        <tr>
            <td colspan="2">
            <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: #cccccc 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #cccccc 1px solid; font-family: Courier New; background-color: #eeeeee">
            <ol style="margin-top: 0px; margin-bottom: 0px">
                <li><span style="color: #0000ff">&lt;?</span><span style="color: #ff00ff">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"&nbsp;standalone="yes"</span><span style="color: #0000ff">?&gt;</span>
                <li><span style="color: #0000ff">&lt;</span><span style="color: #800000">assembly&nbsp;</span><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="urn:schemas-microsoft-com:asm.v1"</span><span style="color: #ff0000">&nbsp;manifestVersion</span><span style="color: #0000ff">="1.0"</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #0000ff">&lt;</span><span style="color: #800000">assemblyIdentity</span>
                <li><span style="color: #800000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0.0.0"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;processorArchitecture</span><span style="color: #0000ff">="X86"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;name</span><span style="color: #0000ff">="zhyi.zhyi.Winhello"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;type</span><span style="color: #0000ff">="win32"</span>
                <li><span style="color: #0000ff">/&gt;</span>
                <li><span style="color: #0000ff">&lt;</span><span style="color: #800000">description</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">Description.</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">description</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #0000ff">&lt;</span><span style="color: #800000">dependency</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">dependentAssembly</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">assemblyIdentity</span>
                <li><span style="color: #800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000">type</span><span style="color: #0000ff">="win32"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name</span><span style="color: #0000ff">="Microsoft.Windows.Common-Controls"</span>
                <li><span style="color: #0000ff">&nbsp;</span><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version</span><span style="color: #0000ff">="6.0.0.0"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;processorArchitecture</span><span style="color: #0000ff">="X86"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;publicKeyToken</span><span style="color: #0000ff">="6595b64144ccf1df"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;language</span><span style="color: #0000ff">="*"</span>
                <li><span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">/&gt;</span>
                <li><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">dependentAssembly</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #0000ff">&lt;/</span><span style="color: #800000">dependency</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #0000ff">&lt;/</span><span style="color: #800000">assembly</span><span style="color: #0000ff">&gt;</span>
                <li><span style="color: #000000"><br />
                </span></li>
            </ol>
            </div>
            </td>
        </tr>
        <tr>
            <td>　　到现在为止，所有的源文件都准备好了，接下来是编译。为避免一篇文章过长，且看下回分解。</td>
            <td style="border-left: #000000 thin solid">&nbsp;&nbsp;&nbsp; By now all source files are ready, and&nbsp;next job&nbsp;is compiling.&nbsp;For avoiding a too long article, please&nbsp;read the next part.</td>
        </tr>
    </tbody>
</table><img src ="http://www.blogjava.net/shinzey/aggbug/163013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shinzey/" target="_blank">暴风雨骑士</a> 2007-11-25 20:47 <a href="http://www.blogjava.net/shinzey/articles/163013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>