﻿<?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++博客-Sunshine Alike-随笔分类-WinAPI应用程序</title><link>http://www.cppblog.com/sunshinealike/category/9770.html</link><description>半完美主义</description><language>zh-cn</language><lastBuildDate>Sat, 30 May 2009 20:18:27 GMT</lastBuildDate><pubDate>Sat, 30 May 2009 20:18:27 GMT</pubDate><ttl>60</ttl><item><title>MultiThread</title><link>http://www.cppblog.com/sunshinealike/archive/2009/05/11/82542.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Mon, 11 May 2009 03:19:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/05/11/82542.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/82542.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/05/11/82542.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/82542.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/82542.html</trackback:ping><description><![CDATA[  WindowsAPI里的多线程简单例子，先记下来，以后再学学<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">windows.h</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">线程处理函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DWORD WINAPI Fun1(LPVOID lpParam);<br />DWORD WINAPI Fun2(LPVOID lpParam);<br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> tickets </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">20</span><span style="color: rgb(0, 0, 0);">;<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main()<br />{</span><span style="color: rgb(0, 0, 0);"><br />    HANDLE hThread1, hThread2;<br />    hThread1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateThread(NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, Fun1, NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, NULL);<br />    hThread2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateThread(NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, Fun2, NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, NULL);<br />    CloseHandle(hThread1);<br />    CloseHandle(hThread2);<br /><br />    cin.</span><span style="color: rgb(0, 0, 255);">get</span><span style="color: rgb(0, 0, 0);">();<br />}<br /><br /><br />DWORD WINAPI Fun1(LPVOID lpParam)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tickets </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Thread1 sell ticket : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">tickets</span><span style="color: rgb(0, 0, 0);">--&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}<br /><br />DWORD WINAPI Fun2(LPVOID lpParam)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tickets </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Thread2 sell ticket : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">tickets</span><span style="color: rgb(0, 0, 0);">--&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}</span></div>这里在main里用两个函数Fun1和Fun2建了两个线程，有一个全局变量ticket＝20表示20张票，分由两个线程进行出售。<br />但是这个程序运行起来结果会出现混乱和不确定：<br /><img src="file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot.png" alt="" /><img src="file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot-1.png" alt="" /><img src="file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot-2.png" alt="" /><img src="/WebResource.axd?d=pLXXeGbWF7eXU8SMs2-GFZvUWY2JNH05dFx5YzJhGUYAYJAFEaTEq36NAhTPy7_KekvzDFwt8wvQWdByvJIGWdEq6x2KpKD80&amp;t=633043190660000000" width="1" height="1" /><br /><img src="http://www.cppblog.com/images/cppblog_com/sunshinealike/%E7%BB%93%E6%9E%9C1.jpg" alt="结果1.jpg" width="440" align="center" border="0" height="362" /><br />原因很简单，在操作系统里都学过关于同步的问题，这里的两个线程之间就没有对临界资源ticket进行同步。类似于操作系统里的PV操作，可以将程序改为：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">windows.h</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">线程处理函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DWORD WINAPI Fun1(LPVOID lpParam);<br />DWORD WINAPI Fun2(LPVOID lpParam);<br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> tickets </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">20</span><span style="color: rgb(0, 0, 0);">;<br />HANDLE hMutex;<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main()<br />{<br />    hMutex </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateMutex(NULL, </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">, NULL);<br /><br />    HANDLE hThread1, hThread2;<br />    hThread1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateThread(NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, Fun1, NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, NULL);<br />    hThread2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateThread(NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, Fun2, NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, NULL);<br />    CloseHandle(hThread1);<br />    CloseHandle(hThread2);<br /><br />    cin.</span><span style="color: rgb(0, 0, 255);">get</span><span style="color: rgb(0, 0, 0);">();<br />}<br /><br /><br />DWORD WINAPI Fun1(LPVOID lpParam)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        WaitForSingleObject(hMutex, INFINITE);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tickets </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Thread1 sell ticket : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">tickets</span><span style="color: rgb(0, 0, 0);">--&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        ReleaseMutex(hMutex);<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}<br /><br />DWORD WINAPI Fun2(LPVOID lpParam)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        WaitForSingleObject(hMutex, INFINITE);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tickets </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Thread2 sell ticket : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">tickets</span><span style="color: rgb(0, 0, 0);">--&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        ReleaseMutex(hMutex);<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}</span></div>这里用了一个信息量Mutex来对ticket进行同步操作，进程要操作ticket之前必须先获得信号量，使用完之后释放以使整个过程能继续下去。<br />最后得到正常的结果为：<br /><img src="http://www.cppblog.com/images/cppblog_com/sunshinealike/%E7%BB%93%E6%9E%9C2.jpg" alt="结果2.jpg" width="246" align="center" border="0" height="323" /><br /><img src ="http://www.cppblog.com/sunshinealike/aggbug/82542.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-05-11 11:19 <a href="http://www.cppblog.com/sunshinealike/archive/2009/05/11/82542.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WinSocketTest 2.0</title><link>http://www.cppblog.com/sunshinealike/archive/2009/05/06/82069.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Wed, 06 May 2009 09:08:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/05/06/82069.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/82069.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/05/06/82069.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/82069.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/82069.html</trackback:ping><description><![CDATA[  在VS下建一个对话框的MFC程序UDPChat，去掉所有带的控件。加入以下控件：<br />按钮一个   IDC_BTN_SEND<br />编程框三个 IDC_EDIT_PORT(端口号)，IDC_EDIT_REC(显示接收到的消息)，IDC_EDIT_SEND(输入发送内容)<br />IP控件一个 IDC_IPADDRESS1<br /><br />UDPChatDlg.h中加入<br />#define    WM_RECDATA WM_USER+1<br />来定义一个消息号，用来处理接收到消息的事件<br /><br />然后是以下方法声明：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">:<br />    </span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> InitSocket(</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">);<br />    </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> DWORD WINAPI RecProc(LPVOID lpParam);<br />    afx_msg LRESULT OnRecData(WPARAM wParam,LPARAM lParam);<br />    afx_msg </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> OnBnClickedBtnSend();</span></div><br />消息映射里加入两条：<br />ON_MESSAGE(WM_RECDATA, OnRecData)//处理收到消息事件<br />ON_BN_CLICKED(IDC_BTN_SEND, &amp;CTcpChatDlg::OnBnClickedBtnSend)//处理按钮点击事件<br /><br />至此，万事具备，只欠东风。<br /><br />首先窗口初始化函数OnInitDialog里加入<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">构造一个新线程用于监听接收</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    HANDLE hThread </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> <br />        CreateThread(NULL, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, RecProc, (LPVOID)m_hWnd, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, NULL);<br />    CloseHandle(hThread);<br /><br />    ((CIPAddressCtrl</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)GetDlgItem(IDC_IPADDRESS1))</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">SetAddress(</span><span style="color: rgb(0, 0, 0);">127</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />    SetDlgItemText(IDC_EDIT_PORT, _T(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">6000</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));</span></div>后面就是四个相关的成员函数，需要注意的是在线程必须使用静态函数或者全局函数，因为这程序一开始，线程就运行起来了，而成员方法在那个时候可能还没有生成出来。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> CTcpChatDlg::InitSocket()<br />{</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    WORD wVersionRequested;<br />    WSADATA wsaData;<br />    wVersionRequested </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MAKEWORD( </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> );<br /><br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> WSAStartup( wVersionRequested, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">wsaData );<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( err </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ) {<br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( LOBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"><br />        HIBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> ) {<br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            WSACleanup( );<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">; <br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />}<br /><br /><br />DWORD WINAPI CTcpChatDlg::RecProc(LPVOID lpParam)<br />{</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    HWND hWnd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HWND)lpParam;<br /></span><span style="color: rgb(0, 128, 0);"><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">-----------------------------------------------<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Create a receiver socket to receive datagrams</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    SOCKET RecvSocket </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> socket(AF_INET, SOCK_DGRAM, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(INVALID_SOCKET </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> RecvSocket)<br />    {            <br />        ::AfxMessageBox(_T(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">socket创建失败</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">-----------------------------------------------<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Bind the socket to any address and the specified port.</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br />    SOCKADDR_IN RecvAddr;<br />    RecvAddr.sin_family </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> AF_INET;<br />    RecvAddr.sin_port </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htons(</span><span style="color: rgb(0, 0, 0);">6000</span><span style="color: rgb(0, 0, 0);">);<br />    RecvAddr.sin_addr.S_un.S_addr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htonl(INADDR_ANY);<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(SOCKET_ERROR </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> bind(RecvSocket, (SOCKADDR </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">RecvAddr, </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(RecvAddr)))<br />    {<br />        closesocket(RecvSocket);<br />        ::AfxMessageBox(_T(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bind失败</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">-----------------------------------------------<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Call the recvfrom function to receive datagrams<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> on the bound socket.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> retval;<br /><br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> RecvBuf[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> tmpBuf[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];<br /><br />    sockaddr_in SenderAddr;<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> SenderAddrSize </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(SenderAddr);<br /><br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        retval </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> recvfrom(RecvSocket, <br />            RecvBuf, <br />            </span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">, <br />            </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, <br />            (SOCKADDR </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">SenderAddr, <br />            </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">SenderAddrSize);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(SOCKET_ERROR </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> retval)<br />        {<br />            CString strError;<br />            strError.Format(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">error code : %d</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, WSAGetLastError());<br />            ::AfxMessageBox(strError);<br />            </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        }<br />        sprintf_s(tmpBuf, </span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">收到%s消息: %s</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, inet_ntoa(SenderAddr.sin_addr), RecvBuf);<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">发送消息</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        ::PostMessage(hWnd, WM_RECDATA, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, (LPARAM)tmpBuf);<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">清理工作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    closesocket(RecvSocket);<br />    WSACleanup();<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">成功</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">}<br /><br /><br />LRESULT CTcpChatDlg::OnRecData(WPARAM wParam,LPARAM lParam)<br />{<br />    CString str((</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)lParam);<br />    CString origin;<br />    GetDlgItemText(IDC_EDIT_REC,origin);<br />    str </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\r\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    str </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> origin;<br />    SetDlgItemText(IDC_EDIT_REC,str);<br />    SetDlgItemText(IDC_EDIT_SEND, _T(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">));<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> CTcpChatDlg::OnBnClickedBtnSend()<br />{<br />    DWORD dwIP;<br />    ((CIPAddressCtrl</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)GetDlgItem(IDC_IPADDRESS1))</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">GetAddress(dwIP);<br />    CString strPort;<br />    GetDlgItemText(IDC_EDIT_PORT, strPort);<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">创建发送地址信息</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    SOCKADDR_IN addrTo;<br />    addrTo.sin_family </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> AF_INET;<br />    addrTo.sin_port </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htons(atoi(strPort));<br />    addrTo.sin_addr.S_un.S_addr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htonl(dwIP);<br /><br />    CString strMsg;<br />    GetDlgItemText(IDC_EDIT_SEND, strMsg);<br /><br />    SOCKET sock </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> socket(AF_INET, SOCK_DGRAM, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(SOCKET_ERROR </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> <br />        sendto(<br />        sock, strMsg, <br />        strMsg.GetLength()</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, <br />        (SOCKADDR </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">addrTo, </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(addrTo)<br />        ))<br />    {<br />        CString strError;<br />        strError.FormatMessage(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Send Failed, Error Code: %d</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, WSAGetLastError());<br />        MessageBox(strError);<br />    }<br />    <br />    closesocket(sock);<br />}<br /></span></div><br /><img src ="http://www.cppblog.com/sunshinealike/aggbug/82069.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-05-06 17:08 <a href="http://www.cppblog.com/sunshinealike/archive/2009/05/06/82069.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WinSocketTest 1.0</title><link>http://www.cppblog.com/sunshinealike/archive/2009/04/17/80165.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Fri, 17 Apr 2009 01:44:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/04/17/80165.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/80165.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/04/17/80165.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/80165.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/80165.html</trackback:ping><description><![CDATA[好久没来写点东西,最近鬼事还真是多，破项目搞的人烦死。带队的经理说给我们的要求是日代码100行(核心代码),懒了这么久，一下写起来还真是累啊！<br />最近来了点劲头,先写上练的几个例子<br /><br />使用windows套接字的网络小程序-------------------<br /><br />1.Socket基本操作<br />　(1)启动/终止<br />     winsock在被调用时以动态链接库的形式实现，所以在它初始化时应首先调用WSAStartup函数进行初始化，同时确定被调用的winsock版本号等。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">  加载套接字库</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    WORD wVersionRequested;<br />    WSADATA wsaData;<br />    wVersionRequested </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MAKEWORD( </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> );<br /><br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> WSAStartup( wVersionRequested, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">wsaData );<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( err </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ) {<br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( LOBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"><br />        HIBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ) {<br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            WSACleanup( );<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">; <br /></span></div>这里加载了1.1版本的socket。在网络通信完成后，需要使用函数WSACleanup释放资源。<br />　(2)创建与绑定<br />　　套接字的创建非常简单，只需要调用socket即可。如下：<br />    SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);//流式，TCP<br />　　SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);//数据报，UDP<br /><br />　　使用bind函数可以将一个套接字绑定到一个地址上<br />　　int bind(SOCKET sock, const struct sockaddr* name, int len);//sockaddr是一个用来表示地<br />　　址信息的结构<br />　(3)侦听，接受连接与连接<br />　　listen, accept, connect这三个函数用于建立通信的连接。<br />　　int listen(SOCKET sock, int backlog);//scok必须是一个已经绑定但是没有连接的套接字，<br />　　backlog用于设定最大可以等待的连接长度<br />　　成功调用listen函数后，就可以接受客户机的连接了。<br />　　SOCKET accept(SOCKET sock, struct sockaddr* addr, int* addrlen);<br />　　到此一切就绪，当客户机想到连接时可以使用connect进行连接。<br />　(4)发送，连接<br />　　用于TCP的：<br />　　int send(SOCKET sock, const char* buf, int len, int flags);<br />    int recv(SOCKET sock, char* buf, int len, int flags);<br />　　用于UDP的：<br />　　int sendto(SOCKET sock, const char* buf, int len, int flags, <br />　　　　　　　　　　　　　　const struct sockaddr* to, int tolen);<br />
    int recvfrom(SOCKET sock, char* buf, int len, int flags, <br />　　　　　　　　　　　　　　　struct sockaddr* from, int formlen);<br /><br />2.示例<br />　两个win32的控制台程序，一个TcpSer，一个TcpClient。<br />　为了使用socket需要包含头文件&lt;Winsock2.h&gt;<br />　<br />　TcpSer：<br />　<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Winsock2.h</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main()<br />{<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">加载套接字库</span><span style="color: rgb(0, 128, 0);">，版本1.1<br /></span><span style="color: rgb(0, 0, 0);">    WORD wVersionRequested;<br />    WSADATA wsaData;<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> err;<br /><br />    wVersionRequested </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MAKEWORD( </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> );<br /><br />    err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> WSAStartup( wVersionRequested, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">wsaData );<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( err </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ) {<br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( LOBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"><br />        HIBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ) {<br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            WSACleanup( );<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">; <br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">创建套接字</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    SOCKET sockSer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> socket(AF_INET, SOCK_STREAM, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">地址结构体</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 0, 0);">    SOCKADDR_IN addrSer;<br />    addrSer.sin_addr.S_un.S_addr  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htonl(INADDR_ANY);<br />    addrSer.sin_family </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> AF_INET;<br />    addrSer.sin_port </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htons(</span><span style="color: rgb(0, 0, 0);">6000</span><span style="color: rgb(0, 0, 0);">);<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">绑定与监听</span><br /><span style="color: rgb(0, 0, 0);">    bind(sockSer, (SOCKADDR</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">addrSer, </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(SOCKADDR));<br />    listen(sockSer, </span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">);<br />    cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Tcp Server Run!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br /><br />    SOCKADDR_IN addrClient;<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> len </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(SOCKADDR);<br /></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">　　//</span><span style="color: rgb(0, 128, 0);">收到连接请求，创建一个新socket用于保持连接</span><br /><span style="color: rgb(0, 0, 0);">    SOCKET sockCon </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> accept(sockSer, (SOCKADDR</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">addrClient, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">len);<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> recBuf[</span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">];<br />        recv(sockCon, recBuf, </span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />        cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">message form clinet : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">recBuf</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">清理工作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    closesocket(sockSer);<br />    WSACleanup();</span><br /><span style="color: rgb(0, 0, 0);">}</span></div><br />　TcpClient：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Winsock2.h</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main()<br />{<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">加载套接字库</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    WORD wVersionRequested;<br />    WSADATA wsaData;<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> err;<br /><br />    wVersionRequested </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MAKEWORD( </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> );<br /><br />    err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> WSAStartup( wVersionRequested, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">wsaData );<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( err </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ) {<br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( LOBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"><br />        HIBYTE( wsaData.wVersion ) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ) {<br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Tell the user that we could not find a usable </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> WinSock DLL.                                  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />            WSACleanup( );<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">; <br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">创建套接字</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    SOCKET sockClient </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> socket(AF_INET, SOCK_STREAM, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />    <br />    SOCKADDR_IN addrSer;<br />    addrSer.sin_addr.S_un.S_addr  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> inet_addr(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">127.0.0.1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    addrSer.sin_family </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> AF_INET;<br />    addrSer.sin_port </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> htons(</span><span style="color: rgb(0, 0, 0);">6000</span><span style="color: rgb(0, 0, 0);">);<br /><br />    cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">enter your message: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> sendBuf;<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(cin</span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(0, 0, 0);">sendBuf)<br />    {<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(sendBuf </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">q</span><span style="color: rgb(0, 0, 0);">"　｜｜　sendBuf == "Q"</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">连接服务器</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        connect(sockClient, (SOCKADDR</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">addrSer, </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(SOCKADDR));<br />        send(sockClient, sendBuf.c_str(), sendBuf.length()</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />        cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">enter your message: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">清理工作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    closesocket(sockClient);<br />    WSACleanup();<br />}</span></div><font size="4"><b><br />最后还要注意的就是：</b>在VS下编译时还要在项目属性&gt;配置属性&gt;链接器&gt;命令行里加入附加选项ws2_32.lib<br />否则链接的时候找不到与socket相关的函数</font><br /><img src ="http://www.cppblog.com/sunshinealike/aggbug/80165.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-04-17 09:44 <a href="http://www.cppblog.com/sunshinealike/archive/2009/04/17/80165.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WindowsAPI学习笔记五 - 资源在Windows编程中的应用</title><link>http://www.cppblog.com/sunshinealike/archive/2009/03/14/76539.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Fri, 13 Mar 2009 16:24:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/03/14/76539.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/76539.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/03/14/76539.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/76539.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/76539.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在				windows				应用程序中有几种不同类型的资源，如加速键，位图，光标，对话框，菜单，工具条和字符串等。在最初的				API				编程阶段，程序员可以用文本编辑器来编写资源脚本，这种方式比较灵活，但代码量很大。								在				Winodws				的可执行文件中，资源是独立于代码的，使用单独的				Resource Compil...&nbsp;&nbsp;<a href='http://www.cppblog.com/sunshinealike/archive/2009/03/14/76539.html'>阅读全文</a><img src ="http://www.cppblog.com/sunshinealike/aggbug/76539.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-03-14 00:24 <a href="http://www.cppblog.com/sunshinealike/archive/2009/03/14/76539.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WindowsAPI学习笔记四 - 对键盘和鼠标的响应</title><link>http://www.cppblog.com/sunshinealike/archive/2009/03/12/76346.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Thu, 12 Mar 2009 08:17:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/03/12/76346.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/76346.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/03/12/76346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/76346.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/76346.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span style="font-family: 宋体;">键盘和鼠标在</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">中的重要性不必多说，地球人都知道！键盘上每一个有意义的键都对应着一个唯一的标识值，称之为<b style="">扫描码</b>。但是这种扫描码是硬件相关的，为了实现设备无关性的要求，在</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">应用程序中，使用的往往是与设备无关的<b style="">虚拟码</b>。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span style="font-family: 宋体;">对键盘操作的响应过程基本如下：</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span style="font-family: 宋体;">用户按下一个键时，与键盘驱动程序（</span>
				<span lang="EN-US">KEYBOARD.DRV</span>
				<span style="font-family: 宋体;">）进行中断处理并调用</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">用户模块（</span>
				<span lang="EN-US">USER.EXE</span>
				<span style="font-family: 宋体;">）中的有关程序来生成键盘消息，然后消息被发送到系统的消息队列中由相应的应用应用程序进行处理。鼠标的处理过程与键盘类似。但是注意无论是鼠标还是键盘的所产生的消息经过操作系统处理后都只会被发送给特定的窗口，即具有“输入焦点”的窗口来进行处理。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt;">
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style=""><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">           </span></span>
				</span>
				<b style="">
						<span style="font-family: 宋体;">键盘消息</span>
						<span lang="EN-US">
								<br />
						</span>
				</b>
				<span style="font-family: 宋体;">键盘消息通常可分为按键消息和字符消息两类，用户按下或松开一个键时，就产生一个按键消息，当一个按键组合产生了一个可以显示的字条时，就产生了一个字符消息。</span>
				<b style="">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</b>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">按键消息一般又可以分为系统按键和非系统按键。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">系统按键：是指使用了</span>
				<span lang="EN-US">Alt</span>
				<span style="font-family: 宋体;">等与相关输入键组成产生的消息，一般这些消息都由操作系统内部直接处理。如果应用程序处理了这些系统键消息，就要调用</span>
				<span lang="EN-US">DefWindowProc</span>
				<span style="font-family: 宋体;">函数，以便不影响</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">对它们的处理。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">非系统按键：对应于那些不使用组合键的按键消息。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">再对按键消息的两个变量</span>
				<span lang="EN-US">wParam</span>
				<span style="font-family: 宋体;">和</span>
				<span lang="EN-US">lParam</span>
				<span style="font-family: 宋体;">做一些解释：（名堂还真不少</span>
				<span lang="EN-US">T_T</span>
				<span style="font-family: 宋体;">）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">         </span></span>
				</span>
				<span lang="EN-US">wParam<br /></span>
				<span style="font-family: 宋体;">包含了识别按下键的虚键码，这些码是由系统定义的设备无关的。可以在</span>
				<span lang="EN-US">windows.h</span>
				<span style="font-family: 宋体;">中找到找到相关定义。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">         </span></span>
				</span>
				<span lang="EN-US">lParam<br />32</span>
				<span style="font-family: 宋体;">位的变量</span>
				<span lang="EN-US">lParam</span>
				<span style="font-family: 宋体;">所表示的含义可以分为以下</span>
				<span lang="EN-US">7</span>
				<span style="font-family: 宋体;">个部分</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(1)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">重复计数位（</span>
				<span lang="EN-US">0~15</span>
				<span style="font-family: 宋体;">位）</span>
				<span lang="EN-US">
						<span style="">      </span>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: 21pt;">
				<span style="font-family: 宋体;">表示当前消息的重复次数。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(2)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span lang="EN-US">OEM</span>
				<span style="font-family: 宋体;">扫描码（</span>
				<span lang="EN-US">16~23</span>
				<span style="font-family: 宋体;">位）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: 21pt;">
				<span lang="EN-US">OEM</span>
				<span style="font-family: 宋体;">扫描码是键盘发送的码值，因为是设备相关的帮一般被忽略掉。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(3)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">扩展键标志（</span>
				<span lang="EN-US">24</span>
				<span style="font-family: 宋体;">位）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: 21pt;">
				<span style="font-family: 宋体;">在有</span>
				<span lang="EN-US">Alt</span>
				<span style="font-family: 宋体;">或</span>
				<span lang="EN-US">Ctrl</span>
				<span style="font-family: 宋体;">键按下时为</span>
				<span lang="EN-US">1,</span>
				<span style="font-family: 宋体;">否则为</span>
				<span lang="EN-US">0</span>
				<span style="font-family: 宋体;">。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(4)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">保留位（</span>
				<span lang="EN-US">25~28</span>
				<span style="font-family: 宋体;">位）</span>
				<span lang="EN-US">
						<span style="">           </span>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: 21pt;">
				<span style="font-family: 宋体;">系统保留，一般不用。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(5)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">关联码（</span>
				<span lang="EN-US">29</span>
				<span style="font-family: 宋体;">位）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">主要用来记录某键与</span>
				<span lang="EN-US">Alt</span>
				<span style="font-family: 宋体;">等键的组合状态，若按下</span>
				<span lang="EN-US">Alt</span>
				<span style="font-family: 宋体;">键，当</span>
				<span lang="EN-US">WM_SYSKEYDOWN</span>
				<span style="font-family: 宋体;">消息发送到某个激活窗口时，其值为</span>
				<span lang="EN-US">1,</span>
				<span style="font-family: 宋体;">否则为</span>
				<span lang="EN-US">0</span>
				<span style="font-family: 宋体;">。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(6)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">键的先前状态（</span>
				<span lang="EN-US">30</span>
				<span style="font-family: 宋体;">位）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: 21pt;">
				<span style="font-family: 宋体;">用于记录先前某键的状态。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(7)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">      </span></span>
				</span>
				<span style="font-family: 宋体;">转换状态（</span>
				<span lang="EN-US">31</span>
				<span style="font-family: 宋体;">位）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">用于记录被始终按下的某键所产生的消息。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span lang="EN-US">
						<span style="">       </span>
				</span>
				<span style="font-family: 宋体;">在</span>
				<span lang="EN-US">WinMain</span>
				<span style="font-family: 宋体;">函数里的消息循环中包含了</span>
				<b style="">
						<span lang="EN-US">TranslateMessage</span>
				</b>
				<span style="font-family: 宋体;">函数，它的主要功能是把按键消息转化为字符消息，即把按键所产生的原始的KEYDOWN/KEYUP消息转化成WM_CHAR消息。</span>
				<span lang="EN-US">
				</span>
				<span style="font-family: 宋体;">
				</span>
				<span lang="EN-US">
						<span style="">
						</span>
				</span>
				<span style="font-family: 宋体;">
				</span>
				<span lang="EN-US">
				</span>
				<span style="font-family: 宋体;">同样，字符消息也可以分为系统和非系统消息两类。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span lang="EN-US">Windows</span>
				<span style="font-family: 宋体;">系统支持两类字符集：</span>
				<span lang="EN-US">OEM</span>
				<span style="font-family: 宋体;">和</span>
				<span lang="EN-US">ANSI</span>
				<span style="font-family: 宋体;">。</span>
				<span lang="EN-US">OEM</span>
				<span style="font-family: 宋体;">是</span>
				<span lang="EN-US">IBM</span>
				<span style="font-family: 宋体;">的字符集，在</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">中使用不多，目前大多使用的是</span>
				<span lang="EN-US">ANSI</span>
				<span style="font-family: 宋体;">字符集。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt;">
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style=""><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">           </span></span>
				</span>
				<b style="">
						<span style="font-family: 宋体;">鼠标消息</span>
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</b>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">         </span></span>
				</span>
				<span style="font-family: 宋体;">鼠标操作</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">简单的单击操作包含了按下和松开这一全过程；而双击操作实际上是指用户在知时间内（默认为</span>
				<span lang="EN-US">0.5</span>
				<span style="font-family: 宋体;">秒）的再次单击操作。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">在鼠标消息中，参数</span>
				<span lang="EN-US">lParam</span>
				<span style="font-family: 宋体;">包含了鼠标的位置，低字节是</span>
				<span lang="EN-US">X</span>
				<span style="font-family: 宋体;">坐标，高字节是</span>
				<span lang="EN-US">Y</span>
				<span style="font-family: 宋体;">坐标。参数</span>
				<span lang="EN-US">wParam</span>
				<span style="font-family: 宋体;">则包含了一个指示各种虚键状态的值。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">通过用户区消息的</span>
				<span lang="EN-US">wParam</span>
				<span style="font-family: 宋体;">和</span>
				<span lang="EN-US">lParam</span>
				<span style="font-family: 宋体;">参数，程序员就可以确定鼠标的位置和状态。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">对于鼠标的消息处理，一般分为两种，一种要对</span>
				<span lang="EN-US">Ctrl</span>
				<span style="font-family: 宋体;">等键进行监视，另一种则不需要。下面是一个示例</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">case WM_LbUTTONDWON:<span style="">       </span>//</span>
				<span style="font-family: 宋体;">鼠标按下时</span>
				<span lang="EN-US">ctrl</span>
				<span style="font-family: 宋体;">和</span>
				<span lang="EN-US">shift</span>
				<span style="font-family: 宋体;">都被按下</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>If(( wParam&amp;MK_CONTROL) &amp;&amp; ( wParam&amp;MK_SHIFT) )</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>…</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>break;</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">case WM_LBUTTONDOWN:<span style="">       </span>//</span>
				<span style="font-family: 宋体;">不监视组合按键</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>…</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>break;</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">此外，要使窗口能监视双击消息，必须在注册窗口类的时候使该类具有</span>
				<span lang="EN-US">CS_DBLCLKS</span>
				<span style="font-family: 宋体;">属性才行，否则只能收到两条单击消息。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">         </span></span>
				</span>
				<span style="font-family: 宋体;">光标</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">可以使用系统光标或者调用</span>
				<span lang="EN-US">LoadCursor</span>
				<span style="font-family: 宋体;">加载自定义光标资源</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt;">
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style=""><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">           </span></span>
				</span>
				<b style="">
						<span style="font-family: 宋体;">示例程序</span>
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</b>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">在下面的一个例子中，显示鼠标和键盘的消息响应。程序的用户区被分为四个区域，每个区域里光标设置成不同的样式。通过监视键盘按键，可对一个</span>
				<span lang="EN-US">10</span>
				<span style="font-family: 宋体;">个字符长的缓冲区里输入字符，并最后显示在鼠标上方，鼠标移动时同时修改字符输出的位置。可以按下</span>
				<span lang="EN-US">BACK</span>
				<span style="font-family: 宋体;">键删掉已经输入的字符，缓冲区满时再输入和空的时候删字符的操作都被拒绝，并用消息框进行提示。代码如下：<br /></span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">定义的静态变量</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="color: rgb(0, 0, 255);">#define</span>
				<span style="color: rgb(0, 0, 0);"> BufSize 10</span>
				<span style="color: rgb(0, 0, 0);">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="color: rgb(0, 0, 255);">static</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">char</span>
				<span style="color: rgb(0, 0, 0);"> lpszBuffer[BufSize];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="color: rgb(0, 0, 255);">static</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">int</span>
				<span style="color: rgb(0, 0, 0);"> nNumChar </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 0);">0</span>
				<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="color: rgb(0, 0, 255);">static</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">int</span>
				<span style="color: rgb(0, 0, 0);"> i </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 0);">0</span>
				<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="color: rgb(0, 0, 255);">static</span>
				<span style="color: rgb(0, 0, 0);"> POINT pt;<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" />LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                         UINT wParam, <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                         LONG lParam)<br /><img id="Codehighlighter1_215_1500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_215_1500_Open_Text.style.display='none'; Codehighlighter1_215_1500_Closed_Image.style.display='inline'; Codehighlighter1_215_1500_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_215_1500_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_215_1500_Closed_Text.style.display='none'; Codehighlighter1_215_1500_Open_Image.style.display='inline'; Codehighlighter1_215_1500_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_215_1500_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_215_1500_Open_Text">
						<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    HDC hdc;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    PAINTSTRUCT ps;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    HCURSOR hCur;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="color: rgb(0, 0, 255);">switch</span>
						<span style="color: rgb(0, 0, 0);">(iMsg)<br /><img id="Codehighlighter1_274_1487_Open_Image" onclick="this.style.display='none'; Codehighlighter1_274_1487_Open_Text.style.display='none'; Codehighlighter1_274_1487_Closed_Image.style.display='inline'; Codehighlighter1_274_1487_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_274_1487_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_274_1487_Closed_Text.style.display='none'; Codehighlighter1_274_1487_Open_Image.style.display='inline'; Codehighlighter1_274_1487_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_274_1487_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_274_1487_Open_Text">
								<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="color: rgb(0, 0, 255);">case</span>
								<span style="color: rgb(0, 0, 0);"> WM_CHAR:</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">处理非系统键的消息</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(wParam </span>
								<span style="color: rgb(0, 0, 0);">==</span>
								<span style="color: rgb(0, 0, 0);"> VK_BACK)</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">按下退格键</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img id="Codehighlighter1_335_526_Open_Image" onclick="this.style.display='none'; Codehighlighter1_335_526_Open_Text.style.display='none'; Codehighlighter1_335_526_Closed_Image.style.display='inline'; Codehighlighter1_335_526_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_335_526_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_335_526_Closed_Text.style.display='none'; Codehighlighter1_335_526_Open_Image.style.display='inline'; Codehighlighter1_335_526_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        </span>
								<span id="Codehighlighter1_335_526_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_335_526_Open_Text">
										<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="color: rgb(0, 0, 255);">if</span>
										<span style="color: rgb(0, 0, 0);">(nNumChar </span>
										<span style="color: rgb(0, 0, 0);">==</span>
										<span style="color: rgb(0, 0, 0);"> </span>
										<span style="color: rgb(0, 0, 0);">0</span>
										<span style="color: rgb(0, 0, 0);">)<br /><img id="Codehighlighter1_361_414_Open_Image" onclick="this.style.display='none'; Codehighlighter1_361_414_Open_Text.style.display='none'; Codehighlighter1_361_414_Closed_Image.style.display='inline'; Codehighlighter1_361_414_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_361_414_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_361_414_Closed_Text.style.display='none'; Codehighlighter1_361_414_Open_Image.style.display='inline'; Codehighlighter1_361_414_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_361_414_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_361_414_Open_Text">
												<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                MessageBox(hWnd, </span>
												<span style="color: rgb(0, 0, 0);">"</span>
												<span style="color: rgb(0, 0, 0);">没有字符可以删除！</span>
												<span style="color: rgb(0, 0, 0);">"</span>
												<span style="color: rgb(0, 0, 0);">, NULL, MB_OK);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="color: rgb(0, 0, 0);">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="color: rgb(0, 0, 255);">else</span>
										<span style="color: rgb(0, 0, 0);">
												<br />
												<img id="Codehighlighter1_427_512_Open_Image" onclick="this.style.display='none'; Codehighlighter1_427_512_Open_Text.style.display='none'; Codehighlighter1_427_512_Closed_Image.style.display='inline'; Codehighlighter1_427_512_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_427_512_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_427_512_Closed_Text.style.display='none'; Codehighlighter1_427_512_Open_Image.style.display='inline'; Codehighlighter1_427_512_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_427_512_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_427_512_Open_Text">
												<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="color: rgb(0, 0, 0);">--</span>
												<span style="color: rgb(0, 0, 0);">nNumChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="color: rgb(0, 128, 0);">//</span>
												<span style="color: rgb(0, 128, 0);">此函数刷新用户区，会产生PAINT消息</span>
												<span style="color: rgb(0, 128, 0);">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="color: rgb(0, 0, 0);">                InvalidateRect(hWnd, NULL, TRUE);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="color: rgb(0, 0, 0);">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="color: rgb(0, 0, 255);">break</span>
										<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(nNumChar </span>
								<span style="color: rgb(0, 0, 0);">&gt;=</span>
								<span style="color: rgb(0, 0, 0);"> BufSize)</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">字符超过缓冲区大小</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img id="Codehighlighter1_567_634_Open_Image" onclick="this.style.display='none'; Codehighlighter1_567_634_Open_Text.style.display='none'; Codehighlighter1_567_634_Closed_Image.style.display='inline'; Codehighlighter1_567_634_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_567_634_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_567_634_Closed_Text.style.display='none'; Codehighlighter1_567_634_Open_Image.style.display='inline'; Codehighlighter1_567_634_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        </span>
								<span id="Codehighlighter1_567_634_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_567_634_Open_Text">
										<span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            MessageBox(hWnd, </span>
										<span style="color: rgb(0, 0, 0);">"</span>
										<span style="color: rgb(0, 0, 0);">缓冲区已满！删除字符请用退格键</span>
										<span style="color: rgb(0, 0, 0);">"</span>
										<span style="color: rgb(0, 0, 0);">, NULL, MB_OK);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="color: rgb(0, 0, 255);">break</span>
										<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        lpszBuffer[nNumChar</span>
								<span style="color: rgb(0, 0, 0);">++</span>
								<span style="color: rgb(0, 0, 0);">] </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> (unsigned </span>
								<span style="color: rgb(0, 0, 255);">char</span>
								<span style="color: rgb(0, 0, 0);">)wParam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        InvalidateRect(hWnd, NULL, TRUE);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">break</span>
								<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="color: rgb(0, 0, 255);">case</span>
								<span style="color: rgb(0, 0, 0);"> WM_PAINT:</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">将处理过的字符输出</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        hdc </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> BeginPaint(hWnd, </span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);">ps);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">调整坐标使字出现在鼠标上方</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">         TextOut(hdc, pt.x</span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);">15</span>
								<span style="color: rgb(0, 0, 0);">, pt.y</span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);">15</span>
								<span style="color: rgb(0, 0, 0);">, lpszBuffer, nNumChar);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        EndPaint(hWnd, </span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);">ps);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">break</span>
								<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="color: rgb(0, 0, 255);">case</span>
								<span style="color: rgb(0, 0, 0);"> WM_MOUSEMOVE:</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">移动鼠标后改变文本输出坐标并刷新</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        pt.x </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> LOWORD(lParam);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        pt.y </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> HIWORD(lParam);</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">鼠标的坐标<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">在不同的区域显示不同的光标</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="color: rgb(0, 0, 0);">        </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(pt.x </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&amp;&amp;</span>
								<span style="color: rgb(0, 0, 0);"> pt.y </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            hCur </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> LoadCursor(NULL, IDC_NO);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">else</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(pt.x </span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&amp;&amp;</span>
								<span style="color: rgb(0, 0, 0);"> pt.y </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            hCur </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> LoadCursor(NULL, IDC_HELP);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">else</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(pt.x </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> pt.y </span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            hCur </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> LoadCursor(NULL, IDC_SIZEALL);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">else</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 255);">if</span>
								<span style="color: rgb(0, 0, 0);">(pt.x </span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&amp;&amp;</span>
								<span style="color: rgb(0, 0, 0);"> pt.y </span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">400</span>
								<span style="color: rgb(0, 0, 0);">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            hCur </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> LoadCursor(NULL, IDC_CROSS);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        SetCursor(hCur);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        InvalidateRect(hWnd, NULL, TRUE);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">break</span>
								<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="color: rgb(0, 0, 255);">case</span>
								<span style="color: rgb(0, 0, 0);"> WM_DESTROY:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        PostQuitMessage(</span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="color: rgb(0, 0, 255);">default</span>
								<span style="color: rgb(0, 0, 0);">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> (DefWindowProc(hWnd, iMsg, wParam, lParam));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="color: rgb(0, 0, 255);">return</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 0);">0</span>
						<span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/sunshinealike/aggbug/76346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-03-12 16:17 <a href="http://www.cppblog.com/sunshinealike/archive/2009/03/12/76346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WindowsAPI学习笔记三 - 字体设置与输出</title><link>http://www.cppblog.com/sunshinealike/archive/2009/03/11/76242.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Wed, 11 Mar 2009 08:41:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/03/11/76242.html</guid><description><![CDATA[
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">
				<span lang="EN-US">Windows</span>
				<span style="font-family: 宋体;">系统中经常使用</span>
				<span lang="EN-US">GDI</span>
				<span style="font-family: 宋体;">进行文本输出，从某种意义上来说，图形和文本并没有本质上的界限，很多时候</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">把文本也当作图形对待。在</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">编程中，文本操作首先要获得文本句柄，此外，还要设置字体，字符大小，字符颜色等有关属性，并将它们选入设备环境。</span>
				<span lang="EN-US">
						<br style="" />
						<br style="" />
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt;">
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style=""><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">           </span></span>
				</span>
				<b style="">
						<span style="font-family: 宋体;">设置文本的设备环境</span>
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</b>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span>
				</span>
				<span style="font-family: 宋体;">自定义字体</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">可以使用函数</span>
				<span lang="EN-US">CreateFont</span>
				<span style="font-family: 宋体;">自定义字体</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">HFONT hFont = HFONT CreateFont(</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>int nHeight,<span style="">  </span>int nWidth,<span style="">                 </span>// </span>
				<span style="font-family: 宋体;">字体高，宽</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>int nEscapement,<span style="">           </span>// </span>
				<span style="font-family: 宋体;">文字相对于页底的角度</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>int nOrientation,<span style="">        </span>// </span>
				<span style="font-family: 宋体;">每个文字相对于页底的角度</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>int fnWeight,<span style="">         </span>// </span>
				<span style="font-family: 宋体;">字体粗细，范围</span>
				<span lang="EN-US">0~1000</span>
				<span style="font-family: 宋体;">，</span>
				<span lang="EN-US">400</span>
				<span style="font-family: 宋体;">为正常字体，</span>
				<span lang="EN-US">700</span>
				<span style="font-family: 宋体;">为黑体</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwItalic,<span style="">           </span>// </span>
				<span style="font-family: 宋体;">取非零值则为斜体</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwUnderline,<span style="">        </span>// </span>
				<span style="font-family: 宋体;">取非零值则下划线</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwStrikeOut,<span style="">        </span>// </span>
				<span style="font-family: 宋体;">取非零值则中划线</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwCharSet,<span style="">          </span>// </span>
				<span style="font-family: 宋体;">字体所属字符集</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwOutputPrecision,<span style="">  </span>// </span>
				<span style="font-family: 宋体;">输出精度（一般取默认值）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwClipPrecision,<span style="">    </span>// </span>
				<span style="font-family: 宋体;">剪裁精度（一般取默认值）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwQuality,<span style="">          </span>// </span>
				<span style="font-family: 宋体;">输出质量（一般取默认值）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>DWORD fdwPitchAndFamily,<span style="">   </span>// </span>
				<span style="font-family: 宋体;">字体间距及字体系列（一般取默认值）</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LPCTSTR lpszFace<span style="">           </span>// </span>
				<span style="font-family: 宋体;">字体名</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">);<br /></span>
				<span style="font-family: 宋体;">这个这个......以后这样建字体还不累死才怪咧！而且貌似</span>
				<span lang="EN-US">API</span>
				<span style="font-family: 宋体;">里带这么多恶心参数的方法还不少，了解一下就行了。一般情况下使用系统默认提供的字体就可以了。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span>
				</span>
				<span style="font-family: 宋体;">字体句柄</span>
				<span lang="EN-US">
						<br />windows</span>
				<span style="font-family: 宋体;">系统提供了七种基本字体：</span>
				<span lang="EN-US">
						<br />ANSI_FIXED_FONT</span>
				<span style="font-family: 宋体;">，</span>
				<span lang="EN-US">DEFAULT_GUI_FONT</span>
				<span style="font-family: 宋体;">，</span>
				<span lang="EN-US">ANSI_VAR_FONT<br />DEVICE_DEFAULT_FONT</span>
				<span style="font-family: 宋体;">，</span>
				<span lang="EN-US">SYSTEM_FIXED_FONT</span>
				<span style="font-family: 宋体;">，</span>
				<span lang="EN-US">
						<br />SYSTEM_FONT</span>
				<span style="font-family: 宋体;">（系统默认字体）</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">调用函数</span>
				<span lang="EN-US">GetStockObject</span>
				<span style="font-family: 宋体;">（）即可获得系统默认字体</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">获得字体之后，有时候还需要设置字体颜色和背景色，可以使用下面两个函数：</span>
				<span lang="EN-US">
						<br />SetTextColor<span style="">          </span>//</span>
				<span style="font-family: 宋体;">设置字体颜色</span>
				<span lang="EN-US">
						<br />SetBkColor<span style="">            </span>//</span>
				<span style="font-family: 宋体;">设置背景颜色</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt;">
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style=""><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">           </span></span>
				</span>
				<b style="">
						<span style="font-family: 宋体;">文本输出过程</span>
						<span lang="EN-US">
								<br />
						</span>
				</b>
				<span style="font-family: 宋体;">设置了字体句柄，字体及字体颜色之后就可以把设置字体输入到相应的设备上。</span>
				<span lang="EN-US">Windows</span>
				<span style="font-family: 宋体;">系统在文本输出上有点小小的偷懒，把很多事情都丢给了程序员来做，应用程序必须自己管理换行，后续字符的位置等输出格式。虽提供了编程的自由，但是程序员的工作量也变的非常大。</span>
				<b style="">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</b>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 21pt;">
				<span style="font-family: 宋体;">文本输出过程包括获取字体信息，格式化文本，调用函数输出文本等过程。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span>
				</span>
				<span style="font-family: 宋体;">获取字体信息</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">应用程序在输出字体之前必须先获取当前字体的有关信息，在</span>
				<span lang="EN-US">windows</span>
				<span style="font-family: 宋体;">程序中通过调用</span>
				<span lang="EN-US">GetTextMetrics</span>
				<span style="font-family: 宋体;">函数来获取当前字体的信息。其形式为：</span>
				<span lang="EN-US">
						<br />GetTextMetrics(hdc, &amp;tm);<span style="">          </span>//tm</span>
				<span style="font-family: 宋体;">为</span>
				<span lang="EN-US">TEXTMETRIC</span>
				<span style="font-family: 宋体;">结构</span>
				<span lang="EN-US">
						<br />TEXTMETRIC</span>
				<span style="font-family: 宋体;">结构也非常复杂，其结构定义如下：</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">typedef struct tagTEXTMETRIC { </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmHeight; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmAscent; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmDescent; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmInternalLeading; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmExternalLeading; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmAveCharWidth; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmMaxCharWidth; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmWeight; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmOverhang; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmDigitizedAspectX; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>LONG tmDigitizedAspectY; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>TCHAR tmFirstChar; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>TCHAR tmLastChar; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>TCHAR tmDefaultChar; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>TCHAR tmBreakChar; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>BYTE tmItalic; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>BYTE tmUnderlined; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>BYTE tmStruckOut; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>BYTE tmPitchAndFamily; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">  </span>BYTE tmCharSet; </span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">} TEXTMETRIC, *PTEXTMETRIC;</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span style="font-family: 宋体;">具体各属性不解释，需要时可以查询</span>
				<span lang="EN-US">MSDN</span>
				<span style="font-family: 宋体;">。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span>
				</span>
				<span style="font-family: 宋体;">格式化文本</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">格式化处理一般针对两种情况，一是文本行中确定后续文本的坐标，二是在换行时确定下一行的坐标。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(1)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span>
				</span>
				<span style="font-family: 宋体;">确定后续文本坐标</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span style="font-family: 宋体;">应先获取当前字符的宽度，通过计算字符串起始坐标与字符串宽度之和即可得到后续文本的起始坐标。</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">这里要使用到函数：</span>
				<span lang="EN-US">
						<br />BOOL GetTextExtentPoint32</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">(</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>HDC hdc,</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>LPCTSTR lpsxString,<span style="">    </span>//</span>
				<span style="font-family: 宋体;">指定的字符串</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>int nLength,<span style="">                  </span>//</span>
				<span style="font-family: 宋体;">字符串中字符数</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">
						<span style="">       </span>LPSIZE lpSize<span style="">        </span>//</span>
				<span style="font-family: 宋体;">字符串宽度及高度的</span>
				<span lang="EN-US">SIZE</span>
				<span style="font-family: 宋体;">数据结构</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt;">
				<span lang="EN-US">)</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">(2)<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span>
				</span>
				<span style="font-family: 宋体;">确定换行时文本坐标</span>
				<span lang="EN-US">
						<br />
				</span>
				<span style="font-family: 宋体;">通过计算当前文本行字符的高度与行间隔之和，即可得到换行时文本的起始坐标，而上述两个数值均可通过获取当前字体信息得到。</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;">
				<span style="" lang="EN-US">
						<span style="">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span>
				</span>
				<span style="font-family: 宋体;">文本输出</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span style="font-family: 宋体;">最常用的文本输出函数就是</span>
				<span lang="EN-US">TextOut</span>
				<span style="font-family: 宋体;">，其原型如下：</span>
				<span lang="EN-US">
						<br />BOOL TextOut</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">(</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">       </span>HDC hdc,</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">       </span>int x, int y,</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">       </span>LPCTSTR lpString,</span>
		</p>
		<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt;">
				<span lang="EN-US">
						<span style="">       </span>int nCount</span>
		</p>      
)<br /><br /><br /><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CAtlas%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]--><style><!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;
	mso-font-charset:2;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:0 268435456 0 0 -2147483648 0;}
