<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wut I am &#187; mfc</title>
	<atom:link href="http://wutiam.net/tag/mfc/feed/" rel="self" type="application/rss+xml" />
	<link>http://wutiam.net</link>
	<description>I&#039;m islet8, I&#039;m what I am</description>
	<lastBuildDate>Wed, 25 Jan 2012 14:11:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>遍历 CTreeCtrl</title>
		<link>http://wutiam.net/2009/05/ctreectrl-traversal/</link>
		<comments>http://wutiam.net/2009/05/ctreectrl-traversal/#comments</comments>
		<pubDate>Mon, 04 May 2009 11:52:03 +0000</pubDate>
		<dc:creator>islet8</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mfc]]></category>
		<category><![CDATA[vs/vc++]]></category>

		<guid isPermaLink="false">http://wutiam.net/?p=74</guid>
		<description><![CDATA[CTreeCtrl 的 GetNextItem 成员函数很诡异，nCode 设为 TVGN_NEXT &#124; TVGN_CHILD 会一直返回传进去的 hItem 值，而不是返回下一个兄弟 item “或”第一个 child item。 所以，只好自己写遍历函数，没有采用递归的做法，用了一个 STL List 容器来保存下一个兄弟 item 和第一个 child item，遍历返回的依据是 item 的 lParam 值等于给定的值。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [...]
Related posts:<ul>
<li><a href='http://wutiam.net/2009/05/msg-response-for-dynamic-created-ctreectrl-instance/' rel='bookmark' title='动态创建的 CTreeCtrl 实例的消息响应'>动态创建的 CTreeCtrl 实例的消息响应</a></li>
<li><a href='http://wutiam.net/2010/09/lower_bound-strange-compiling-error-in-ms-stl/' rel='bookmark' title='微软 STL lower_bound() 在 DEBUG 下的诡异编译错误'>微软 STL lower_bound() 在 DEBUG 下的诡异编译错误</a></li>
<li><a href='http://wutiam.net/2010/06/lambdas-auto-and-static-assert-c-0x-features-in-vc10/' rel='bookmark' title='VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert'>VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>CTreeCtrl 的 GetNextItem 成员函数很诡异，nCode 设为 TVGN_NEXT | TVGN_CHILD 会一直返回传进去的 hItem 值，而不是返回下一个兄弟 item “或”第一个 child item。</p>
<p>所以，只好自己写遍历函数，没有采用递归的做法，用了一个 STL List 容器来保存下一个兄弟 item 和第一个 child item，遍历返回的依据是 item 的 lParam 值等于给定的值。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">HTREEITEM CModelNodeTreePane<span style="color: #008080;">::</span>_GetTreeItemByID<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> uiItemID<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    HTREEITEM   hCurrItem <span style="color: #000080;">=</span> m_kModelNodeTreeCtrl.<span style="color: #007788;">GetRootItem</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
                hItem<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">list</span> kItemList<span style="color: #008080;">;</span>
&nbsp;
    kItemList.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>hCurrItem<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>kItemList.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        hCurrItem <span style="color: #000080;">=</span> kItemList.<span style="color: #007788;">front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        kItemList.<span style="color: #007788;">pop_front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>m_kModelNodeTreeCtrl.<span style="color: #007788;">GetItemData</span><span style="color: #008000;">&#40;</span>hCurrItem<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> uiItemID<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">return</span> hCurrItem<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>hItem <span style="color: #000080;">=</span> m_kModelNodeTreeCtrl.<span style="color: #007788;">GetChildItem</span><span style="color: #008000;">&#40;</span>hCurrItem<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            kItemList.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>hItem<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>hItem <span style="color: #000080;">=</span> m_kModelNodeTreeCtrl.<span style="color: #007788;">GetNextSiblingItem</span><span style="color: #008000;">&#40;</span>hCurrItem<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            kItemList.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>hItem<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Related posts:<ul>
<li><a href='http://wutiam.net/2009/05/msg-response-for-dynamic-created-ctreectrl-instance/' rel='bookmark' title='动态创建的 CTreeCtrl 实例的消息响应'>动态创建的 CTreeCtrl 实例的消息响应</a></li>
<li><a href='http://wutiam.net/2010/09/lower_bound-strange-compiling-error-in-ms-stl/' rel='bookmark' title='微软 STL lower_bound() 在 DEBUG 下的诡异编译错误'>微软 STL lower_bound() 在 DEBUG 下的诡异编译错误</a></li>
<li><a href='http://wutiam.net/2010/06/lambdas-auto-and-static-assert-c-0x-features-in-vc10/' rel='bookmark' title='VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert'>VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://wutiam.net/2009/05/ctreectrl-traversal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>动态创建的 CTreeCtrl 实例的消息响应</title>
		<link>http://wutiam.net/2009/05/msg-response-for-dynamic-created-ctreectrl-instance/</link>
		<comments>http://wutiam.net/2009/05/msg-response-for-dynamic-created-ctreectrl-instance/#comments</comments>
		<pubDate>Mon, 04 May 2009 11:38:39 +0000</pubDate>
		<dc:creator>islet8</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mfc]]></category>
		<category><![CDATA[vs/vc++]]></category>

		<guid isPermaLink="false">http://wutiam.net/?p=71</guid>
		<description><![CDATA[由于程序里的 CTreeCtrl 控件实例是通过 CTreeCtr::Create() 来创建的，无法通过 VS 的 Properties 面板里的 Control Events 工具来生成消息映射函数，但控件又需要响应鼠标点击事件，这时最简单的办法就是重载 CTreeCtr 实例的 owner 的 OnNotify() 成员虚函数（这个 owner 也必然是 CWnd 的子类）： protected: virtual BOOL OnNotify&#40;WPARAM wParam, LPARAM lParam, LRESULT* pResult&#41;; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 BOOL CTreePane::OnNotify&#40;WPARAM wParam, LPARAM lParam, LRESULT* pResult&#41; [...]
Related posts:<ul>
<li><a href='http://wutiam.net/2009/05/ctreectrl-traversal/' rel='bookmark' title='遍历 CTreeCtrl'>遍历 CTreeCtrl</a></li>
<li><a href='http://wutiam.net/2010/09/lower_bound-strange-compiling-error-in-ms-stl/' rel='bookmark' title='微软 STL lower_bound() 在 DEBUG 下的诡异编译错误'>微软 STL lower_bound() 在 DEBUG 下的诡异编译错误</a></li>
<li><a href='http://wutiam.net/2010/06/lambdas-auto-and-static-assert-c-0x-features-in-vc10/' rel='bookmark' title='VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert'>VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>由于程序里的 CTreeCtrl 控件实例是通过 CTreeCtr::Create() 来创建的，无法通过 VS 的 Properties 面板里的 Control Events 工具来生成消息映射函数，但控件又需要响应鼠标点击事件，这时最简单的办法就是重载 CTreeCtr 实例的 owner 的 OnNotify() 成员虚函数（这个 owner 也必然是 CWnd 的子类）：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">virtual</span> BOOL OnNotify<span style="color: #008000;">&#40;</span>WPARAM wParam, LPARAM lParam, LRESULT<span style="color: #000040;">*</span> pResult<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">BOOL CTreePane<span style="color: #008080;">::</span><span style="color: #007788;">OnNotify</span><span style="color: #008000;">&#40;</span>WPARAM wParam, LPARAM lParam, LRESULT<span style="color: #000040;">*</span> pResult<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    NMHDR<span style="color: #000040;">*</span> pNMHDR <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>NMHDR<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>lParam<span style="color: #008080;">;</span>
    ASSERT<span style="color: #008000;">&#40;</span>pNMHDR <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>pNMHDR<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>code<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">case</span> TVN_SELCHANGED<span style="color: #008080;">:</span>
        _OnTreeCtrlSelChanged<span style="color: #008000;">&#40;</span>wParam, lParam, pResult<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> CWnd<span style="color: #008080;">::</span><span style="color: #007788;">OnNotify</span><span style="color: #008000;">&#40;</span>wParam, lParam, pResult<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Related posts:<ul>
<li><a href='http://wutiam.net/2009/05/ctreectrl-traversal/' rel='bookmark' title='遍历 CTreeCtrl'>遍历 CTreeCtrl</a></li>
<li><a href='http://wutiam.net/2010/09/lower_bound-strange-compiling-error-in-ms-stl/' rel='bookmark' title='微软 STL lower_bound() 在 DEBUG 下的诡异编译错误'>微软 STL lower_bound() 在 DEBUG 下的诡异编译错误</a></li>
<li><a href='http://wutiam.net/2010/06/lambdas-auto-and-static-assert-c-0x-features-in-vc10/' rel='bookmark' title='VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert'>VS2010 中的 C++ 0x 新特性：Lambdas、auto 和 static_assert</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://wutiam.net/2009/05/msg-response-for-dynamic-created-ctreectrl-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

