﻿<?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++博客-Beginning to 编程-随笔分类-关键代码</title><link>http://www.cppblog.com/richardzeng/category/1013.html</link><description>VC++ 方面编程文章</description><language>zh-cn</language><lastBuildDate>Thu, 22 May 2008 23:30:50 GMT</lastBuildDate><pubDate>Thu, 22 May 2008 23:30:50 GMT</pubDate><ttl>60</ttl><item><title>MFC 容器类对象的序列化问题</title><link>http://www.cppblog.com/richardzeng/archive/2006/05/15/7223.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Mon, 15 May 2006 14:14:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/05/15/7223.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/7223.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/05/15/7223.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/7223.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/7223.html</trackback:ping><description><![CDATA[
		<p>设计一个程序实现如何保存一系列的SPen（如下定义）对象到文件，或者称为序列化SPen collection<br /><br />SPenCollection::Load和 Save函数实现打开画笔文件（文件的内容是一系列SPen对象）<br />// for example<br /> SPenCollection pc;<br /> pc.Load("C:\\1.pen");<br /><br />我不知道如何序列化容器类对象，请大虾指教。<br /><br /><br /><br />// SPen object<br />class SPen : public CObject<br />{<br /> DECLARE_SERIAL(SPen)<br />public:<br /> SPen();<br /> virtual ~SPen();</p>
		<p>public:<br /> int lineStyle;<br /> int lineWidth;<br /> COLORREF lineColor;<br />public:<br /> virtual void Serialize(CArchive&amp; ar);<br />};<br /><br /><br />// SPen.cpp : 实现文件<br />//</p>
		<p>#include "stdafx.h"<br />#include "ArchiveTest.h"<br />#include "SPen.h"</p>
		<p>
				<br />// SPen<br />IMPLEMENT_SERIAL(SPen,CObject,1)</p>
		<p>SPen::SPen()<br />{<br /> lineStyle = PS_SOLID;<br /> lineWidth = 2;<br /> lineColor = RGB(255,0,0);<br />}</p>
		<p>SPen::~SPen()<br />{<br />}</p>
		<p>
				<br />// SPen 成员函数</p>
		<p>void SPen::Serialize(CArchive&amp; ar)<br />{<br /> if (ar.IsStoring())<br /> { // storing code<br />  ar&lt;&lt;lineStyle;<br />  ar&lt;&lt;lineWidth;<br />  ar&lt;&lt;lineColor;<br /> }<br /> else<br /> { // loading code<br />  ar&gt;&gt;lineStyle;<br />  ar&gt;&gt;lineWidth;<br />  ar&gt;&gt;lineColor;<br /> }<br />}<br /><br /><br />///////////////////////////////////////<br />// 关键是要实现如何保存一系列的SPen对象<br />// load 和 save函数实现打开画笔文件（文件的内容是一系列SPen对象）<br />// for example<br />/** SPenCollection pc;<br />   pc.Load("C:\\1.pen");<br /> **/<br /><br />#pragma once</p>
		<p>// SPenCollection 命令目标</p>
		<p>#include "SPen.h"<br />#include &lt;afxtempl.h&gt;</p>
		<p>class SPenCollection : public CObject<br />{<br /> DECLARE_SERIAL(SPenCollection)<br />public:<br /> SPenCollection();<br /> virtual ~SPenCollection();<br /><br /> void AddPen(SPen* pen);</p>
		<p> void Load(CString strFileName);<br /> void Save(CString strFileName);</p>
		<p>// CArray 不知道用得对不对，请大虾指教<br /> CArray&lt;SPen*,SPen*&gt; pens;<br />};</p>
		<p>
				<br /> </p>
<img src ="http://www.cppblog.com/richardzeng/aggbug/7223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-05-15 22:14 <a href="http://www.cppblog.com/richardzeng/archive/2006/05/15/7223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>boost serialize 和 ostream 问题  </title><link>http://www.cppblog.com/richardzeng/archive/2006/05/15/7202.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Mon, 15 May 2006 09:26:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/05/15/7202.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/7202.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/05/15/7202.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/7202.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/7202.html</trackback:ping><description><![CDATA[
		<div>
				<div>下面是Boost serialization 中的demo例子</div>
				<div>为何写了serialize 函数还写个ostream&lt;&lt;</div>
				<div>阿，</div>
				<div>我对ostream 不是很了解，</div>
				<div>我的印象是iostream 是在控制台里输入输出的</div>
				<div>//////////////////////////////<wbr>//////////////////////////////<wbr>/////////////////</wbr></wbr></div>
				<div>class gps_position<br />{<br />    friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp;os, const gps_position &amp;gp);<br />    friend class boost::serialization::access;<br />    int degrees;<br />    int minutes;<br />    float seconds;<br />    template&lt;class Archive&gt;<br />    void serialize(Archive &amp; ar, const unsigned int /* file_version */){<br />        ar &amp; degrees &amp; minutes &amp; seconds;<br />    }<br />public:<br />    // every serializable class needs a constructor <br />    gps_position(){};<br />    gps_position(int _d, int _m, float _s) : <br />        degrees(_d), minutes(_m), seconds(_s)<br />    {}<br />};<br />std::ostream &amp; operator&lt;&lt;(std::ostream &amp;os, const gps_position &amp;gp) <br />{<br />    return os &lt;&lt; ' ' &lt;&lt; gp.degrees &lt;&lt; (unsigned char)186 &lt;&lt; gp.minutes &lt;&lt; '\'' &lt;&lt; gp.seconds &lt;&lt; '"';<br />}</div>
		</div>
<img src ="http://www.cppblog.com/richardzeng/aggbug/7202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-05-15 17:26 <a href="http://www.cppblog.com/richardzeng/archive/2006/05/15/7202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>不能将“this”指针从“const Vector3D”转换为“Vector3D &amp;" 错误</title><link>http://www.cppblog.com/richardzeng/archive/2006/05/10/6876.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Wed, 10 May 2006 06:42:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/05/10/6876.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/6876.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/05/10/6876.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/6876.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/6876.html</trackback:ping><description><![CDATA[
		<p>我在VS2005中编译Vector3D类出现<br />error C2662: “Vector3D::dotP”: 不能将“this”指针从“const Vector3D”转换为“Vector3D &amp;”<br /><br />怎么样改正呢，这个类也是看到别人这样写的，编译也没有错误。<br /><br />#pragma once</p>
		<p>#define M_PI 3.141<br />#include &lt;math.h&gt;</p>
		<p>class Vector3D{<br /> Vector3D(){x=y=z=0.0;}<br /> Vector3D(double vx, double vy,double vz=0.0){<br />  x = vx;<br />  y = vy;<br />  z = vz;<br /> }<br /> <br /> double magnitude() const{<br />  return sqrt(x*x+y*y+z*z);<br /> }</p>
		<p> double dotP(const Vector3D&amp; v1,const Vector3D&amp; v2){<br />  return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);<br /> }</p>
		<p> // get the vector angle<br /> double angle() const{<br />  double ret = 0.0;<br />  double m = magnitude();</p>
		<p>  if (m&gt;1.0e-6) {<br /><br />// 问题出在这里！！！！<br />// ==============================<br />   double dp = dotP(*this,Vector3D(1.0,0.0));<br />//==============================</p>
		<p>   if (dp/m&gt;=1.0) {<br />    ret = 0.0;<br />   }<br />   else if (dp/m&lt;-1.0) {<br />    ret = M_PI;<br />   }<br />   else {<br />    ret = acos( dp / m);<br />   }<br />   if (y&lt;0.0) {<br />    ret = 2*M_PI - ret;<br />   }<br />  }<br />  return ret;<br /> }</p>
		<p>
				<br />protected:<br /> double x;<br /> double y;<br /> double z;</p>
		<p>};#pragma once</p>
		<p>#define M_PI 3.141<br />#include &lt;math.h&gt;</p>
		<p>class Vector3D{<br /> Vector3D(){x=y=z=0.0;}<br /> Vector3D(double vx, double vy,double vz=0.0){<br />  x = vx;<br />  y = vy;<br />  z = vz;<br /> }<br /> <br /> double magnitude() const{<br />  return sqrt(x*x+y*y+z*z);<br /> }</p>
		<p> double dotP(const Vector3D&amp; v1,const Vector3D&amp; v2){<br />  return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);<br /> }</p>
		<p> // get the vector angle<br /> double angle() const{<br />  double ret = 0.0;<br />  double m = magnitude();</p>
		<p>  if (m&gt;1.0e-6) {<br />   double dp = dotP(*this,Vector3D(1.0,0.0));</p>
		<p>   if (dp/m&gt;=1.0) {<br />    ret = 0.0;<br />   }<br />   else if (dp/m&lt;-1.0) {<br />    ret = M_PI;<br />   }<br />   else {<br />    ret = acos( dp / m);<br />   }<br />   if (y&lt;0.0) {<br />    ret = 2*M_PI - ret;<br />   }<br />  }<br />  return ret;<br /> }</p>
		<p>
				<br />protected:<br /> double x;<br /> double y;<br /> double z;</p>
		<p>};</p>