@font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:36.0pt;
	mso-footer-margin:36.0pt;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:370768441;
	mso-list-type:hybrid;
	mso-list-template-ids:-520222266 1657045614 67698703 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:21.0pt;
	mso-level-number-position:left;
	margin-left:21.0pt;
	text-indent:-21.0pt;
	font-family:Wingdings;}
@list l0:level2
	{mso-level-tab-stop:21.0pt;
	mso-level-number-position:left;
	margin-left:21.0pt;
	text-indent:-21.0pt;}
@list l0:level3
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:42.0pt;
	mso-level-number-position:left;
	margin-left:42.0pt;
	text-indent:-21.0pt;
	font-family:Wingdings;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
--></style><!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]--><p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;"><!--[if !supportLists]--><span style="font-family: Wingdings;" lang="EN-US"><span style=""><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">          
</span></span></span><!--[endif]--><b style=""><span style="font-family: 宋体;">文本操作实例</span><span lang="EN-US"><o:p></o:p></span></b></p><p class="MsoNormal" style="margin-left: 21pt;"><span style="font-family: 宋体;">因为代码太长，全部贴出来页面不好看。故只给出</span><b style=""><span lang="EN-US">WndProc</span></b><span style="font-family: 宋体;">函数的实现，程序其它部分可以参考以前的笔记。</span></p><p class="MsoNormal" style="margin-left: 21pt;"><span style="font-family: 宋体;"><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, <br />                         UINT wParam, <br />                         LONG lParam)<br />{<br />    HDC hdc;<br />    HFONT hFont;    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字体句柄</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    PAINTSTRUCT ps;<br />    TEXTMETRIC tm;<br /><br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> lpszTx1[] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">红色的SYSTEM字体：好好学习，天天向上！</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> lpszTx2[] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">绿色自定义字体：保护眼睛，注意休息！</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> lpszTx3[] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">蓝色大号斜体并带有下划线！</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> lpszTx4[] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">两行文本输出到同一行里！</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> lpszTx5[] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">今天的学习就到这里，祝你成功！</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> x </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, y </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />    SIZE size;<br />    </span><span style="color: rgb(0, 0, 255);">switch</span><span style="color: rgb(0, 0, 0);">(iMsg)<br />    {<br /><br />    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> WM_PAINT:<br />            hdc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> BeginPaint(hWnd, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ps);<br /><br />            SetTextColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">));</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">文本为红色</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            TextOut(hdc, x, y, lpszTx1, strlen(lpszTx1));</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字体输出</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />            GetTextMetrics(hdc, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">tm);    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取系统当前字体</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            y </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> y </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> tm.tmHeight </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> tm.tmExternalLeading;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">计算下一行坐标</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            hFont </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateFont<br />                        (<br />                            </span><span style="color: rgb(0, 0, 0);">20</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">高度20, 宽取0表示由系统选择最佳值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">文本倾斜，与字体倾斜都为0</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            FW_HEAVY,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">粗体</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">非斜体，无下划线，无中划线</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            GB2312_CHARSET,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字符集</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            OUT_DEFAULT_PRECIS,        <br />                            CLIP_DEFAULT_PRECIS,        <br />                            DEFAULT_QUALITY,        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">一系列的默认值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            DEFAULT_PITCH </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> FF_DONTCARE,    <br />                            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">自定义字体</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字体名称</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                        );<br />            SetTextColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">));<br />            SelectObject(hdc, hFont);<br />            TextOut(hdc, x, y, lpszTx2, strlen(lpszTx2));<br /><br />            GetTextMetrics(hdc, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">tm);    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">将当前字体信息选入tm结构中</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            y </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> y </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> tm.tmHeight </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">15</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> tm.tmExternalLeading;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">5倍行间距</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            hFont </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CreateFont<br />                        (<br />                            </span><span style="color: rgb(0, 0, 0);">40</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">高度40, 宽取0表示由系统选择最佳值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">文本倾斜，与字体倾斜都为0</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            FW_NORMAL,    <br />                            </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">斜体，下划线，无中划线</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            GB2312_CHARSET,    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字符集</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            OUT_DEFAULT_PRECIS,    <br />                            CLIP_DEFAULT_PRECIS,    <br />                            DEFAULT_QUALITY,        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">一系列的默认值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                            DEFAULT_PITCH </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> FF_DONTCARE,    <br />                            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">大号字体</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字体名称</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                        );<br />            SetTextColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">));<br />            SetBkColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">160</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">160</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">160</span><span style="color: rgb(0, 0, 0);">));</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">设置背景颜色</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            SelectObject(hdc, hFont);<br />            TextOut(hdc, x, y, lpszTx3, strlen(lpszTx3));<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取系统提供的字体</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            hFont </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HFONT)GetStockObject(SYSTEM_FIXED_FONT);<br />            y </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> y </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> tm.tmHeight </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> tm.tmExternalLeading;<br />            SetTextColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">));<br />            SetBkColor(hdc, RGB(</span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">));<br />            SelectObject(hdc, hFont);<br />            TextOut(hdc, x, y, lpszTx4, strlen(lpszTx4));<br />            GetTextExtentPoint32(hdc, lpszTx4, strlen(lpszTx4), </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">size);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">计算高宽</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            x </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> x </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> size.cx;<br />            TextOut(hdc, x , y ,lpszTx5, strlen(lpszTx5));<br /><br />            EndPaint(hWnd, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ps);<br />            DeleteObject(hFont);<br />            </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> WM_DESTROY:<br />        PostQuitMessage(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);">:<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> DefWindowProc(hWnd, iMsg, wParam, lParam);<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}</span></div><br /></span></p><br /><img src ="http://www.cppblog.com/sunshinealike/aggbug/76242.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-03-11 16:41 <a href="http://www.cppblog.com/sunshinealike/archive/2009/03/11/76242.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WindowsAPI学习笔记二 - 图形设备接口及windows绘图</title><link>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76148.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Tue, 10 Mar 2009 13:09:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76148.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/76148.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76148.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/76148.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/76148.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Windows				图形设备接口（				Graphics Device Interface, GDI				）是为与设备无关的图形设计的，由操作系统屏蔽了硬件设备的差异，简化了程序员的程序编写工作。														 																		           														设备上下文（		...&nbsp;&nbsp;<a href='http://www.cppblog.com/sunshinealike/archive/2009/03/10/76148.html'>阅读全文</a><img src ="http://www.cppblog.com/sunshinealike/aggbug/76148.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-03-10 21:09 <a href="http://www.cppblog.com/sunshinealike/archive/2009/03/10/76148.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WindowsAPI学习笔记一 - Windows应用程序基本结构</title><link>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76050.html</link><dc:creator>Sunshine Alike</dc:creator><author>Sunshine Alike</author><pubDate>Tue, 10 Mar 2009 04:42:00 GMT</pubDate><guid>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76050.html</guid><wfw:comment>http://www.cppblog.com/sunshinealike/comments/76050.html</wfw:comment><comments>http://www.cppblog.com/sunshinealike/archive/2009/03/10/76050.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/sunshinealike/comments/commentRss/76050.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/sunshinealike/services/trackbacks/76050.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Windows				应用程序基本结构																												一个完整的				windos				应用程序通常由下面五种类型的文件组成：														1.         								扩展名为				.c/.cpp				的Ｃ语言程序源文件										...&nbsp;&nbsp;<a href='http://www.cppblog.com/sunshinealike/archive/2009/03/10/76050.html'>阅读全文</a><img src ="http://www.cppblog.com/sunshinealike/aggbug/76050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/sunshinealike/" target="_blank">Sunshine Alike</a> 2009-03-10 12:42 <a href="http://www.cppblog.com/sunshinealike/archive/2009/03/10/76050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>