﻿<?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</title><link>http://www.cppblog.com/flyingxu/</link><description>to get ready...</description><language>zh-cn</language><lastBuildDate>Wed, 22 Apr 2026 02:27:48 GMT</lastBuildDate><pubDate>Wed, 22 Apr 2026 02:27:48 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>2</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>关于IServiceProvider的一篇很好的文章</title><link>http://www.cppblog.com/flyingxu/archive/2007/01/05/17275.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 04 Jan 2007 16:14:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2007/01/05/17275.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/17275.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2007/01/05/17275.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/17275.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/17275.html</trackback:ping><description><![CDATA[关于几个HTML文档接口的使用探讨 <br /><a href="http://www.vckbase.com/vckbase/vckbase10/vc/nonctrls/atlcomocx_02/1002005.htm">http://www.vckbase.com/vckbase/vckbase10/vc/nonctrls/atlcomocx_02/1002005.htm</a><br /><br />我觉得讲的很清楚，呵呵<img src ="http://www.cppblog.com/flyingxu/aggbug/17275.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-01-05 00:14 <a href="http://www.cppblog.com/flyingxu/archive/2007/01/05/17275.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>thinking in c++ 习题答案</title><link>http://www.cppblog.com/flyingxu/archive/2006/08/09/11022.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 08 Aug 2006 16:19:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/08/09/11022.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/11022.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/08/09/11022.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/11022.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/11022.html</trackback:ping><description><![CDATA[<p>这个答案本来是作者卖钱的，我忘了是从那个网站下载的了，估计不全。<br>现在有人要，就放上来吧</p>
<p><a href="http://www.cppblog.com/Files/flyingxu/ThinkinginCppExercise.rar">http://www.cppblog.com/Files/flyingxu/ThinkinginCppExercise.rar</a> <br><br>(未验证，可能不全，或者根本就不是答案)<br><br></p>
<img src ="http://www.cppblog.com/flyingxu/aggbug/11022.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-08-09 00:19 <a href="http://www.cppblog.com/flyingxu/archive/2006/08/09/11022.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>1</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>10</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>Make header files self-sufficient的一个例子</title><link>http://www.cppblog.com/flyingxu/archive/2006/06/23/8908.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Fri, 23 Jun 2006 12:56:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/06/23/8908.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/8908.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/06/23/8908.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/8908.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/8908.html</trackback:ping><description><![CDATA[C＋＋编程规范中第23条中说：<br />If one header file won't work unless the file that includes it also includes another header, that's gauche and puts unnecessary burden on that header file's users.<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: #008000">//</span><span style="COLOR: #008000">a.h</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">class</font></span><font face="Courier New"><span style="COLOR: #000000"> A <br />{<br /> </span><span style="COLOR: #0000ff">int</span></font><span style="COLOR: #000000"><font face="Courier New"> a;<br />};</font></span></div> <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">b.h<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">注意：b.h并没有include a.h</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">class</font></span><span style="COLOR: #000000"><font face="Courier New"> B <br />{<br /> A a;<br />};</font> </span></div>用的时候怎么用呢？比如在main.cpp中想用class B<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: #008000">//</span><span style="COLOR: #008000">main.cpp</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">a.h</span><span style="COLOR: #000000">"</span></font><span style="COLOR: #000000"><br /><font face="Courier New">#include </font></span><font face="Courier New"><span style="COLOR: #000000">"</span><span style="COLOR: #000000">b.h</span><span style="COLOR: #000000">"</span></font><span style="COLOR: #000000"><br /></span><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">B b;<br /></span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/dot.gif" /><br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">do something on b</span></font></div>可以看到，main为了使用B，还得包含a.h，这就是上面一段英语说的：<br />如果一个头文件（b.h）不能工作，除非包含它（b.h）的文件（也就是main.cpp）也包含另一个头文件（a.h）...<br /><br />hehe，当我第一次遇到这种情况时，想了半天也想不明白为什么我明明包含了b.h还是不能用B啊<br /><br />那么，正确的写法应该是什么呢？<br />在类B的作者在设计B的时候，就应该想到用户只需要#include "b.h"就可以使用这个class B。所以，在b.h文件中，应该写明#include "a.h"，而不是让用户在main.cpp中去include "a.h"<br /><br />:)<img src ="http://www.cppblog.com/flyingxu/aggbug/8908.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-23 20:56 <a href="http://www.cppblog.com/flyingxu/archive/2006/06/23/8908.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>