<img src ="http://www.cppblog.com/richardzeng/aggbug/6876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-05-10 14:42 <a href="http://www.cppblog.com/richardzeng/archive/2006/05/10/6876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>查错：下面的程序编译没问题，为什么运行会出错呢</title><link>http://www.cppblog.com/richardzeng/archive/2006/03/20/4389.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Mon, 20 Mar 2006 13:32:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/03/20/4389.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/4389.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/03/20/4389.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/4389.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/4389.html</trackback:ping><description><![CDATA[
		<p>最近在看吉林大学的C程序设计的课件，有一章讲到这个函数动手写了一下。<br /><br />题目：<br />编写一个Insert函数实现在字符串s中的第i个位置插入字符串s1；<br />在VC++2005中编译这段程序没有任何的Error和warning但是运行就会错误，不知道为什么阿，请高手指点一二。<br /><br />#include "stdafx.h"</p>
		<p>#include &lt;iostream&gt;<br />using namespace std;</p>
		<p>void Insert(char *s, char *s1, int i)<br />{<br /> char *p,*q;<br /> p = s + strlen(s); // p 指向s的末尾+1<br /> q = p + strlen(s1); //q 指向新构造的字符串的\0 <br /> *q = '\0';</p>
		<p> // <br /> for(p--,q--;p&gt;=s+i-1;)<br /> {<br />  *(p--) = *(q--);<br /> }</p>
		<p> //<br /> for(p=s+i-1;*s1;)<br /> {<br />  *(p++) = *(s1++);<br /> }<br />}<br /><br /><br />int _tmain(int argc, _TCHAR* argv[])<br />{</p>
		<p> char *s = "Student";<br /> char *s1 = "Teacher";</p>
		<p> Insert(s,s1,3);<br /><br />// 期待的输出是StuTeacherdent;<br /> cout&lt;&lt;s;</p>
		<p>
				<br /> return 0;<br />}<br /><br /><br />// 还有我如果把insert函数改成下面的应该也是可以的吧<br /></p>
		<p>void Insert2(char *s, char *s1, int i)<br />{<br /> char *p,*q;<br /> p = s + strlen(s); // p 指向s的末尾+1<br /> q = p + strlen(s1); //q 指向新构造的字符串的\0 <br /> *q = '\0';</p>
		<p> // <br /> for(p--,q--;p&gt;=s+i-1;)<br /> {<br />  *p-- = *q--;<br /> }</p>
		<p> //<br /> for(p=s+i-1;*s1;)<br /> {<br />  *p++ = *s1++;<br /> }<br />}<br /></p>
<img src ="http://www.cppblog.com/richardzeng/aggbug/4389.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-03-20 21:32 <a href="http://www.cppblog.com/richardzeng/archive/2006/03/20/4389.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转换大小写C函数</title><link>http://www.cppblog.com/richardzeng/archive/2006/03/19/4331.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Sun, 19 Mar 2006 02:56:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/03/19/4331.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/4331.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/03/19/4331.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/4331.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/4331.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
						</o:p>
				</span> </p>
		<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
				<o:p>
				</o:p>
		</span>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">Richard zeng<span style="mso-spacerun: yes">  </span>3/19/2006 10:50:36 AM<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">这几天又把以前的</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">C</span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">课程翻了出来</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">,</span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">因为自己对</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">C</span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的指针和数组不是很</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">DEV.<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">模拟</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">C</span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">库函数中的转化大小写函数</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">.<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">// </span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">转换成大写</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">, </span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">函数参数为字符数组</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">// </span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">利用字符串数组的结尾都是</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">\0<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">void</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: black">ToUpper</span>(<span style="COLOR: blue">char</span><span style="COLOR: black">s</span>[])<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">i</span>=0;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>
						<span style="COLOR: blue">while</span>(<span style="COLOR: black">s</span>[<span style="COLOR: black">i</span>++]!=<span style="COLOR: maroon">'\0'</span> )<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">              </span>// </span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">判断是否是小写字母</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">              </span>
						<span style="COLOR: blue">if</span>(<span style="COLOR: black">s</span>[<span style="COLOR: black">i</span>]&gt;=<span style="COLOR: maroon">'a'</span> &amp;&amp; <span style="COLOR: black">s</span>[<span style="COLOR: black">i</span>]&lt;=<span style="COLOR: maroon">'z'</span> )<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">                     </span>
						<span style="COLOR: black">s</span>[<span style="COLOR: black">i</span>] -= 32;<span style="mso-tab-count: 1">     </span>// </span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">小写字母比大写字母的</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">ASCII</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">大</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">32<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">// </span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">转换成大写</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">, </span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">函数参数为字符指针</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">void</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: black">ToUpperPtr</span>(<span style="COLOR: blue">char</span>* <span style="COLOR: black">s</span>)<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>
						<span style="COLOR: blue">while</span>(*<span style="COLOR: black">s</span> != <span style="COLOR: maroon">'\0'</span>)<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">// </span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">判断是否是小写字母</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">              </span>
						<span style="COLOR: blue">if</span>(*<span style="COLOR: black">s</span> &gt;=<span style="COLOR: maroon">'a'</span> &amp;&amp; *<span style="COLOR: black">s</span> &lt;=<span style="COLOR: maroon">'z'</span>)<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">                     </span>*<span style="COLOR: black">s</span> -= 32; <span style="mso-tab-count: 1">     </span>// </span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">小写字母比大写字母的</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">ASCII</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">大</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">32<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">              </span>
						<span style="COLOR: black">s</span>++; // </span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">指针的地址</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">++<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">       </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-font-kerning: 0pt; mso-no-proof: yes">}</span>
		</p>
<img src ="http://www.cppblog.com/richardzeng/aggbug/4331.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-03-19 10:56 <a href="http://www.cppblog.com/richardzeng/archive/2006/03/19/4331.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一些基本的GDI操作BITMAP的方法  /zhuan</title><link>http://www.cppblog.com/richardzeng/archive/2006/03/10/3962.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Fri, 10 Mar 2006 03:27:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/03/10/3962.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/3962.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/03/10/3962.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/3962.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/3962.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1&nbsp;&nbsp;2&nbsp;#ifndef&nbsp;_BITMAP_H&nbsp;3&nbsp;#define&nbsp;_BITMAP_H&nbsp;4&nbsp;&nbsp;5&nbsp;#include&nbsp;&lt;windows.h&gt;&nbsp;6&nbsp;&nbsp;7&nbsp;void&nbsp;SaveImage(const&nbsp;char&nbsp...&nbsp;&nbsp;<a href='http://www.cppblog.com/richardzeng/archive/2006/03/10/3962.html'>阅读全文</a><img src ="http://www.cppblog.com/richardzeng/aggbug/3962.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-03-10 11:27 <a href="http://www.cppblog.com/richardzeng/archive/2006/03/10/3962.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++中实现串口操作类 </title><link>http://www.cppblog.com/richardzeng/archive/2006/03/10/3961.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Fri, 10 Mar 2006 03:15:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/03/10/3961.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/3961.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/03/10/3961.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/3961.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/3961.html</trackback:ping><description><![CDATA[<DIV class=postText>
<P><FONT face=Arial size=2>工程下载：<FONT face="Times New Roman" size=3><A HREF="/Files/richardzeng/C">http://www.cppblog.com/Files/richardzeng/C</A>++中实现串口操作类%20SerialPortLib.rar<BR></FONT></FONT><A href="/Files/dyj057/SerialPortLib.rar"><FONT face=Arial size=2></FONT></A><BR><FONT face=Arial size=2>最近封装了一个串口类,与大家分享,该类的主要特点是：能实现数据的异步接收；无须MFC的支持；只能在VS2003编译通过，但只要做少量修改就可以在VC6.0中使用．使用起来非常简单，主要代码如下：<BR></FONT></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">stdafx.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">comm_exception.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">SerialPort.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">serialportobservertest.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">namespace</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;C2217::StdLib;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">namespace</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;IBMS;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;_tmain(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;argc,&nbsp;_TCHAR</SPAN><SPAN style="COLOR: #000000">*</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;argv[])<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">12</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">声明一个串口观察者</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #008000"></SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CSerialPortObserverTest&nbsp;portObserver;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">声明串口1</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #008000"></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CSerialPort&nbsp;port(</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">注册串口的观察者</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #008000"></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port.AtachPortObserver(</SPAN><SPAN style="COLOR: #000000">&amp;</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">portObserver);<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">打开串口</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">20</SPAN>&nbsp;<SPAN style="COLOR: #008000"></SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port.Open();<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">&nbsp;data[</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;{</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">};<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">23</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port.Send(data,</SPAN><SPAN style="COLOR: #0000ff">sizeof</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">(data));<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">25</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(comm_exception&nbsp;</SPAN><SPAN style="COLOR: #000000">&amp;</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">e)<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SET_CATCH_POS(e);<BR></SPAN><SPAN style="COLOR: #008080">28</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;e;<BR></SPAN><SPAN style="COLOR: #008080">29</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">30</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">31</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN>&nbsp;</FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">}<BR></SPAN><SPAN style="COLOR: #008080">33</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></FONT></FONT></DIV>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;串口数据的接收在</FONT></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT face=Arial><FONT size=2><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;CSerialPortObserverTest::OnSerialPortReceive(CSerialPort&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">pSerialPort,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">pData,&nbsp;size_t&nbsp;nDataLen)<BR>{<BR>&nbsp;cout&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;pSerialPort</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">GetName().c_str()&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Received&nbsp;Data:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">endl;<BR>&nbsp;<BR>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(size_t&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;nDataLen&nbsp;;</SPAN><SPAN style="COLOR: #000000">++</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">i&nbsp;)<BR>&nbsp;{<BR>&nbsp;&nbsp;cout&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;pData[i]&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;;<BR>&nbsp;}<BR><BR>&nbsp;cout&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><FONT face=Arial size=2>endl;<BR>}<BR><BR></FONT></SPAN></DIV>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;完成，你也可以不使用观察者，直接重写void CSerialPort::OnReceiveData(byte *pData, size_t nDataLen)可以获得更好的执行效率。去掉观察者对象list.</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp; 有什么问题邮件联系:dyj057@gmail.com<BR><BR><BR><BR></P>
<DIV class=post>
<DIV class=postTitle><A title="permalink: re: C++中实现串口操作类" href="/dyj057/archive/2005/12/22/1965.html#1967">#</A>&nbsp;<A name=1967></A>re: C++中实现串口操作类 2005-12-22 18:34 <A id=Comments1_CommentList__ctl0_NameLink href="/sandy/" target=_blank>小明</A> </DIV>
<DIV class=postText>我看你的程序使用了一个叫IbmsSerialPort.dll的dll来完成通讯 <BR><BR>而这个IbmsSerialPort.dll首先使用CreateFile，然后使用GetCommState等等一系列communications resource function来完成端口通讯 <BR><BR>ok,学到了一些东西 <BR><BR>&nbsp;&nbsp;<A onclick='SetReplyAuhor("小明")' href="/dyj057/archive/2005/12/22/1965.html#post">回复</A>&nbsp;<BR><BR>
<DIV class=post>
<DIV class=postTitle><A title="permalink: re: C++中实现串口操作类" href="/dyj057/archive/2005/12/22/1965.html#3596"><FONT color=#3f3d3d>#</FONT></A>&nbsp;<A name=3596></A>re: C++中实现串口操作类 2006-03-01 10:44 <A id=Comments1_CommentList__ctl1_NameLink target=_blank>msn:a.zlp@163.com</A> </DIV>
<DIV class=postText>CreateFile对串口操作是独占的，其他的应用程序就不能打开，怎么实现观察者的角色呢？想请教楼主！msn:a.zlp@163.com&nbsp;&nbsp;<A onclick='SetReplyAuhor("msn:a.zlp@163.com")' href="/dyj057/archive/2005/12/22/1965.html#post"><FONT color=#3f3d3d>回复</FONT></A> <BR><A id=Comments1_CommentList__ctl1_DeleteLink href="javascript:__doPostBack('Comments1$CommentList$_ctl1$DeleteLink','')"></A>&nbsp;&nbsp;<A id=Comments1_CommentList__ctl1_EditLink></A> </DIV></DIV><BR>
<DIV class=post>
<DIV class=postTitle><A title="permalink: re: C++中实现串口操作类" href="/dyj057/archive/2005/12/22/1965.html#3599"><FONT color=#3f3d3d>#</FONT></A>&nbsp;<A name=3599></A>re: C++中实现串口操作类<A name=Post></A> 2006-03-01 12:00 <A id=Comments1_CommentList__ctl2_NameLink href="/dyj057/" target=_blank><FONT color=#3f3d3d>天下无双</FONT></A> </DIV>
<DIV class=postText>这个简单，当你发送数据的时候，也发送一份到观察者.接收到数据的时候，也转一份到观察者。&nbsp;&nbsp;<A onclick='SetReplyAuhor("天下无双")' href="/dyj057/archive/2005/12/22/1965.html#post"><FONT color=#3f3d3d>回复</FONT></A>&nbsp;<BR><A id=Comments1_CommentList__ctl2_DeleteLink href="javascript:__doPostBack('Comments1$CommentList$_ctl2$DeleteLink','')"></A>&nbsp;&nbsp;<A id=Comments1_CommentList__ctl2_EditLink></A>&nbsp;<BR><A id=Comments1_CommentList__ctl0_DeleteLink href="javascript:__doPostBack('Comments1$CommentList$_ctl0$DeleteLink','')"></A>&nbsp;&nbsp;<A id=Comments1_CommentList__ctl0_EditLink></A> </DIV></DIV></DIV></DIV></FONT></DIV><img src ="http://www.cppblog.com/richardzeng/aggbug/3961.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-03-10 11:15 <a href="http://www.cppblog.com/richardzeng/archive/2006/03/10/3961.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>时间和日历类的设计</title><link>http://www.cppblog.com/richardzeng/archive/2006/03/10/3958.html</link><dc:creator>Beginning to 编程</dc:creator><author>Beginning to 编程</author><pubDate>Fri, 10 Mar 2006 02:56:00 GMT</pubDate><guid>http://www.cppblog.com/richardzeng/archive/2006/03/10/3958.html</guid><wfw:comment>http://www.cppblog.com/richardzeng/comments/3958.html</wfw:comment><comments>http://www.cppblog.com/richardzeng/archive/2006/03/10/3958.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/richardzeng/comments/commentRss/3958.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/richardzeng/services/trackbacks/3958.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 时间和日历类的设计（Java的Date和Calendar的C++实现） &nbsp;C++通用框架的设计 作者：naven1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 介绍时间和日历以及时间的格式化处理在软件的设计中起着非常重要的作用，但是目前C++的库却未有一个简单易用的时间类，大部分都需要开发者直接调...&nbsp;&nbsp;<a href='http://www.cppblog.com/richardzeng/archive/2006/03/10/3958.html'>阅读全文</a><img src ="http://www.cppblog.com/richardzeng/aggbug/3958.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/richardzeng/" target="_blank">Beginning to 编程</a> 2006-03-10 10:56 <a href="http://www.cppblog.com/richardzeng/archive/2006/03/10/3958.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>