﻿<?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++博客-love in C++, live on MFC-随笔分类-VC/MFC</title><link>http://www.cppblog.com/flyingxu/category/824.html</link><description>to get ready...</description><language>zh-cn</language><lastBuildDate>Wed, 21 May 2008 20:10:07 GMT</lastBuildDate><pubDate>Wed, 21 May 2008 20:10:07 GMT</pubDate><ttl>60</ttl><item><title>我的新博客在 http://www.codediscuss.com</title><link>http://www.cppblog.com/flyingxu/archive/2007/10/02/33321.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 02 Oct 2007 06:23:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2007/10/02/33321.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/33321.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2007/10/02/33321.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/33321.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/33321.html</trackback:ping><description><![CDATA[<u><font color=#800080>我的新博客在 <br><br><a href="http://www.codediscuss.com/">http://www.codediscuss.com</a></font></u>&nbsp;&nbsp;
<script src="http://blog.csdn.net/count.aspx?ID=1809661&amp;Type=Rank"></script>
<img title=文章指数:0 alt=文章指数:0 src="http://blog.csdn.net/images/star_0.gif" border=0>&nbsp;&nbsp;<img title="CSDN Blog推出文章指数概念，文章指数是对Blog文章综合评分后推算出的，综合评分项分别是该文章的点击量，回复次数，被网摘收录数量，文章长度和文章类型；满分100，每月更新一次。" alt="CSDN Blog推出文章指数概念，文章指数是对Blog文章综合评分后推算出的，综合评分项分别是该文章的点击量，回复次数，被网摘收录数量，文章长度和文章类型；满分100，每月更新一次。" src="http://blog.csdn.net/images/ask.gif" border=0>
<div class=postText><a title=http://www.codediscuss.com href="http://www.codediscuss.com/" target=_blank><u><font color=#800080>http://www.codediscuss.com</font></u></a>&nbsp;是我的博客的新地址。还是以VC++编程为主，有mfc，英语，还有点点shareware的内容。<br></div>
<img src ="http://www.cppblog.com/flyingxu/aggbug/33321.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2007-10-02 14:23 <a href="http://www.cppblog.com/flyingxu/archive/2007/10/02/33321.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Memory leak in CWinThread?</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 26 Jul 2006 11:11:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/10557.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/10557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/10557.html</trackback:ping><description><![CDATA[
		<p>类似的问题见<a href="http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html">http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html</a></p>
		<p>下面的代码，当用AfxBeginThread开始一个线程时，实际上是有内存泄漏的</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="Courier New">
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (ii </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; ii </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1000</span>
						<span style="COLOR: #000000">; ii</span>
						<span style="COLOR: #000000">++</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">) <br />{<br />  CWinThread </span>
						<span style="COLOR: #000000">*</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">pWinThread; <br />  pWinThread </span>
						<span style="COLOR: #000000">=</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000"> AfxBeginThread(ThreadLBProc, NULL);<br />  ::Sleep(</span>
						<span style="COLOR: #000000">500</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">);<br />}<br /><br />UINT ThreadLBProc(LPVOID pParam)<br />{<br />  </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New">;<br />}</font>
						<br />
				</span>
		</div>VC输出的典型提示为：<br />Detected memory leaks!<br />Dumping objects -&gt;<br /><font style="BACKGROUND-COLOR: #ffffff"><b style="COLOR: black; BACKGROUND-COLOR: #ffff66"><font style="BACKGROUND-COLOR: #ffffff">thrdcore.cpp</font></b>(</font><font style="BACKGROUND-COLOR: #ffffff">166)</font> : {782} client block at 0x00425300, subtype 0, 112 bytes long.<br />实际上，只要看到是<font style="BACKGROUND-COLOR: #ffff00"><strong>thrdcore.cpp</strong>(166)</font> 的内存泄漏，基本就是同一个原因，和上面的代码一样。<br />解决方法：<br />step 1)<br />在线程函数中，记得写AfxEndThread();(与AfxBeginThread对应，其他的开始线程的函数，有相应的函数)<br />step 2)<br />用::WaitForSingleObject()确保线程彻底退出<br /><br />step 2是比较容易忽略的，用sleep函数只能侥幸的保证线程退出，但不能确保。<img src ="http://www.cppblog.com/flyingxu/aggbug/10557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-26 19:11 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再调试状态下，按下F12，程序就出错了（VC）</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 13 Jul 2006 10:29:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9818.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9818.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9818.html</trackback:ping><description><![CDATA[用VC调试程序，只要按下F12，程序就出错了，出错的代码还很奇怪，再PeekMessage中，但是只出现在调试（按F5），不出现在全速运行（Ctrl+F5），release版本也没有问题<br />网上的解答:<br /><a href="http://support.microsoft.com/kb/q130667/">http://support.microsoft.com/kb/q130667/</a> F12居然就是这么定义的，ft<br /><br />所以，在定义程序功能的时候，就尽量不要用到F12 ，哈<img src ="http://www.cppblog.com/flyingxu/aggbug/9818.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-13 18:29 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Is MSDN wrong?  or I made a mistake? about static member function</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/11/9697.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 11 Jul 2006 11:14:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/11/9697.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9697.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/11/9697.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9697.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9697.html</trackback:ping><description><![CDATA[我在ms的group上问了个问题<a href="http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;tid=402a414c-a125-45bd-9cf4-c1819db7e3e4">http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;tid=402a414c-a125-45bd-9cf4-c1819db7e3e4</a>：<br /><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="Tahoma"><span style="COLOR: #000000">in http://msdn2.microsoft.com/en-us/library/480b7kf7.aspx</span><span style="COLOR: #000000">,</span></font><font face="Tahoma"><span style="COLOR: #000000"> it says that <br />pGdiObject-&gt;DeleteTempMap()</span><span style="COLOR: #008000">;</span><span style="COLOR: #008000">  // Causes compiler error</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Tahoma">But I'm confused for a static member can be called by the object or a pointer.<br />Is there anything wrong of my understanding?</font><br /></span></div>回答的人到蛮多，讨论的也很热烈，但都没有直接回答我的问题，我的问题是，对于静态函数，<br />pGdiObject-&gt;DeleteTempMap()<span style="COLOR: #008000">;</span><span style="COLOR: #008000">  // Causes compiler error，<br />到底对不对？如果不对，就是msdn错了，不过总觉得比较奇怪，msdn不该出这样的错的</span><img src ="http://www.cppblog.com/flyingxu/aggbug/9697.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-11 19:14 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/11/9697.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz]MFC返回的临时对象指针成因?</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/10/9663.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 10 Jul 2006 15:18:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/10/9663.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9663.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/10/9663.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9663.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9663.html</trackback:ping><description><![CDATA[
		<p>csdn上难得的好文章，怕不争气的csdn网站过几天又找不到这篇文章了，我得先转一下，保存一下：<br /><a href="http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=193097">http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=193097</a><br /><br /></p>
		<table cellspacing="1" cellpadding="3" width="620" border="0">
				<tbody>
						<tr bgcolor="#eeeeee">
								<td valign="top" align="right" width="40">
										<font style="FONT-SIZE: 11pt; FONT-FAMILY: Arial" color="red">
												<b>Q :</b>
										</font>
								</td>
								<td valign="top" width="580" colspan="3">MFC返回的临时对象指针成因?</td>
						</tr>
						<tr bgcolor="#eeeeee">
								<td valign="top" align="right">
										<font color="red">
												<b>主要解答者:</b>
										</font>
								</td>
								<td>QunKangLi</td>
								<td align="right">
										<font color="red">
												<b>提交人:</b>
										</font>
								</td>
								<td>QunKangLi</td>
						</tr>
						<tr bgcolor="#eeeeee">
								<td valign="top" align="right">
										<font color="red">
												<b>感谢:</b>
										</font>
								</td>
								<td valign="top" width="580" colspan="3">oldforest、yu_hl、QunKangLi</td>
						</tr>
						<tr bgcolor="#eeeeee">
								<td valign="top" align="right">
										<font color="red">
												<b>审核者:</b>
										</font>
								</td>
								<td>happyparrot</td>
								<td align="right">
										<font color="red">
												<b>社区对应贴子:</b>
										</font>
								</td>
								<td>
										<a href="http://community.csdn.net/Expert/TopicView.asp?id=2916681" target="_blank">
												<font color="#002c99">查看</font>
										</a>
								</td>
						</tr>
						<tr bgcolor="#eeeeee">
								<td valign="top" align="left" colspan="4">    <font style="FONT-SIZE: 11pt; FONT-FAMILY: Arial" color="red"><b> A :</b></font></td>
						</tr>
						<tr bgcolor="#ffffff">
								<td valign="top" align="left" colspan="4">
										<br />msdn在介绍GetDlgItem的时候，明确指出：  <br />The  returned  pointer  may  be  temporary  and  should  not  be  stored  for  later  use.  <br />如果真是这样那我不惨了！在我的一个软件中，因为常常要使切换按钮的可用与不可用以及改变按钮文字，所以我用DetDlgItem把它们存了起来，用的时候直接到数组里面取，这样的话这个软件不是犯了一个重大的错误了？可是用这么久也没出错。  <br />另外，它也是说可能是临时的，那一定在某种情况下不是临时的，高手能不能解释一下这个问题？  <br />---------------------------------------------------------------  <br />//    Most  Windows  objects  are  represented  with  a  HANDLE,  including  <br />//            the  most  important  ones,  HWND,  HDC,  HPEN,  HFONT  etc.  <br />//    We  want  C++  objects  to  wrap  these  handle  based  objects  whenever  we  can.  <br />//    Since  Windows  objects  can  be  created  outside  of  C++  (eg:  calling  <br />//            ::CreateWindow  will  return  an  HWND  with  no  C++  wrapper)  we  must  <br />//            support  a  reasonably  uniform  mapping  from  permanent  handles  <br />//            (i.e.  the  ones  allocated  in  C++)  and  temporary  handles  (i.e.  <br />//            the  ones  allocated  in  C,  but  passed  through  a  C++  interface.  <br />//    We  keep  two  dictionaries  for  this  purpose.    The  permanent  dictionary  <br />//            stores  those  C++  objects  that  have  been  explicitly  created  by  <br />//            the  developer.    The  C++  constructor  for  the  wrapper  class  will  <br />//            insert  the  mapping  into  the  permanent  dictionary  and  the  C++  <br />//            destructor  will  remove  it  and  possibly  free  up  the  associated  <br />//            Windows  object.  <br />//    When  a  handle  passes  through  a  C++  interface  that  doesn't  exist  in  <br />//            the  permanent  dictionary,  we  allocate  a  temporary  wrapping  object  <br />//            and  store  that  mapping  into  the  temporary  dictionary.  <br />//    At  idle  time  the  temporary  wrapping  objects  are  flushed  (since  you  better  <br />//            not  be  holding  onto  something  you  didn't  create).  <br />//  <br /> <br /> <br />在CWinThread::OnIdle里调用AfxUnlockTempMaps，AfxUnlockTempMaps会释放temporary  maps.  <br /> <br />所以不要保留GetDlgItem等返回的临时指针，可以直接保存HWND  objects，然后CWnd::FromHandle获取临时指针来用。  <br /> <br />---------------------------------------------------------------  <br /> <br />临时包装对象会在空闲时间删除.在同一函数中多次使用是没用问题的,不同函数中使用先前保存下来的指针就有可能出错,特别是对话框初使化时候存下来的指针.  <br />       在MFC层次上的函数使用CWnd对象,而本地Windows代码(API)使用句柄.如:当Windows系统调用一个窗口过程时将传递一个HWND参数,而MFC本身的消息机制使用CWnd类;为了更好更高效的实现,MFC需要与Windows系统合作,将句柄与CWnd对象进行关联---它用CHandleMap完成关联.  <br />CHandleMap有两个CMapPtrToPtr的成员变量:m_permanentMap(永久映射表,程序运行过程中对象/句柄之间的关系),m_temporaryMap(临时映射表,在消息存在的过程中才存在).永久表保存显式创建的CWnd对象,当对象创建时将在永久目录下插入一个条目,在CWnd::OnNcDestrory时删除对应条目.但是Windows有时会传入某些不是由开发人员显式创建的窗口的句柄,此时MFC会分配一个临时对象来包装这个句柄并将它们的映射保存到临时映射表中,这些临时对象会在空闲时间被删除并移走相应的临时映射表条目.类似的MFC对象与Windows句柄的映射表有:  <br />m_pmapHWND:                        窗口句柄与CWnd对象  <br />m_pampHMENU:                        菜单句柄与CMenu对象  <br />m_pmapHDC:                        设备环境句柄与CDC对象  <br />m_pmapHGDIOBJ:                        GDI句柄与CGDI对象  <br />m_mapHIMAGELIST:            图像链表句柄到CImageList对象  <br /> <br />当给定句柄,如HWND时,MFC简单调用CWnd*  PASCAL  CWnd::FromHandle(HWND  hWnd),  此函数内部使用CHandleMap::FromHandle(hWnd)获取相关联的CWnd对象.在CHandleMap::FromHandle(h)内部(源代码在WinHand.cpp),先使用CObject*  pObject  =  LookupPermanent(h);            if  (pObject  !=  NULL)return  pObject;    检查永久表;如永久表中不存在,使用pObject  =  LookupTemporary(h))  !=  NULL检查临时表,都不存在时,使用pTemp  =  =  m_pClass-&gt;CreateObject();if  (pTemp  ==  NULL)AfxThrowMemoryException();m_temporaryMap.SetAt((LPVOID)h,  pTemp);创建临时对象并将其插入到临时表中去,同时返回该临时对象.  <br />void  CHandleMap::RemoveHandle(HANDLE  h)的注释说明临时对象将在空闲时由OnIdel释放:  <br />           //  remove  only  from  permanent  map  --  temporary  objects  are  removed  <br />           //    at  idle  in  CHandleMap::DeleteTemp,  always!  <br />如果想不自动释放临时对象,使用void  AFXAPI  AfxLockTempMaps()/BOOL  AFXAPI  AfxUnlockTempMaps(BOOL  bDeleteTemps)进行锁定.  <br /><br /></td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
