﻿<?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++博客-GoGo Jeffrey-文章分类-技术点</title><link>http://www.cppblog.com/jeffrey78/category/687.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 15 Jun 2008 02:18:45 GMT</lastBuildDate><pubDate>Sun, 15 Jun 2008 02:18:45 GMT</pubDate><ttl>60</ttl><item><title>跟踪焦点去向的方法，可以使用spy++</title><link>http://www.cppblog.com/jeffrey78/articles/2559.html</link><dc:creator>Jeffrey.Coding</dc:creator><author>Jeffrey.Coding</author><pubDate>Wed, 11 Jan 2006 03:34:00 GMT</pubDate><guid>http://www.cppblog.com/jeffrey78/articles/2559.html</guid><wfw:comment>http://www.cppblog.com/jeffrey78/comments/2559.html</wfw:comment><comments>http://www.cppblog.com/jeffrey78/articles/2559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jeffrey78/comments/commentRss/2559.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jeffrey78/services/trackbacks/2559.html</trackback:ping><description><![CDATA[<P>近日工作遇到一个问题，在某个treeview控件中使用键盘的上下箭头按键选择树节点，使到面版右面相应切换到具体的界面时候，发现在某几个节点时会突然丢失焦点，出现了灰色选择条的现象。焦点到底去哪里呢，从表象来看毫无头绪。<BR><BR>正郁闷之制突然想到了vc6.0中附带的一个工具spy++。此工具可以跟踪界面上的任何控件窗体，以及任何与此窗体有关的window消息。而且使用简单。事实胜于雄辩，立即行动。用spy++监视treeview的窗口消息。而且把需要监视的消息设置为全部（晕阿，太多的消息会看傻人的。不过怕有遗漏，所以只好设置全部，后来发现可以只监视wm_killfocus和wm_setfocus两个消息，这可以大大减少检查量<IMG height=1 src="/jeffrey78/admin/FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.1.34886%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&amp;r=FreeTextBoxControls.Resources.Images.Utility.spacer.gif&amp;t=632699064217187500" width=1><IMG height=1 src="/jeffrey78/admin/FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.1.34886%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&amp;r=FreeTextBoxControls.Resources.Images.Utility.spacer.gif&amp;t=632699064217187500" width=1>）。现在spy++按需求都配置好了，开始工作。立马切换会要监视的treeview控件上，继续选择不同的节点，不多久焦点又丢失了。我马上切换回spy++监视画面，查找良久果然发现了wm_killfocus消息。检查此消息是对哪个窗体发得（得到此窗体的句柄，然后用spy++查找界面上所有控件看是否有此句柄得控件。最后查出此窗口句柄就是treeview右面的面版）。<BR><BR>总结，当treeview中某个节点被选择后，焦点会切换离开treeview到达右面相应出现的面版。怀疑是底层作的好事，这就不多追究了，底层的事情还管阿，还不累死人啊，知道原因就好了。<BR><BR>解决方案，强制把焦点留在treeview上面。哈哈，奈我何阿，见代码<BR>void CUsrManDlg::OnSelchangedTreeUsrman(NMHDR *pNMHDR, LRESULT *pResult)<BR>{</P>
<P>&nbsp;LPNMTREEVIEW pNMTreeView = reinterpret_cast&lt;LPNMTREEVIEW&gt;(pNMHDR);<BR>&nbsp;DWORD dwItemId = pNMTreeView-&gt;itemNew.lParam;<BR>&nbsp;ShowSubDlg(dwItemId);</P>
<P>&nbsp;<STRONG>//由于在treeview里面上下移动的时候，某些节点上会丢失了焦点，原因是焦点跑到右边的版面中得控件上了，所以下面一句代码是强制把焦点流在treeview上。<BR></STRONG>&nbsp;m_treeUsrMan.SetFocus();<BR>&nbsp;<BR>&nbsp;*pResult = 0;<BR>}<BR><BR><BR><BR><BR><BR><IMG height=1 src="/jeffrey78/admin/FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.1.34886%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&amp;r=FreeTextBoxControls.Resources.Images.Utility.spacer.gif&amp;t=632699064217187500" width=1><IMG src="/jeffrey78/admin/FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.1.34886%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&amp;r=FreeTextBoxControls.Resources.Images.Utility.spacer.gif&amp;t=632699064217187500"><IMG height=1 src="/jeffrey78/admin/FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.1.34886%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&amp;r=FreeTextBoxControls.Resources.Images.Utility.spacer.gif&amp;t=632699064217187500" width=1><BR><BR></P><img src ="http://www.cppblog.com/jeffrey78/aggbug/2559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jeffrey78/" target="_blank">Jeffrey.Coding</a> 2006-01-11 11:34 <a href="http://www.cppblog.com/jeffrey78/articles/2559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在堆栈中分配内存_alloca</title><link>http://www.cppblog.com/jeffrey78/articles/2319.html</link><dc:creator>Jeffrey.Coding</dc:creator><author>Jeffrey.Coding</author><pubDate>Sat, 31 Dec 2005 07:22:00 GMT</pubDate><guid>http://www.cppblog.com/jeffrey78/articles/2319.html</guid><wfw:comment>http://www.cppblog.com/jeffrey78/comments/2319.html</wfw:comment><comments>http://www.cppblog.com/jeffrey78/articles/2319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jeffrey78/comments/commentRss/2319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jeffrey78/services/trackbacks/2319.html</trackback:ping><description><![CDATA[<P>如果在一个函数里面分配内存，在函数退出时释放内存的情况下可以使用_alloca代替malloc。前者<BR>是可以在函数退出时自动释放内存块，而不用显式使用free函数，而且在堆栈中分配内存可以减少<BR>在堆中分配内存的缺点---产生内存碎片。<BR><BR><STRONG>alloca</STRONG> allocates <I>size</I> bytes from the program stack. The allocated space is automatically freed when the calling function exits (not when the allocation merely passes out of scope). Therefore, do not pass the pointer value returned by <B>_alloca</B> as an argument to <A href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vclib/html/_crt_free.htm">free</A>.<BR><BR>详细用法请参考msdn<BR><BR></P><img src ="http://www.cppblog.com/jeffrey78/aggbug/2319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jeffrey78/" target="_blank">Jeffrey.Coding</a> 2005-12-31 15:22 <a href="http://www.cppblog.com/jeffrey78/articles/2319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>richedit 控件在不同语言环境的操作系统上可能出现的乱码问题</title><link>http://www.cppblog.com/jeffrey78/articles/2214.html</link><dc:creator>Jeffrey.Coding</dc:creator><author>Jeffrey.Coding</author><pubDate>Wed, 28 Dec 2005 09:01:00 GMT</pubDate><guid>http://www.cppblog.com/jeffrey78/articles/2214.html</guid><wfw:comment>http://www.cppblog.com/jeffrey78/comments/2214.html</wfw:comment><comments>http://www.cppblog.com/jeffrey78/articles/2214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jeffrey78/comments/commentRss/2214.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jeffrey78/services/trackbacks/2214.html</trackback:ping><description><![CDATA[由于工作上需要，把软件移植到英文版的os上（软件已是unicode版本的），发现richedit控件上显示的字体（本来内容应该显示为中文）乱码了。<BR><BR>发生乱码的具体代码：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetDlgItemText(IDCE_MEMO, m_Results[nIdx].Content);<BR>IDCE_MEMO为richedit的资源名，m_Results[nIdx].Content为要显示的字符串内容（已经是unicode编码的了）。<BR><BR>查找原因：可能是控件不了解字符串已经是unicode代码，所以控件根据locale 的code page来硬性将代码转换为unicode显示，所以出现乱码。<BR><BR>解决方法：<BR>#ifdef UNICODE<BR>&nbsp;<STRONG>&nbsp;//请注意，因为是unicode版本，所以codepage要用1200，以告诉RichEdit传过去的文本已经是unicode，以免出现乱码，详情请看MSDN。<BR></STRONG>&nbsp;&nbsp;SETTEXTEX SetTxtEx;<BR>&nbsp;&nbsp;SetTxtEx.flags = ST_DEFAULT;<BR>&nbsp;&nbsp;SetTxtEx.codepage = 1200;<BR>&nbsp;&nbsp;BOOL bRet = ::SendMessage(::GetDlgItem(m_hWnd, IDCE_MEMO), EM_SETTEXTEX, (WPARAM)&amp;SetTxtEx, (LPARAM)m_Results[nIdx].Content);<BR>&nbsp;&nbsp;ASSERT(bRet);<BR>#else<BR>&nbsp;&nbsp;SetDlgItemText(IDCE_MEMO, m_Results[nIdx].Content);<BR>#endif<BR><BR>
<DD>The code page used to translate the text to Unicode. If <B>codepage</B> is 1200 (Unicode code page), no translation is done. If <B>codepage</B> is CP_ACP, the system code page is used. </DD><BR><BR><img src ="http://www.cppblog.com/jeffrey78/aggbug/2214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jeffrey78/" target="_blank">Jeffrey.Coding</a> 2005-12-28 17:01 <a href="http://www.cppblog.com/jeffrey78/articles/2214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>