<img src ="http://www.cppblog.com/flyingxu/aggbug/9663.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-10 23:18 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/10/9663.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bug： OnIdle called only while mouse's moving</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Sat, 08 Jul 2006 18:03:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9593.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9593.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9593.html</trackback:ping><description><![CDATA[在mfc的group上有这样一个问题：（<a href="http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&amp;sloc=en-us">http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&amp;sloc=en-us</a>）<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">I need to update one </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> data and the view during the idle, I used </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">  <br />method </span><span style="COLOR: #0000ff">in</span><span style="COLOR: #000000"> the Cdoc:<br /></span><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CMyAppDoc::OnIdle(){<br /><br />    theClass</span><span style="COLOR: #000000">-&gt;</span></font><font face="Courier New"><span style="COLOR: #000000">Update();<br />    POSITION pos </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> GetFirstViewPosition();<br />    CView</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pView </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> GetNextView(pos);<br />    pView</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Invalidate(</span><span style="COLOR: #0000ff">true</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    pView</span><span style="COLOR: #000000">-&gt;</span></font><span style="COLOR: #000000"><font face="Courier New">UpdateWindow();    <br />}</font><br /><br />It works only when I move the mouse, what</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">s wrong? Z_Z</span><span style="COLOR: #000000"><br /></span></div>这个问题的确比较搞，要好好看mfc源码的，下面是我的回答<br />Nothing is wrong, I can explain it  is by design.<br />Please take a look at the source code of int CWinThread::Run(), in that function, IsIdleMessage() is called, and in IsIdleMessage() WM_PAINT is ignored, which means WM_PAINT will not cause OnIdle to be called, for windows think it's just a WM_PAINT message and will not change the UI.<br />Your UpdateWindow() only post a WM_PAINT message, the message queue is not empty but it's ignored by IsIdleMessage(), that's why.<br />But when you move your mouse, the message queue is filled with some WM_MOUSEMOVE and it's not ignored for the position changes. So your OnIdle() is called again.<br />-<br />My suggestion is to move your Invalidate &amp; UpdateWindow code to somewhere else.<br /><font face="Courier New">OnIdle（）</font>的确是个有点复杂的问题，我可能还会写几篇文章 ：）<br />这里（<a href="http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&amp;q=AfxUnlockTempMaps&amp;rnum=40&amp;hl=zh-CN#66b6e5949a31bfa2">http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&amp;q=AfxUnlockTempMaps&amp;rnum=40&amp;hl=zh-CN#66b6e5949a31bfa2</a>）有篇文章讲的很到位<img src ="http://www.cppblog.com/flyingxu/aggbug/9593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-09 02:03 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>_asm int 3 的一个应用：在程序运行后再进入调试器</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 06 Jul 2006 09:35:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9493.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9493.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9493.html</trackback:ping><description><![CDATA[调试程序的时候，一般<br />1）启动调试器，比如VC<br />2）在VC中设断点<br />3）操作程序，使得程序运行到断点，停下来<br />但是现在我遇到一个情况，希望调试的情景是这样的：双击某个文件，我的程序启动后，这个时候我想程序停下来，让我在VC中调试它。<br />但是，双击文件后启动的程序，是个独立的exe运行程序，肯定不是在VC的运行控制下的，VC中设置的断点不起作用的。怎么办呢？<br />这个时候可以在想让程序停下来的地方增加指令_asm int 3，debug下编译好。双击文件后运行这个exe，在exe运行到_asm int 3时，就会中断，而把当前的exe运行与一个新的调试器（一个新的VC进程）结合起来。接下来就像一般的调试了。<br />这时的调试步骤类似与：<br />1）程序运行<br />2）遇到特定条件时，_asm int 3把当前exe与一个新的调试器，比如一个新的VC进程，联系起来<br />3）在调试器中调试exe<br /><br />：）<img src ="http://www.cppblog.com/flyingxu/aggbug/9493.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-06 17:35 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ANSI版本保存的文件，在UNICODE时是否依然能读入？</title><link>http://www.cppblog.com/flyingxu/archive/2006/06/13/8521.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 13 Jun 2006 15:53:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/06/13/8521.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/8521.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/06/13/8521.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/8521.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/8521.html</trackback:ping><description><![CDATA[情况是这样的，一个程序从ansi移植到了unicode，见<a id="viewpost1_TitleUrl" href="/flyingxu/archive/2006/05/18/7356.html"><font color="#000080">把代码移植成UNICODE</font></a> （<a href="/flyingxu/archive/2006/05/18/7356.html">http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html</a>），之后产生了一个问题，之前文件保存的那些文件，unicode版本还能打开吗？这真是个大问题，如果不能，就基本表示这个程序已经半死不活了。<br /><br />文件的保存基本用的序列化，比如<br /><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="Courier New"><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> CSDITestDoc::Serialize(CArchive</span><span style="COLOR: #000000">&amp;</span></font><font face="Courier New"><span style="COLOR: #000000"> ar)<br />{<br />    </span><span style="COLOR: #0000ff">if</span></font><font face="Courier New"><span style="COLOR: #000000"> (ar.IsStoring())<br />    {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: add storing code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        ar </span><span style="COLOR: #000000">&lt;&lt;</span></font><font face="Courier New"><span style="COLOR: #000000"> m_strName;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">    {<br />        </font></span><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: add loading code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        ar </span><span style="COLOR: #000000">&gt;&gt;</span></font><span style="COLOR: #000000"><font face="Courier New"> m_strName;<br />    }<br />}</font></span></div><font face="Courier New">如果m_strName = _T("name");那么ansi情况下，保存的文件为:<br />04 6E 61 6D 65，一共5个字节。<br />然后用unicode版本保存时，是<br />FF FE FF 04 6E 00 61 00 6D 00 65 00,一共12个字节。<br /><br />然后我发现，ansi版本的可以打开unicode版本的文件，unicode版本的也可以打开ansi版本的文件。<br /><br />为什么？我觉得关键在于CString，我觉得CString功能比较强大。<br />CString的序列化函数<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> CString serialization code<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> String format:<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      UNICODE strings are always prefixed by 0xff, 0xfffe<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if &lt; 0xff chars: len:BYTE, TCHAR chars<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if &gt;= 0xff characters: 0xff, len:WORD, TCHAR chars<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if &gt;= 0xfffe characters: 0xff, 0xffff, len:DWORD, TCHARs</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><br />CArchive</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> AFXAPI </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(CArchive</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> ar, </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> CString</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">)<br />{<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> special signature to recognize unicode strings</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">#ifdef _UNICODE<br />    ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />    ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #000000">0xfffe</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"><br /><br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">)<br />    {<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0xfffe</span><span style="COLOR: #000000">)<br />    {<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br />    {<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #000000">0xffff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> (DWORD)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength;<br />    }<br />    ar.Write(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.m_pchData, </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nDataLength</span><span style="COLOR: #000000">*</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(TCHAR));<br />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ar;<br />}<br /></span></div></font>它对unicode做了特别的支持<br />特别是当它在读序列化过程的时候<br /><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="Courier New"><span style="COLOR: #000000">CArchive</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> AFXAPI </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">(CArchive</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> ar, CString</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />{<br />#ifdef _UNICODE<br />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if we get ANSI, convert</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#else</font></span><span style="COLOR: #000000"><br /><font face="Courier New">    </font></span><font face="Courier New"><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if we get UNICODE, convert</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#endif</font></span><span style="COLOR: #000000"><br /><br /><font face="Courier New">    UINT nNewLen </font></span><span style="COLOR: #000000"><font face="Courier New">=</font></span><font face="Courier New"><span style="COLOR: #000000"> _AfxReadStringLength(ar);<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> (UINT)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />    {<br />        nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span></font><font face="Courier New"><span style="COLOR: #000000"> nConvert;<br />        nNewLen </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> _AfxReadStringLength(ar);<br />        ASSERT(nNewLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    }<br /><br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> set length of string to new length</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    UINT nByteLen </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> nNewLen;<br />#ifdef _UNICODE<br />    </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength((</span><span style="COLOR: #0000ff">int</span></font><font face="Courier New"><span style="COLOR: #000000">)nNewLen);<br />    nByteLen </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> nByteLen </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> nConvert);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> bytes to read</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#else</font></span><span style="COLOR: #000000"><br /><font face="Courier New">    nByteLen </font></span><font face="Courier New"><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> nByteLen </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> nConvert;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> bytes to read</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />        </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength(</span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">        </font></span><font face="Courier New"><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength((</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)nByteLen</span><span style="COLOR: #000000">+</span></font><font face="Courier New"><span style="COLOR: #000000">nConvert);<br /></span><span style="COLOR: #0000ff">#endif</span></font><span style="COLOR: #000000"><br /><br /><font face="Courier New">    </font></span><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> read in the characters</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />    {<br />        ASSERT(nByteLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> read new data</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (ar.Read(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.m_pchData, nByteLen) </span><span style="COLOR: #000000">!=</span></font><font face="Courier New"><span style="COLOR: #000000"> nByteLen)<br />            AfxThrowArchiveException(CArchiveException::endOfFile);<br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> convert the data if as necessary</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nConvert </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />        {<br />#ifdef _UNICODE<br />            CStringData</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pOldData </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.GetData();<br />            LPSTR lpsz </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (LPSTR)</span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.m_pchData;<br /></span><span style="COLOR: #0000ff">#else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">            CStringData</font></span><font face="Courier New"><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pOldData </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.GetData();<br />            LPWSTR lpsz </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (LPWSTR)</span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.m_pchData;<br /></span><span style="COLOR: #0000ff">#endif</span></font><span style="COLOR: #000000"><br /><font face="Courier New">            lpsz[nNewLen] </font></span><font face="Courier New"><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> must be NUL terminated</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.Init();   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> don't delete the old data</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> lpsz;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> convert with operator=(LPWCSTR)</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            CString::FreeData(pOldData);<br />        }<br />    }<br />    </span><span style="COLOR: #0000ff">return</span></font><span style="COLOR: #000000"><font face="Courier New"> ar;<br />}<br /></font></span></div>也就是说，不管你保存的文件是不是unicode，都可以读进来，转换称当前unicode或者ansi版本<br /><br />不过回到文章的标题，这里只讲了用CString序列化的保存。如果是其他保存方式，可以学着CString的做法，写函数把文件总是能读进来。<img src ="http://www.cppblog.com/flyingxu/aggbug/8521.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-06-13 23:53 <a href="http://www.cppblog.com/flyingxu/archive/2006/06/13/8521.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC程序中，自定义的字符串id范围是什么？</title><link>http://www.cppblog.com/flyingxu/archive/2006/06/13/8478.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 12 Jun 2006 16:25:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/06/13/8478.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/8478.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/06/13/8478.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/8478.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/8478.html</trackback:ping><description><![CDATA[MFC自己定义了一些字符串，在用户自己定义字符串的时候，id不能重复。这个时候，用户自定义id的范围是什么？<br />今天同事问我。<br /><br />我还真不知道，但是我看了下AFXRES.RC 和AFXRES.H ，发现MFC用的ID都是0xE000以上的。所以，用户自己用的，从0－&gt;0xCFFFF？不过不确定。呵呵，查了一下，正确的可以见TN020:<a href="http://msdn2.microsoft.com/en-us/library/t2zechd4.aspx">http://msdn2.microsoft.com/en-us/library/t2zechd4.aspx</a><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">By convention, the ID value of </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000"> not used.<br /><br /><strong>Windows implementation limitations restrict </strong></span><strong><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000"> resource IDs to be less than or equal to </span><span style="COLOR: #000000">0x7FFF</span></strong><span style="COLOR: #000000"><strong>.<br /></strong><br />MFC</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">s internal framework implementations reserve several ranges: 0xE000-&gt;0xEFFF and 0x7000-&gt;0x7FFF.</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #000000"><br />Several Windows system commands use the range of </span><span style="COLOR: #000000">0xF000</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0xFFFF</span><span style="COLOR: #000000">.<br /><br />Control IDs of </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000"> are reserved by IDOK, IDCANCEL, and so on.<br /><br />The range of </span><span style="COLOR: #000000">0x8000</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">0xFFFF</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> strings </span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000"> reserved </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> menu prompts </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> commands.</span></div><br /><br />但是在我的印象中，重复的字符串id在编译的时候，就会出错的。但是<a href="http://support.microsoft.com/kb/q194299/">http://support.microsoft.com/kb/q194299/</a>上说，实际上，选<strong>static</strong> link mfc才会在编译的时候发现，否则发现不了。<br /><br />另外：<a href="http://www.vckbase.com/article/misc/0022.htm">http://www.vckbase.com/article/misc/0022.htm</a>中说，在一个rc文件中，可以同时有几种语言的资源，呵呵，我发现我傻了，每次把不同语言的资源发在不同的rc中，搞得现在好几个rc文件，每次拷贝切换烦的要死<img src ="http://www.cppblog.com/flyingxu/aggbug/8478.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-06-13 00:25 <a href="http://www.cppblog.com/flyingxu/archive/2006/06/13/8478.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>编译优化选项不匹配引起的一个bug</title><link>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Fri, 02 Jun 2006 02:32:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/8075.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/8075.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/8075.html</trackback:ping><description><![CDATA[有两个工程,w.exe和c.dll;开始的时候,如果exe是release版本用debug版本的dll时,函数调用会出错,我觉得也可以理解,没有多想.<br />今天遇到一个问题更奇怪,都是debug版本,但是exe和dll的optimizations设置不一样,都会出莫名的错误,出错行更搞笑,是<br />m_ComboBox.AddString(_T("") )<br />怎么查也查不出问题,把优化选项改成一致问题就没有了,搞不懂<img src ="http://www.cppblog.com/flyingxu/aggbug/8075.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-06-02 10:32 <a href="http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>错误提示"An unsupported operation was attempted"的原因</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 31 May 2006 09:27:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7963.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7963.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7963.html</trackback:ping><description><![CDATA[编译好了,运行一个程序,试图打开一个对话框时,对话框出不来,反倒是出来一个错误提示:<br />"An unsupported operation was attempted"<br />搜了一下:<a href="http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21023191.html"><br />http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21023191.html</a>里面有回答,的确是那样的,是resource id的问题.<br /><br />错误原因:<br />开始,给一个radio映射了一个变量:<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><font face="Courier New"> DDX_Radio(pDX, IDC_RADIO1, m_nFindType);</font></span></div>后来发现<u>IDC_RADIO1</u>这个id不好,改为 DDX_Radio(pDX, <u>IDC_RADIO_BIT,</u> m_nFindType);<br />编译当然不会出错,运行时,就出现异常了.如果在上面的代码上设个断点,然后跟踪进去,看的非常清楚.<br /><br /><img src ="http://www.cppblog.com/flyingxu/aggbug/7963.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-31 17:27 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在OnPaint()使用两次CPaintDC，关于::BeginPaint()/::EndPaint()</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 22 May 2006 15:39:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7517.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7517.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7517.html</trackback:ping><description><![CDATA[在重载CSplitterWnd中，重载了OnPaint()，<br />默认的代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> TODO: Add your message handler code here<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Courier New">}</font></span></div>wizard添加的代码居然有这样一行：<font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages<font color="#000000">，后面有个猜测。<br /></font></span></font><span style="COLOR: #008000"><font color="#000000">然后我继续写我的函数：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 调用基类，先</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    CSplitterWnd::OnPaint();<br />    <br /></span><span style="COLOR: #008000">     //</span></font><font face="Courier New"><span style="COLOR: #008000">利用dc画一些别的东西，但是实际上，它们永远不会被画出来<br /></span><span style="COLOR: #008000">   //</span><span style="COLOR: #008000">除非不调用基类的OnPaint()</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    m_rectButton.DrawButton(</span><span style="COLOR: #000000">&amp;</span></font><span style="COLOR: #000000"><font face="Courier New">dc);<br />}</font></span></div>结果我添加的东西怎么也不会被画出来，为什么会这样？<br /></font><br /><font color="#000000">看了CSplitterWnd::OnPaint()的代码，发现它也用了一个CPaintDC，而且也是个临时变量<br /></font><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CSplitterWnd::OnPaint()<br />{<br />    ASSERT_VALID(</span><span style="COLOR: #0000ff">this</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">);</span></font></div><font color="#000000">而关键的地方就在CPaintDC的ctor和dtor中了：在CPaintDC的ctor中调用了<br /><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="Courier New"><span style="COLOR: #000000">::BeginPaint(m_hWnd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pWnd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_hWnd, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m_ps)</span></font></div>而在CPaintDC的dtor中调用了<br /><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="Courier New"><span style="COLOR: #000000">::EndPaint(m_hWnd, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m_ps);</span></font></div>而：BeginPaint是开始根据当前的cliprect来画，EndPaint则会清空当前的cliprect。<br /></font><br /><font color="#000000">所以，前面调用基类的OnPaint的过程结束后，当前的cliprect为NULL，所以，第二个CPaintDC在视图画点什么时，cliprect已经为NULL，当然什么也画不上去了 ：）<br /></font><br /><font color="#000000">如果我一定想再用CPaintDC画点什么，怎么办？再次调用InvalidateRect，使得cliprect不为空。</font><br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    //注意临时变量声明的顺序，因为BeginPaint/EndPaint是不支持嵌套的<br />    //CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: Add your message handler code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    CSplitterWnd::OnPaint();<br />    <br />    //第二此调用<br />    InvalidateRect(</span><span style="COLOR: #000000">&amp;</span></font><font face="Courier New"><span style="COLOR: #000000">m_rectButton,FALSE);<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 在这里，device context for painting</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    m_rectButton.DrawButton(</span><span style="COLOR: #000000">&amp;</span></font><font face="Courier New"><span style="COLOR: #000000">dc);<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Courier New">}</font></span></div>所以，我猜测，所有用了CPaintDC的地方，MFC都会加一句：不要调用基类的函数啦～<br /><br /><font face="Courier New">呵呵，不知道我讲清楚没有</font><img src ="http://www.cppblog.com/flyingxu/aggbug/7517.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-22 23:39 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>把代码移植成UNICODE</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 18 May 2006 08:09:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7356.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7356.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7356.html</trackback:ping><description><![CDATA[
		<h2 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">动机</span>
				<font face="Arial">:</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">在没有装中文字体的机器上显示中文</span>
		</h2>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果不是</span>unicode,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">某些中文字符会在不同的</span>codepage<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上出现乱码</span>;<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果当前</span>codepage<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为韩文时</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">某些中文字会变成韩文的样子</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">奇怪</span>.</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step1: define _UNICODE, undefine _MBCS</font>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">宏定义</span>UNICODE, _UNICODE<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义两个也可以</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义一个也可以</span>,windows<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的头文件会保证两个都会被定义</span>.</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="Courier New">
						<span style="COLOR: #000000">#ifdef _UNICODE<br />#ifndef UNICODE<br /></span>
						<span style="COLOR: #0000ff">#define</span>
						<span style="COLOR: #000000"> UNICODE </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> UNICODE is used by Windows headers</span>
				</font>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
						<br />
						<font face="Courier New"> <br />#ifdef UNICODE<br />#ifndef _UNICODE<br /></font>
				</span>
				<font face="Courier New">
						<span style="COLOR: #0000ff">#define</span>
						<span style="COLOR: #000000"> _UNICODE        </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> _UNICODE is used by C-runtime/MFC headers</span>
				</font>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
		</div>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> </p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step2: </font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">更改变量类型</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">char -&gt; TCHAR</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">但是</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">,<span lang="ZH-CN">并不是说所有的</span>char<span lang="ZH-CN">类型都不能用了</span>.<span lang="ZH-CN">如果需要用</span>,<span lang="ZH-CN">并且函数的参数</span>/<span lang="ZH-CN">返回值什么的都不冲突</span>,char<span lang="ZH-CN">类型还是可以用的</span>.<o:p></o:p></span>
		</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span style="mso-font-kerning: 0pt">
						<font face="Arial">Step3: </font>
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-font-kerning: 0pt">更改常量字符串形式</span>
				<span style="mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">"</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">" -&gt; _T("</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">")</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">因为开始写程序时没有注意</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">,<span lang="ZH-CN">造成这样的常量字符串形式非常多</span>,<span lang="ZH-CN">一个个改起来很烦</span>,<span lang="ZH-CN">我写了个小插件</span>,<span lang="ZH-CN">可以讲</span></span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">选中后点一下</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">button<span lang="ZH-CN">就能变成</span>_T(</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">“</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">),<span lang="ZH-CN">有点用</span>,<span lang="ZH-CN">代码也非常的短</span>.<o:p></o:p></span>
		</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span style="mso-font-kerning: 0pt">
						<font face="Arial">Step4: </font>
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-font-kerning: 0pt">替换某些函数</span>
				<span style="mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如</span>atoi -&gt; _ttoi</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在这里遇到一个问题</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的替换</span>.</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按照</span>msdn, atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应该被</span>_ttof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">替换</span></p>
		<table style="mso-cellspacing: 0in" cellspacing="0" cellpadding="0" border="0">
				<tbody>
						<tr>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="17%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>TCHAR.H routine </b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 29%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="29%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_UNICODE &amp; _MBCS not defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 26%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="26%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_MBCS defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 28%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="28%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_UNICODE defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
						</tr>
						<tr>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="17%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>_tstof</b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 29%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="29%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>atof</b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 26%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="26%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>atof </b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 28%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="28%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>_wtof </b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是奇怪的是</span>,VC6<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面不认识</span>_tstof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个函数</span>,VC.net 2003<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就可以</span>.</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有两个解决的办法</span>:</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in">1)<span style="FONT: 7pt 'Times New Roman'">      </span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只是替换为浮点数</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以这里用</span>WideCharToMultiByte<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转化一下之后再调用</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也是可行的</span></p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in">2)<span style="FONT: 7pt 'Times New Roman'">      </span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">呵呵</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用</span>strtod<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的替换函数</span>_tcstod,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">哈哈</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当然参数要变一下,我觉得这个方法不错,不要被msdn限制死了</span></p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step5: </font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">检查一下调用其他</span>
				<font face="Arial">dll</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">的接口函数</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为项目还用了另外一个</span>dll,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中有些接口需要</span>char*<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">参数</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个时候就必须用</span>WideCharToMultiByte<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转换一下了</span>.<br /><br /><font size="4"><strong>VC里面的设置:</strong></font><br />1) 等把所有的编译error改完了之后一编译,除了个link错误,不过msdn有解释:<br />If you are using Unicode and MFC, you will get an unresolved external on _<b>WinMain@16</b> if you don’t create an entrypoint to <b>wWinMainCRTStartup</b>. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.) <br /><img src="http://www.codeguru.com/dbfiles/get_image.php?id=10285&amp;lbl=ALIN3_GIF&amp;ds=20050809" /><br />2)终于编译成功了,调试的时候却发现CString的值不能在QuickWatch窗口中显示了<br />tools-&gt;option-&gt;<br />in the debug tab u can find a check box Labeled "Display unicode strings"<br />Check it. <br /></p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">问题</span>
				<font face="Arial">:</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">直接用</span>
				<font face="Arial">ANSI</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">的</span>
				<font face="Arial">dll</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">中的</span>
				<font face="Arial">CString</font>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在使用</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">需要直接使用</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的一个变量</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</span>CString<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为这个</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">还没有改为</span>unicode,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以在直接使用其变量时有点问题</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使得值不对</span>.(是不是这个原因还没有完全验证,应该是的)</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">到这里</span>
				<font face="Arial">,</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">宣布移植失败</span>
				<font face="Arial">!</font>
		</h3>
		<p style="MARGIN: 12pt 0in 3pt">/*补充：<br />结果是失败，但是基本移植代码的所有步骤都有了。而且，也指出了如果需要调用的dll不是unicode，每次调用/传递参数时，都要转换，很烦。<br />后来我把dll的代码也移植了下，现在运行的很好，韩文、中文都可以显示，不管你当前语言是什么。<br />*/</p>
		<p style="MARGIN: 12pt 0in 3pt">还有一篇讲移植步骤的,更全面,适合更复杂的情况:<br />Cheat Sheet:Unicode-enabling Microsoft C/C++ Source Code (<a href="http://www.i18nguy.com/unicode/c-unicode.html">http://www.i18nguy.com/unicode/c-unicode.html</a>)</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> <o:p></o:p></p>
<img src ="http://www.cppblog.com/flyingxu/aggbug/7356.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-18 16:09 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>尽量用代码来替代资源中的属性</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/17/7299.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 17 May 2006 06:17:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/17/7299.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7299.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/17/7299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7299.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7299.html</trackback:ping><description><![CDATA[资源中的属性,是指写MFC程序时VC IDE的resource编辑器中可以设定的各种属性,比如<font face="Courier New">WS_EX_TRANSPARENT</font>或者<font face="Courier New">LVS_REPORT</font>.<br />而这些属性,都是可以用代码在程序初始化后加上去的,比如在<font face="Courier New">OnInitDialog()</font> 或者<font face="Courier New">OnCreate()</font>函数中.<br /><br />从方便性来说,肯定是在资源中设置这些属性更加方便,但是..<br />我遇到一种情况,在我的程序中,有两个rc文件,分别是中文和英文,这个时候,就发生了在英文资源中设置了属性修正了一个bug但是在中文版的资源中忘记设置,bug依然存在.而如果是在在代码中加上类似的代码:<br /><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="Courier New"><span style="COLOR: #000000">m_CrossRefTab.ModifyStyleEx(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,WS_EX_TRANSPARENT);</span></font></div>资源文件不用改变,而且修正了所有的问题.<br /><br />所以,我觉得,应该尽量用几行代码来替代在资源中的设定属性<img src ="http://www.cppblog.com/flyingxu/aggbug/7299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-17 14:17 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/17/7299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写了个很小的软件，快速切换鼠标左键/右键</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/11/6975.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 11 May 2006 14:33:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/11/6975.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/6975.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/11/6975.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/6975.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/6975.html</trackback:ping><description><![CDATA[
		<p>鼠标用久了，容易肩膀疼，所以有时候要换到左边，然后需要的时候，再换到右边。每次到控制面板里改还蛮烦的。</p>
		<p>现在好了，自己写了个程序，快速切换：当前是右手习惯就换到左手习惯；反之换到右手习惯<br />程序很小，只有2行代码：<img src="http://writeblog.csdn.net/fckeditor/editor/images/smiley/msn/regular_smile.gif" _fcksavedurl="/fckeditor/editor/images/smiley/msn/regular_smile.gif" /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #0000ff">
						<font face="Courier New">int</font>
				</span>
				<font face="Courier New">
						<span style="COLOR: #000000"> APIENTRY WinMain(HINSTANCE hInstance,<br />                     HINSTANCE hPrevInstance,<br />                     LPSTR     lpCmdLine,<br />                     </span>
						<span style="COLOR: #0000ff">int</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">       nCmdShow)<br />{<br />     </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> TODO: Place code here.</span>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font face="Courier New">
						<span style="COLOR: #000000">    BOOL bSwapped </span>
						<span style="COLOR: #000000">=</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000"> ::GetSystemMetrics(SM_SWAPBUTTON);<br />    ::SwapMouseButton(</span>
						<span style="COLOR: #000000">!</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">bSwapped);<br />    <br />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New">;<br />}</font>
				</span>
		</div>参考了这篇blog：<a href="http://blog.joycode.com/musicland/articles/36160.aspx">用C#实现鼠标左右键自动切换</a><br /><br />编译后的程序<a class="" title="MouseSwapper" href="http://flyingxu.googlepages.com/MouseSwapper.exe" target="_blank">下载</a><img src ="http://www.cppblog.com/flyingxu/aggbug/6975.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-11 22:33 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/11/6975.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对MFC8.1的白日梦</title><link>http://www.cppblog.com/flyingxu/archive/2006/04/09/5208.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Sun, 09 Apr 2006 13:50:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/04/09/5208.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/5208.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/04/09/5208.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/5208.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/5208.html</trackback:ping><description><![CDATA[今天突然想起一个问题，在mfc里面，比较典型的程序模型，dialog， sdi，mdi。特别的，有doc/view结构。有点类似于mvc结构，影响了一代又一代mfc程序员。<br />那么mfc8.1中，能不能多些这样的结构吧？把当前比较流行的设计模式，都做成现成的类，放在mfc中<br /><br />呵呵，那个时候，我估计没有人再说mfc设计的很烂了吧？<br /><br />不过很奇怪,开源社区那么多人在用java c#讨论设计模式,MFC领域的却很少,真是奇怪<img src ="http://www.cppblog.com/flyingxu/aggbug/5208.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-04-09 21:50 <a href="http://www.cppblog.com/flyingxu/archive/2006/04/09/5208.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Z - Order的初始顺序 － 草稿</title><link>http://www.cppblog.com/flyingxu/archive/2006/04/05/5049.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 05 Apr 2006 14:13:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/04/05/5049.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/5049.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/04/05/5049.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/5049.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/5049.html</trackback:ping><description><![CDATA[windows窗口系统的3个分层<br /><br />z－order的初始顺序就是窗口创建的先后顺序<br /><br />对于子窗口，z-order于tab 顺序的关系<img src ="http://www.cppblog.com/flyingxu/aggbug/5049.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-04-05 22:13 <a href="http://www.cppblog.com/flyingxu/archive/2006/04/05/5049.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CString的另一个问题,关于GetBuffer/ReleaseBuffer的几个错误例子</title><link>http://www.cppblog.com/flyingxu/archive/2006/03/21/4430.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 21 Mar 2006 09:51:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/03/21/4430.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/4430.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/03/21/4430.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/4430.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/4430.html</trackback:ping><description><![CDATA[关于GetBuffer/ReleaseBuffer,网上比较流行的一种说法是:如果你要直接修改CString的内部数据,就要调用GetBuffer/ReleaseBuffer.我也同意这样的表述.<br /><br />下面是几个例子,主要是错误的例子,来加深理解.<br />1<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">CString strTest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strTest.GetBuffer(</span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span></font><span style="COLOR: #000000"><font face="Courier New"> atoi(p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />strTest.ReleaseBuffer();</font></span></div>这种用法当然没有错,但是我认为这里的GetBuffer/ReleaseBuffer是没有必要的,为什么呢?因为<br /><font face="Courier New">int __cdecl atoi(const char *)</font> 的参数是const char*,CString的内部数据肯定不会被修改的.<br />所以上面的代码可以直接写成<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">CString strTest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> atoi((LPCTSTR)strTest);</span></font></div>顺便说一下GetBuffer的参数问题,网上的例子中,很多都是GetBuffer(5) GetBuffer(10)这样的常数,实际中的程序不可能是这么容易事先知道的,所以也就有了strTest.GetBuffer(strTest.GetLength() )的写法.其实,GetBuffer(0)就可以了.可以由GetBuffer的源码得到验证.<br /><br />2<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">   <font face="Courier New"> CString strTest </font></span><font face="Courier New"><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123 45</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">some other code</span></font><span style="COLOR: #008000"><br /><font face="Courier New"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font face="Courier New"><span style="COLOR: #000000">    CString strTest2 </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> strTest;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> seps[] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">char* pStr = strTest2.GetBuffer(0);</span></font><span style="COLOR: #008000"><br /><font face="Courier New"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font face="Courier New"><span style="COLOR: #000000">    pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strtok((</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span></font><font face="Courier New"><span style="COLOR: #000000">)(LPCTSTR)strTest2, seps);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">    //pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strtok(pStr</span></font><font face="Courier New"><span style="COLOR: #000000">, seps);</span></font><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span></font><font face="Courier New"><span style="COLOR: #000000">(pToken)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        pToken </span><span style="COLOR: #000000">=</span></font><span style="COLOR: #000000"><font face="Courier New"> strtok(NULL, seps);<br /></font><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        <font face="Courier New"> //strTest2.ReleaseBuffer(0);</font></span></div>运行上面的代码,可以看到strTest的值也变了,呵呵,这就是程序中一些关与CString的奇怪问题的起源.如果用注释中的GetBuffer/ReleaseBuffer方法,就一点问题也没有了.<br />同样,对于ReleaseBuffer的参数,缺省的是-1,但是我不建议.因为-1表示使用当前的00结束符位置来确定新的长度.而上面的例子中,strtok是会重新设置00结束符的,所以,安全的做法,就是把这个CString的长度设为0,ReleaseBuffer(0),反正它的内容已经变了,也没有人要用了.<br />说明一下,GetBuffer/ReleaseBuffer方法只能保证strTest不变,strTest2还是会变的.所以,对于一个成员变量,比如m_strTest2调用ReleaseBuffer要多一个心眼,局部变量就不用想这么多了.<br />那么怎么从最开始就意识到程序写错了呢?上面代码中<font face="Courier New">(<span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(LPCTSTR)是很危险的,把const去掉了,否则strtok是编译不过的,也从一个侧面说明了const的重要性.</span></font><br /><img src ="http://www.cppblog.com/flyingxu/aggbug/4430.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-03-21 17:51 <a href="http://www.cppblog.com/flyingxu/archive/2006/03/21/4430.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于CString的两个问题</title><link>http://www.cppblog.com/flyingxu/archive/2006/03/02/3631.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 02 Mar 2006 01:29:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/03/02/3631.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/3631.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/03/02/3631.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/3631.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/3631.html</trackback:ping><description><![CDATA[<P><STRONG>关于CString的两个问题<BR></STRONG><FONT size=2>读</FONT><A class=postTitle2 id=viewpost1_TitleUrl href="http://dayouluo.cnblogs.com/archive/2005/04/17/139086.html"><FONT size=2>CString,string,char*的综合比较(一)</FONT></A>&nbsp;<BR><BR>1 CString的基类<BR>在《比较》一文中，写到：<BR>“CString（typedef CStringT&lt;TCHAR, StrTraitMFC&lt;TCHAR&gt;&gt; CString）为Visual C++中最常用的字符串类，继承自CSimpleStringT类，主要应用在MFC和ATL编程中，主要数据类型有char(应用于ANSI)，wchar_t(unicode)，TCHAR(ANSI与unicode均可)；”<BR>我第一感觉就是文章写错了，因为我看过CString的源码的啊：<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><STRONG>struct</STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;CStringData<BR><IMG id=Codehighlighter1_19_292_Open_Image onclick="this.style.display='none'; Codehighlighter1_19_292_Open_Text.style.display='none'; Codehighlighter1_19_292_Closed_Image.style.display='inline'; Codehighlighter1_19_292_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_19_292_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_19_292_Closed_Text.style.display='none'; Codehighlighter1_19_292_Open_Image.style.display='inline'; Codehighlighter1_19_292_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_19_292_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN></STRONG><SPAN id=Codehighlighter1_19_292_Open_Text><STRONG><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">long</SPAN><SPAN style="COLOR: #000000">&nbsp;nRefs;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;reference&nbsp;count</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;nDataLength;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;length&nbsp;of&nbsp;data&nbsp;(including&nbsp;terminator)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;nAllocLength;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN></STRONG><STRONG><SPAN style="COLOR: #008000">&nbsp;length&nbsp;of&nbsp;allocation<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;TCHAR&nbsp;data[nAllocLength]</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><SPAN style="COLOR: #000000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;TCHAR</STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;data()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;TCHAR*&nbsp;to&nbsp;managed&nbsp;data</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG id=Codehighlighter1_263_290_Open_Image onclick="this.style.display='none'; Codehighlighter1_263_290_Open_Text.style.display='none'; Codehighlighter1_263_290_Closed_Image.style.display='inline'; Codehighlighter1_263_290_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_263_290_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_263_290_Closed_Text.style.display='none'; Codehighlighter1_263_290_Open_Image.style.display='inline'; Codehighlighter1_263_290_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_263_290_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_263_290_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;(TCHAR</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">)(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);&nbsp;}</SPAN></SPAN></STRONG><SPAN style="COLOR: #000000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</STRONG></SPAN></SPAN><STRONG><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">class</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">&nbsp;CString<BR><IMG id=Codehighlighter1_310_934_Open_Image onclick="this.style.display='none'; Codehighlighter1_310_934_Open_Text.style.display='none'; Codehighlighter1_310_934_Closed_Image.style.display='inline'; Codehighlighter1_310_934_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_310_934_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_310_934_Closed_Text.style.display='none'; Codehighlighter1_310_934_Open_Image.style.display='inline'; Codehighlighter1_310_934_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_310_934_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN></STRONG><SPAN id=Codehighlighter1_310_934_Open_Text><STRONG><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">:<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></STRONG><STRONG><SPAN style="COLOR: #008000">&nbsp;Constructors<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>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;constructs&nbsp;empty&nbsp;CString</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString();<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;copy&nbsp;constructor</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000">&nbsp;CString</SPAN><SPAN style="COLOR: #000000">&amp;</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">&nbsp;stringSrc);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;from&nbsp;a&nbsp;single&nbsp;character</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(TCHAR&nbsp;ch,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;nRepeat&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;from&nbsp;an&nbsp;ANSI&nbsp;string&nbsp;(converts&nbsp;to&nbsp;TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(LPCSTR&nbsp;lpsz);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;from&nbsp;a&nbsp;UNICODE&nbsp;string&nbsp;(converts&nbsp;to&nbsp;TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(LPCWSTR&nbsp;lpsz);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;subset&nbsp;of&nbsp;characters&nbsp;from&nbsp;an&nbsp;ANSI&nbsp;string&nbsp;(converts&nbsp;to&nbsp;TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(LPCSTR&nbsp;lpch,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">&nbsp;nLength);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;subset&nbsp;of&nbsp;characters&nbsp;from&nbsp;a&nbsp;UNICODE&nbsp;string&nbsp;(converts&nbsp;to&nbsp;TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(LPCWSTR&nbsp;lpch,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">&nbsp;nLength);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;from&nbsp;unsigned&nbsp;characters</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000">&nbsp;unsigned&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">*</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">&nbsp;psz);<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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Attributes&nbsp;&amp;&nbsp;Operations</SPAN></STRONG></DIV>
<P></SPAN><STRONG>但是看文章的样子，也不像是粗制滥造的，心里很是疑惑。<BR>后来再打开VC7的源码看，果然：<BR></STRONG></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"><STRONG><SPAN style="COLOR: #000000">typedef&nbsp;ATL::CStringT</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;TCHAR,&nbsp;StrTraitMFC</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;TCHAR&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN></STRONG><SPAN style="COLOR: #000000"><STRONG>&nbsp;CString;<BR></STRONG></SPAN></DIV>
<P><STRONG>看来微软在不知不觉中做了这么大的变化。<BR><BR>2 <BR>“string是方便的，可以从几乎所有的字符串构造而来，包括CString和char*；&nbsp;<BR>&nbsp;CString次之，可以从基本的一些字符串变量构造而来，包括char*等； ”<BR>的确，如下的代码是可以编译的：<BR></STRONG></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"><STRONG><SPAN style="COLOR: #000000">CString&nbsp;strTest&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">test</SPAN><SPAN style="COLOR: #000000">"</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;sTest(strTest);</SPAN></STRONG></DIV>
<P><STRONG>但是这是表明string比CString方便吗？<BR>实际上，在string sTest(strTest);中有一个函数被调用，就是：<BR></STRONG></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"><STRONG><SPAN style="COLOR: #000000">_AFX_INLINE&nbsp;CString::</SPAN><SPAN style="COLOR: #0000ff">operator</SPAN><SPAN style="COLOR: #000000">&nbsp;LPCTSTR()&nbsp;</SPAN><SPAN style="COLOR: #0000ff">const</SPAN></STRONG><SPAN style="COLOR: #000000"><BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</STRONG></SPAN><STRONG><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;m_pchData;&nbsp;}</SPAN></STRONG></DIV>
<P><STRONG>然后才是string构造生成，这能说是string比CString方便吗？应该说是CString比string方便才好。<BR>虽然可以用<BR></STRONG></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000"><STRONG>CString&nbsp;strTest(sTest.c_str()&nbsp;);</STRONG></SPAN></DIV>
<P><STRONG>来初始化CString，但是CString没有参数为string的构造函数，也是一个小小的遗憾，毕竟string是c++标准库的一部分了。</STRONG></P><img src ="http://www.cppblog.com/flyingxu/aggbug/3631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-03-02 09:29 <a href="http://www.cppblog.com/flyingxu/archive/2006/03/02/3631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC wizard出错: Parsing error : Expected "*/" 的原因</title><link>http://www.cppblog.com/flyingxu/archive/2006/02/17/3306.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Fri, 17 Feb 2006 05:16:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/02/17/3306.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/3306.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/02/17/3306.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/3306.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/3306.html</trackback:ping><description><![CDATA[当我在运行wizard,选到某一个类时,遇到了这个错误提示:<BR>Parsing error : Expected "*/"<BR>出错的代码如下<BR>&nbsp;
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">BEGIN_EVENTSINK_MAP(CMonitorView, CFormView)<BR>&nbsp;&nbsp;&nbsp; //{{AFX_EVENTSINK_MAP(CMonitorView)<BR>&nbsp;&nbsp;&nbsp; ON_EVENT(CMonitorView,&nbsp;IDC_REGVALUE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">72</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">&nbsp;Leave&nbsp;Cell&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnLeaveCellRV,&nbsp;VTS_NONE)&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; //}}AFX_EVENTSINK_MAP<BR>END_EVENTSINK_MAP()</SPAN></DIV>但是我看来看去没有问题.<BR><BR>后来找到最初的代码一对比,原来/* Leave<FONT style="BACKGROUND-COLOR: #ff1493" color=#000000> </FONT>Cell */中间有个空格, 是的wizard解析出错,去掉空格就好了.哈<BR><img src ="http://www.cppblog.com/flyingxu/aggbug/3306.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-02-17 13:16 <a href="http://www.cppblog.com/flyingxu/archive/2006/02/17/3306.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用CString作为Key使用CMap</title><link>http://www.cppblog.com/flyingxu/archive/2005/12/27/4274.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 26 Dec 2005 23:17:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2005/12/27/4274.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/4274.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2005/12/27/4274.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/4274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/4274.html</trackback:ping><description><![CDATA[CMap在用CString做key类型时，ARG_KEY要选LPCTSTR <img height="1" src="http://blog.csdn.net/flyingxu/aggbug/562852.aspx" width="1" /><br />文章来源:<a href="http://blog.csdn.net/flyingxu/archive/2005/12/26/562852.aspx">http://blog.csdn.net/flyingxu/archive/2005/12/26/562852.aspx</a><br /><br /><p>遇到好几个人说CMap在用CString做key类型时有问题，说用int和DWORD就可以，用CString就不行。因此很多人推荐使用MFC中的CMapStringToPtr之类。</p><p>看下面的代码：<br />//.h<br />    CMap&lt;CString, LPCTSTR, int, int&gt; typeMap;<br />//.cpp<br />    typeMap.SetAt(_T("ONE"),1);<br />    typeMap.SetAt(_T("TWO"),2);<br /><br />    int nValue = 0;<br />    BOOL ret = typeMap.Lookup(_T("ONE"), nValue);<br />    ret = typeMap.Lookup(_T("THREE"), nValue);<br />    ret = typeMap.Lookup(_T("TWO"), nValue);<br />我的代码运行的很好，我觉得关键是ARG_KEY要选LPCTSTR </p><img src ="http://www.cppblog.com/flyingxu/aggbug/4274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2005-12-27 07:17 <a href="http://www.cppblog.com/flyingxu/archive/2005/12/27/4274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>