﻿<?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>博客园-邓石的博客</title><link>http://www.cnblogs.com/smartstone/</link><description>成功与其说是取决于人的才能，不如说取决于人的热忱。</description><language>zh-cn</language><lastBuildDate>Sun, 07 Sep 2008 09:20:12 GMT</lastBuildDate><pubDate>Sun, 07 Sep 2008 09:20:12 GMT</pubDate><ttl>60</ttl><item><title>如何隐藏TabControl中TabPage的页标签</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/27/1278101.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Wed, 27 Aug 2008 14:09:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/27/1278101.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1278101.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/27/1278101.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1278101.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1278101.html</trackback:ping><description><![CDATA[隐藏TabControl的标签必须通过继承TabControl并自行重画来实现。下面是一个重画TabControl的完整的例子：&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
<div class="cnblogs_code"><img id="Code_Closed_Image_220411" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_220411').style.display='none'; document.getElementById('Code_Open_Image_220411').style.display='inline'; document.getElementById('Code_Open_Text_220411').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_220411" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_220411').style.display='none'; getElementById('Code_Closed_Image_220411').style.display='inline'; getElementById('Code_Closed_Text_220411').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_220411">Code</span><span id="Code_Open_Text_220411" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;FTabControl&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;System.Windows.Forms.TabControl{&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;System.ComponentModel.Container&nbsp;&nbsp;&nbsp;components&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color&nbsp;&nbsp;&nbsp;BackColor</span><span style="color: #000000">=</span><span style="color: #000000">Color.FromArgb(</span><span style="color: #800080">227</span><span style="color: #000000">,</span><span style="color: #800080">237</span><span style="color: #000000">,</span><span style="color: #800080">251</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color&nbsp;&nbsp;&nbsp;ButtonColor;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color&nbsp;&nbsp;&nbsp;ButtonHighlightColor;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color&nbsp;&nbsp;&nbsp;BorderColor</span><span style="color: #000000">=</span><span style="color: #000000">Color.Black;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;UserChangeTab</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;FTabControl(){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;InitializeComponent();&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;SetDafaultStyle();&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;SetStyle(ControlStyles.UserPaint,</span><span style="color: #0000ff">true</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">#region</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Component&nbsp;&nbsp;&nbsp;Designer&nbsp;&nbsp;&nbsp;generated&nbsp;&nbsp;&nbsp;code&nbsp;&nbsp;&nbsp;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;InitializeComponent(){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;components&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;System.ComponentModel.Container();&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">#endregion</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SetDafaultStyle(){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;Appearance&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;System.Windows.Forms.TabAppearance.FlatButtons;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;ButtonColor&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color.FromArgb(</span><span style="color: #800080">184</span><span style="color: #000000">,</span><span style="color: #800080">210</span><span style="color: #000000">,</span><span style="color: #800080">250</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;ButtonHighlightColor&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Color.FromArgb(</span><span style="color: #800080">144</span><span style="color: #000000">,</span><span style="color: #800080">187</span><span style="color: #000000">,</span><span style="color: #800080">252</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">protected</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">override</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;OnPaint(PaintEventArgs&nbsp;&nbsp;&nbsp;e){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;e.Graphics.FillRectangle(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SolidBrush(BackColor),e.ClipRectangle);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #800080">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">this</span><span style="color: #000000">.TabCount;i</span><span style="color: #000000">++</span><span style="color: #000000">){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;DrawItem(e.Graphics,i);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">protected</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;DrawItem(Graphics&nbsp;&nbsp;&nbsp;g,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;index){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;Rectangle&nbsp;&nbsp;&nbsp;r&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;GetTabRect(index);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;r.Inflate(</span><span style="color: #000000">-</span><span style="color: #800080">2</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #800080">2</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;(SelectedIndex</span><span style="color: #000000">==</span><span style="color: #000000">index)&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;g.FillRectangle(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SolidBrush(ButtonHighlightColor),r);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;g.FillRectangle(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SolidBrush(ButtonColor),r);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;g.DrawRectangle(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;Pen(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SolidBrush(BorderColor)),r);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;r.Inflate(</span><span style="color: #000000">-</span><span style="color: #800080">3</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #800080">3</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;g.DrawString(TabPages[index].Text,Font,</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;SolidBrush(BorderColor),r);&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">protected</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">override</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;WndProc(</span><span style="color: #0000ff">ref</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;System.Windows.Forms.Message&nbsp;&nbsp;&nbsp;m){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;(m.Msg&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #800080">513</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">!</span><span style="color: #0000ff">this</span><span style="color: #000000">.UserChangeTab&nbsp;&nbsp;&nbsp;){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">trap&nbsp;&nbsp;&nbsp;WM_LBUTTONDOWN&nbsp;&nbsp;&nbsp;</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">{&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">base</span><span style="color: #000000">.WndProc(</span><span style="color: #0000ff">ref</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;m);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">protected</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">override</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;OnKeyDown(KeyEventArgs&nbsp;&nbsp;&nbsp;e){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(e.Control</span><span style="color: #000000">==</span><span style="color: #0000ff">true</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;e.KeyCode</span><span style="color: #000000">==</span><span style="color: #000000">System.Windows.Forms.Keys.Tab&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">!</span><span style="color: #0000ff">this</span><span style="color: #000000">.UserChangeTab){&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">trap&nbsp;&nbsp;&nbsp;CTRL+TAB&nbsp;&nbsp;&nbsp;and&nbsp;&nbsp;&nbsp;CTRL+SHIFT+TAB&nbsp;&nbsp;&nbsp;</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">{&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">base</span><span style="color: #000000">.OnKeyDown(e);&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
}</span></span></div>
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp; 以下是对上面的例子代码的一点说明： &nbsp; <br />
&nbsp; 1) &nbsp; public &nbsp; bool &nbsp; UserChangeTab成员的作用是规定是否允许用户在界面上通过鼠标点击标签和按"Ctrl+Tab"来改变当前标签页。 &nbsp; <br />
&nbsp; 2) &nbsp; 在构造函数中调用SetStyle()的目的是告诉系统这个控件将自行重画，而不是用系统默认的显示方式。 &nbsp; <br />
&nbsp; 3) &nbsp; OnPaint()完成的就是自行重画的工作，其中调用了DrawItem函数来重画所有的标签。 &nbsp; <br />
&nbsp; 4) &nbsp; SetDafaultStyle()的功能是设定一些默认的颜色和界面风格。 &nbsp; <br />
&nbsp; 5) &nbsp; 最重要的就是重载WndProc()和OnKeyDown()函数。在这两个重载函数中捕获了鼠标点击事件以及键盘输入事件。一旦this.UserChangeTab的值为false（即不允许用户来改变标签页），则将捕获的事件销毁，不再传递给基类的事件处理函数。 &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; 使用这个FTabControl时， &nbsp; <br />
&nbsp; 1) &nbsp; 如果需要禁止用户通过鼠标或者Ctrl+Tab改变标签页，需要设定UserChangeTab为false。 &nbsp; <br />
&nbsp; 2) &nbsp; 如果需要隐藏标签，需要将FTabControl的ItemSize属性设为(1,1)，并适当调整颜色设置以达到视觉上看不出的效果。 &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; 需要说明的是，通过上面这个例子，不但可以实现隐藏Tab标签、禁止用户改变标签等功能，通过扩充DrawItem函数还可以实现Tab标签的各种复杂视觉效果。&nbsp;&nbsp;
<img src ="http://www.cnblogs.com/smartstone/aggbug/1278101.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42132/" target="_blank">[新闻]Google 10周岁生日</a>]]></description></item><item><title>CListCtrl使用条款</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/26/1276475.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Tue, 26 Aug 2008 02:59:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/26/1276475.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1276475.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/26/1276475.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1276475.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1276475.html</trackback:ping><description><![CDATA[<p><font face="Verdana">ListCtrl在工作中，常常用到，也常常看到大家发帖问怎么用这个控件，故总结了一下自己的使用经验，以供参考使用。<br />
先注明一下，这里，我们用m_listctrl来表示一个CListCtrl的类对象，然后这里我们的ListCtrl都是Report形式，至于其他的如什么大图标，小图标的暂时不讲，毕竟Report是大众话的使用。其次，我们这里用条款一，条款二来描述第一点，第二点，这个是参照《Effective C++》的叫法，俺觉得这么叫比较COOL :)</font></p>
<p><font face="Verdana">条款一：设置ListCtrl的风格</font></p>
<p><font face="Verdana">在CSDN上常常看到有人问怎么设置风格的，他们ListCtrl的样子是一个列表，有横条和竖条分界线，然后选中一行，要整一行都选中，而不是只有某一列被选中，等等，这里给一个比较全面的设置方法。</font></p>
<p><font face="Verdana">//获得原有风格<br />
DWORD dwStyle = ::GetWindowLong(m_listctrl.m_hWnd, GWL_STYLE); <br />
dwStyle &amp;= ~(LVS_TYPEMASK);<br />
dwStyle &amp;= ~(LVS_EDITLABELS);<br />
//设置新风格<br />
SetWindowLong(m_listctrl.m_hWnd, GWL_STYLE, dwStyle,|LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);</font></p>
<p><font face="Verdana">//设置扩展风格<br />
DWORD styles = <br />
LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES;<br />
ListView_SetExtendedListViewStyleEx(m_listctrl.m_hWnd, styles, styles );</font></p>
<p><font face="Verdana">其中<br />
LVS_EX_FULLROWSELECT　就是前面说得整行选中<br />
LVS_EX_GRIDLINES　网格线（只适用与Report风格的ListCtrl）<br />
LVS_EX_CHECKBOXES　前面加个checkbox<br />
pListCtrl-&gt;SetExtendedStyle(m_listctrl.GetExtendedStyle()|LVS_EX_SUBITEMIMAGES);</font></p>
<p><font face="Verdana">这也是一个很重要的属性，这样的话，可以在列表中加ICON，记得windows的任务管理器吗，你想做得那样，这个属性也要加哦，这个我以后会讲的～</font></p>
<p><font face="Verdana">条款二：加入列头</font></p>
<p><font face="Verdana">这是一个比较实质的东西，给列表框分列，然后加上列头。代码说话，来了</font></p>
<p><font face="Verdana">TCHAR rgtsz[2][10] = {_T("列头1"), _T("列头2")};<br />
LV_COLUMN lvcolumn;<br />
CRect rect;<br />
m_listctrl.GetWindowRect(&amp;rect);<br />
for(int i=0;i&lt;2;i++)<br />
{<br />
&nbsp;lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;<br />
&nbsp;lvcolumn.fmt = LVCFMT_LEFT;<br />
&nbsp;lvcolumn.pszText = rgtsz[i];<br />
&nbsp;lvcolumn.iSubItem = i;<br />
&nbsp;lvcolumn.iOrder = i;<br />
&nbsp;if(i==0){<br />
&nbsp;&nbsp;lvcolumn.cx = rect.Width()*3/5 ; <br />
&nbsp;}else{<br />
&nbsp;&nbsp;lvcolumn.cx = rect.Width()*2/5;<br />
&nbsp;&nbsp;m_listctrl.InsertColumn(i, &amp;lvcolumn);<br />
&nbsp;}<br />
这是插入两列的做法，你要插入20列？随便你，依样画葫芦～～lvcolumn.mask 中那个mask可以有各种属性，具体去看msdn吧。</font></p>
<p><font face="Verdana">条款三：把记录插入列表框中</font></p>
<p><font face="Verdana">int nIndex = m_listctrl.GetItemCount();<br />
LV_ITEM&nbsp;&nbsp;&nbsp; lvitemAdd = {0};<br />
lvitemAdd.mask = LVIF_TEXT;<br />
lvitemAdd.iItem = nIndex ;<br />
lvitemAdd.iSubItem = 0;<br />
lvitemAdd.pszText =_T("毛毛1");;</font></p>
<p><font face="Verdana">if (m_listctrl.InsertItem(&amp;lvitemAdd) != -1){ <br />
&nbsp;LV_ITEM lvitem = {0};<br />
&nbsp;lvitem.mask = LVIF_TEXT;<br />
&nbsp;lvitem.iItem = nIndex ;<br />
&nbsp;lvitem.iSubItem = 1;<br />
&nbsp;lvitem.pszText =_T("毛毛2");<br />
&nbsp;m_listctrl.SetItem(&amp;lvitem);<br />
}<br />
nIndex 是当前的行数，然后把新的一行，插在最下面。</font></p>
<p><font face="Verdana">条款四：给列表中插入图标</font></p>
<p><font face="Verdana">在report格式中，也能插入图标。继续代码说话，m_image是个CImageList对象</font></p>
<p><font face="Verdana">m_image.Create(16,16, TRUE|ILC_COLOR24, 3, 1);<br />
m_listctrl.SetImageList(&amp;m_image,LVSIL_SMALL);</font></p>
<p><font face="Verdana">然后调用CImageList的成员函数int CImageList::Add( HICON hIcon );把ICON插入到imagelist，然后在插入记录的时候</font></p>
<p><font face="Verdana">lvitemAdd.mask = LVIF_TEXT;<br />
lvitemAdd.mask = LVIF_TEXT|LVIF_IMAGE</font></p>
<p><font face="Verdana">然后添加一个lvitemAdd.iImage = n;<br />
这个n是imagelist中的序号，表示是具体的哪一个图标，List么，呵呵。</font></p>
<p><font face="Verdana">条款五：　插入记录时使用额外的信息，lParam 的使用</font></p>
<p><font face="Verdana">有时候，你想对于某一行，加入一些额外的信息，那么就可以使用这个lParam，MSDN是这么描述的Specifies the 32-bit value of the item我上次是为了在某一行加入一个信息，窗口句柄，然后是这么加的：</font></p>
<p><font face="Verdana">int nIndex = m_listctrl.GetItemCount();<br />
LV_ITEM&nbsp;&nbsp;&nbsp; lvitemAdd = {0};<br />
lvitemAdd.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;<br />
lvitemAdd.iItem = nIndex ;<br />
lvitemAdd.iSubItem = 0;<br />
lvitemAdd.pszText =_T("毛毛1");;<br />
lvitemAdd.iImage = n;<br />
lvitemAdd.lParam = (LPARAM)hwnd;(某个窗口的窗口句柄)</font></p>
<p><font face="Verdana">if (m_listctrl.InsertItem(&amp;lvitemAdd) != -1){ <br />
&nbsp;LV_ITEM lvitem = {0};<br />
&nbsp;lvitem.mask = LVIF_TEXT;<br />
&nbsp;lvitem.iItem = nIndex ;<br />
&nbsp;lvitem.iSubItem = 1;<br />
&nbsp;lvitem.pszText =_T("毛毛2");<br />
&nbsp;m_listctrl.SetItem(&amp;lvitem);<br />
}<br />
这是一个比较全的例子的，又插ICON，又使用PARAM的。</font></p>
<p><font face="Verdana">条款六：点击列表框，获取选中行信息</font></p>
<p><font face="Verdana">响应NM_CLICK消息，如果你有MSDN，可以看到，有专门关于ListView的NM_CLICK的介绍<br />
void CMyDlg::OnItemClick(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
&nbsp;int nItem = -1;<br />
&nbsp;LPNMITEMACTIVATE lpNMItemActivate = (LPNMITEMACTIVATE)pNMHDR;<br />
&nbsp;if(lpNMItemActivate != NULL)<br />
&nbsp;{<br />
&nbsp;&nbsp;nItem = lpNMItemActivate-&gt;iItem;<br />
&nbsp;}<br />
} <br />
现在nItem就是点击选中那行的index了，有了index，获取那行的信息还难吗？懒汉说：难，因为你还没讲，晕，那就继续说。</font></p>
<p><font face="Verdana">条款七：　根据行的index，获取该行的信息</font></p>
<p><font face="Verdana">直接上代码吧：<br />
LV_ITEM lvitem = {0};<br />
lvitem.iItem = nIndex;<br />
lvitem.iSubItem = 0;<br />
lvitem.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;<br />
m_listctrl.GetItem(&amp;lvitem)</font></p>
<p><font face="Verdana">这样，就把nindex,第一列的信息取出来了，包括刚才我们加入的ICON,和那个额外信息（窗口句柄），比如我要获取窗口句柄，就可以hwnd = (HWND)lvitem.lParam; mask 用来指明你想获取那些信息，具体可以查msdn中LVITEM Structure的定义和CListCtrl::GetItem。</font></p>
<p><font face="Verdana">条款八：用程序选中某一行，使之选中</font></p>
<p><font face="Verdana">选中之　<br />
m_listctrl.SetItemState<br />
(nIndex,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);<br />
不选中，取消选中之<br />
m_listctrl.SetItemState(nIndex,0,LVIS_SELECTED|LVIS_FOCUSED);</font></p>
<p><font face="Verdana">条款九：获取当前所有选中的行（多选）</font></p>
<p><font face="Verdana">这个，俺就比较懒了，抄msdn的代码吧，反正很简单。<br />
　　<br />
Example<br />
// CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_YOURLISTCONTROL);<br />
ASSERT(pListCtrl != NULL);<br />
POSITION pos = pList-&gt;GetFirstSelectedItemPosition();<br />
if (pos == NULL)<br />
&nbsp;&nbsp;&nbsp; TRACE0("No items were selected!\n");<br />
else<br />
{<br />
&nbsp;&nbsp; while (pos)<br />
&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int nItem = pList-&gt;GetNextSelectedItem(pos);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRACE1("Item %d was selected!\n", nItem);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // you could do your own processing on nItem here<br />
&nbsp;&nbsp; }<br />
}</font></p>
<p><font face="Verdana">条款十：删除条款九中选中的行</font></p>
<p><font face="Verdana">这个相对前面九个条款是比较麻烦的，因为如果你要删除多行的话。往往要出错。比如，我现在要删除第0行和第1行（列表的行序列是从0开始的）那么好啊。我来删了：<br />
m_listctrl.DeleteItem(0)<br />
m_listctrl.DeleteItem(1)</font></p>
<p><font face="Verdana">恭喜你，错了，我好开心啊：）因为你删除第0行以后，下面的行会往上移，那么原来的第1行就变成了第0行，那么你再m_listctrl.DeleteItem(1)，那么删除的是原来的第2行，真麻烦，所以，只有从下往上删，才是安全的，先删的，不会影响后面的操作：<br />
m_listctrl.DeleteItem(1)<br />
m_listctrl.DeleteItem(0)<br />
但有时候，我们也不知道要删除哪些行，只知道要删除选中的那些行，像条款九中的那些。如果我们还是用<br />
　　　<br />
POSITION pos = m_listctrl.GetFirstSelectedItemPosition();<br />
if (pos == NULL)<br />
&nbsp;&nbsp;&nbsp; TRACE0("No items were selected!\n");<br />
else<br />
{<br />
&nbsp;&nbsp; while (pos)<br />
&nbsp;&nbsp; {<br />
&nbsp;int nItem = m_listctrl.GetNextSelectedItem(pos);<br />
&nbsp;m_listctrl.DeleteItem(nItem );<br />
&nbsp;&nbsp; }<br />
}<br />
你就等着犯错吧！这时候我们就要鄙视一下微软了，为虾米木有GetLastselectedItemPosition 和GetPrevSelectedItem<br />
多写一对成员函数会死啊:(没办法，办法自己想，这里有个笨办法<br />
POSITION sSelPos = NULL;<br />
while(sSelPos = m_listctrl.GetFirstSelectedItemPosition())<br />
{<br />
&nbsp;int nSelItem = -1;<br />
&nbsp;nSelItem = m_listctrl.GetNextSelectedItem(sSelPos);<br />
&nbsp;if(nSelItem &gt;= 0 &amp;&amp; nSelItem&lt;m_listctrl.GetItemCount())<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;//好了，这个nSelItem 就是我们要的DD<br />
&nbsp;}<br />
}<br />
GetNextSelectedItem这个函数，看msdn的用法，其实是返回第一个的index，然后走到下一个选中的行去，所以这么做也是安全的，在实际中，俺也是这么做的，测试也通过，没问题的当然，还有个办法，先通过GetFirstSelectedItemPosition和GetNextSelectedItem来获取所有的选中行的index，然后把这些index放到一个数组里，然后再从下往上删。唉！真麻烦啊，还要不定数组，不说用new在堆上开吧，那么一个vector总是要的吧，麻烦啊！所以我暂时是用上述的办法来删除，也供大家参考，希望能找到更好的办法。</font></p>
<img src ="http://www.cnblogs.com/smartstone/aggbug/1276475.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42131/" target="_blank">[新闻]祝Google 10周岁生日快乐</a>]]></description></item><item><title>SHBrowseForFolder Function</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/22/1274238.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Fri, 22 Aug 2008 08:44:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/22/1274238.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1274238.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/22/1274238.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1274238.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1274238.html</trackback:ping><description><![CDATA[<p>Displays a dialog box that enables the user to select a Shell folder.</p>
<p>Syntax</p>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_ctl01_">
<pre id="ctl00_rs1_mainContentContainer_ctl01" space="preserve">PIDLIST_ABSOLUTE&nbsp;SHBrowseForFolder(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;LPBROWSEINFO&nbsp;<em>lpbi</em><br />
);</pre>
</div>
</blockquote>
<p>Parameters</p>
<blockquote><dl><dt><em>lpbi</em></dt><dd> [in]&nbsp; A pointer to a <a id="ctl00_rs1_mainContentContainer_ctl02" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/bb773205%28VS.85%29.aspx">BROWSEINFO</a> structure. Conveys information used to display the dialog box.</dd></dl></blockquote>
<p>Return Value</p>
<blockquote> Returns a pointer to an item identifier list (PIDL) that specifies the location of the selected folder relative to the root of the namespace. If the user chooses the <strong>Cancel</strong> button in the dialog box, the return value is NULL.
<p>It is possible that the PIDL returned is that of a folder shortcut rather than a folder. For a full discussion of this case, see the Remarks section.</p>
<br />
</blockquote>
<p>Remarks</p>
<blockquote>
<p>You must initialize Component Object Model (COM) before you call <strong>SHBrowseForFolder</strong>. If you initialize COM using <a id="ctl00_rs1_mainContentContainer_ctl03" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/ms695279%28VS.85%29.aspx">CoInitializeEx</a>, you must set the COINIT_APARTMENTTHREADED flag in its <em>dwCoInit</em> parameter. You can also use <a id="ctl00_rs1_mainContentContainer_ctl04" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/ms678543%28VS.85%29.aspx">CoInitialize</a> or <a id="ctl00_rs1_mainContentContainer_ctl05" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl05',this);" href="http://msdn.microsoft.com/en-us/library/ms690134%28VS.85%29.aspx">OleInitialize</a>, which always use apartment threading. If you require drag-and-drop functionality, <strong>OleInitialize</strong> is recommended because it initializes the required OLE as well as COM.</p>
<div><strong> Note</strong>&nbsp;&nbsp;If COM is initialized using <strong>CoInitializeEx</strong> with the COINIT_MULTITHREADED flag, <strong>SHBrowseForFolder</strong> fails if the calling application uses the BIF_USENEWUI or BIF_NEWDIALOGSTYLE flag in the <strong>BROWSEINFO</strong> structure.</div>
<p>It is the responsibility of the calling application to call <a id="ctl00_rs1_mainContentContainer_ctl06" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/ms680722%28VS.85%29.aspx">CoTaskMemFree</a> to free the IDList returned by <strong>SHBrowseForFolder</strong> when it is no longer needed.</p>
<p>There are two styles of dialog box available. The older style is displayed by default and is not resizable. The newer style provides a number of additional features, including drag-and-drop capability within the dialog box, reordering, deletion, shortcut menus, the ability to create new folders, and other shortcut menu commands. Initially, it is larger than the older dialog box, but the user can resize it. To specify a dialog box using the newer style, set the <code xmlns:msxsl="urn:schemas-microsoft-com:xslt">BIF_USENEWUI</code> flag in the <strong>ulFlags</strong> member of the <strong>BROWSEINFO</strong> structure.</p>
<p>If you implement a callback function, specified in the <strong>lpfn</strong> member of the <strong>BROWSEINFO</strong> structure, you receive a handle to the dialog box. One use of this window handle is to modify the layout or contents of the dialog box. Because it is not resizable, modifying the older style dialog box is relatively straightforward. Modifying the newer style dialog box is much more difficult, and not recommended. Not only does it have a different size and layout than the old style, but its dimensions and the positions of its controls change every time it is resized by the user.</p>
<p>If the BIF_RETURNONLYFSDIRS flag is set in the <strong>ulFlags</strong> member of the <strong>BROWSEINFO</strong> structure, the <strong>OK</strong> button remains enabled for """server" items, as well as """server"share" and directory items. However, if the user selects a """server" item, passing the PIDL returned by <strong>SHBrowseForFolder</strong> to <a id="ctl00_rs1_mainContentContainer_ctl07" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl07',this);" href="http://msdn.microsoft.com/en-us/library/bb762194%28VS.85%29.aspx">SHGetPathFromIDList</a> fails.</p>
<p><strong>SHBrowseForFolder</strong> does not display libraries.</p>
<p>Custom Filtering</p>
<p>As of Microsoft Windows XP, <strong>SHBrowseForFolder</strong> supports custom filtering on the contents of the dialog box. To create a custom filter, follow these steps.  				</p>
<ol>
    <li>Set the BIF_NEWDIALOGSTYLE flag in the <strong>ulFlags</strong> member of the <strong>BROWSEINFO</strong> structure pointed to by the <em>lpbi</em> parameter.</li>
    <li>Specify a callback function in the <strong>lpfn</strong> member of that same <strong>BROWSEINFO</strong> structure.</li>
    <li>Code the callback function to receive the BFFM_INITIALIZED and BFFM_IUNKNOWN messages. On receipt of the BFFM_IUNKNOWN message, the callback function's <em>lParam</em> parameter contains a pointer to the dialog box's implementation of <a id="ctl00_rs1_mainContentContainer_ctl08" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl08',this);" href="http://msdn.microsoft.com/en-us/library/ms680509%28VS.85%29.aspx">IUnknown</a>. Call <a id="ctl00_rs1_mainContentContainer_ctl09" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl09',this);" href="http://msdn.microsoft.com/en-us/library/ms682521%28VS.85%29.aspx">QueryInterface</a> on that <strong>IUnknown</strong> to obtain a pointer to an instance of <a id="ctl00_rs1_mainContentContainer_ctl10" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl10',this);" href="http://msdn.microsoft.com/en-us/library/bb775620%28VS.85%29.aspx">IFolderFilterSite</a>.</li>
    <li>Create an object that implements <a id="ctl00_rs1_mainContentContainer_ctl11" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl11',this);" href="http://msdn.microsoft.com/en-us/library/bb775626%28VS.85%29.aspx">IFolderFilter</a>.</li>
    <li>Call <a id="ctl00_rs1_mainContentContainer_ctl12" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl12',this);" href="http://msdn.microsoft.com/en-us/library/bb775622%28VS.85%29.aspx">IFolderFilterSite::SetFilter</a>, passing to it a pointer to your <strong>IFolderFilter</strong>. <strong>IFolderFilter</strong> methods can then be used to include and exclude items from the tree.</li>
    <li>Once the filter is created, the <strong>IFolderFilterSite</strong> interface is no longer needed. Call <a id="ctl00_rs1_mainContentContainer_ctl13" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl13',this);" href="http://msdn.microsoft.com/en-us/library/ms682317%28VS.85%29.aspx">IFolderFilterSite::Release</a> if you have no further use for it.</li>
</ol>
<p>Dealing With Shortcuts</p>
<div><strong> Note</strong>&nbsp;&nbsp;This section applies to only Windows 2000 and earlier systems. By default, Windows XP and later systems return the PIDL of a shortcut's target rather than the shortcut itself, as long as the BIF_NOTRANSLATETARGETS flag is not set in the <strong>BROWSEINFO</strong> structure.</div>
<p>If <strong>SHBrowseForFolder</strong> returns a PIDL to a shortcut, sending that PIDL to <strong>SHGetPathFromIDList</strong> returns the path of the shortcut itself rather than the path of its target. The path to the shortcut's target can be obtained by using the <a id="ctl00_rs1_mainContentContainer_ctl14" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl14',this);" href="http://msdn.microsoft.com/en-us/library/bb774950%28VS.85%29.aspx">IShellLink</a> interface as shown in this example.</p>
<div id="ctl00_rs1_mainContentContainer_ctl15_">
<div>
<div><a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl15');"><img src="http://i.msdn.microsoft.com/platform/Controls/CodeSnippet/resources/copy_off.gif" align="center" border="0" height="9"  alt="" /> Copy Code</a></div>
</div>
<pre id="ctl00_rs1_mainContentContainer_ctl15" space="preserve">#include <br />
<br />
// Macros for interface casts<br />
#ifdef __cplusplus<br />
#define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast(static_cast(ppType))<br />
#else<br />
#define IID_PPV_ARG(IType, ppType) &amp;IID_##IType, (void**)(ppType)<br />
#endif<br />
<br />
// Retrieves the UIObject interface for the specified full PIDL<br />
STDAPI SHGetUIObjectFromFullPIDL(LPCITEMIDLIST pidl, HWND hwnd, REFIID riid, void **ppv)<br />
{<br />
LPCITEMIDLIST pidlChild;<br />
IShellFolder* psf;<br />
<br />
*ppv = NULL;<br />
<br />
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &amp;psf), &amp;pidlChild);<br />
if (SUCCEEDED(hr))<br />
{<br />
hr = psf-&gt;GetUIObjectOf(hwnd, 1, &amp;pidlChild, riid, NULL, ppv);<br />
psf-&gt;Release();<br />
}<br />
return hr;<br />
}<br />
<br />
#define ILSkip(pidl, cb)       ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))<br />
#define ILNext(pidl)           ILSkip(pidl, (pidl)-&gt;mkid.cb)<br />
<br />
HRESULT SHILClone(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidl)<br />
{<br />
DWORD cbTotal = 0;<br />
<br />
if (pidl)<br />
{<br />
LPCITEMIDLIST pidl_temp = pidl;<br />
cbTotal += sizeof (pidl_temp-&gt;mkid.cb);<br />
<br />
while (pidl_temp-&gt;mkid.cb) <br />
{<br />
cbTotal += pidl_temp-&gt;mkid.cb;<br />
pidl_temp += ILNext (pidl_temp);<br />
}<br />
}<br />
<br />
*ppidl = (LPITEMIDLIST)CoTaskMemAlloc(cbTotal);<br />
<br />
if (*ppidl)<br />
CopyMemory(*ppidl, pidl, cbTotal);<br />
<br />
return  *ppidl ? S_OK: E_OUTOFMEMORY;<br />
}<br />
<br />
// Get the target PIDL for a folder PIDL. This also deals with cases of a folder  <br />
// shortcut or an alias to a real folder.<br />
STDAPI SHGetTargetFolderIDList(LPCITEMIDLIST pidlFolder, LPITEMIDLIST *ppidl)<br />
{<br />
IShellLink *psl;<br />
<br />
*ppidl = NULL;<br />
<br />
HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFolder, NULL, IID_PPV_ARG(IShellLink, &amp;psl));<br />
<br />
if (SUCCEEDED(hr))<br />
{<br />
hr = psl-&gt;GetIDList(ppidl);<br />
psl-&gt;Release();<br />
}<br />
<br />
// It's not a folder shortcut so get the PIDL normally.<br />
if (FAILED(hr))<br />
hr = SHILClone(pidlFolder, ppidl);<br />
<br />
return hr;<br />
}<br />
<br />
// Get the target folder for a folder PIDL. This deals with cases where a folder<br />
// is an alias to a real folder, folder shortcuts, the My Documents folder, etc.<br />
STDAPI SHGetTargetFolderPath(LPCITEMIDLIST pidlFolder, LPWSTR pszPath, UINT cchPath)<br />
{<br />
LPITEMIDLIST pidlTarget;<br />
<br />
*pszPath = 0;<br />
<br />
HRESULT hr = SHGetTargetFolderIDList(pidlFolder, &amp;pidlTarget);<br />
<br />
if (SUCCEEDED(hr))<br />
{<br />
SHGetPathFromIDListW(pidlTarget, pszPath);   // Make sure it is a path<br />
CoTaskMemFree(pidlTarget);<br />
}<br />
<br />
return *pszPath ? S_OK : E_FAIL;<br />
}</pre>
</div>
<p><strong>Windows 95/98/Me</strong>: <strong>SHBrowseForFolder</strong> is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in <a id="ctl00_rs1_mainContentContainer_ctl16" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl16',this);" href="http://msdn.microsoft.com/en-us/library/ms812865%28VS.85%29.aspx">Microsoft Layer for Unicode on Windows Me/98/95 Systems</a>.</p>
</blockquote>
<p>Function&nbsp;Information</p>
<table>
    <tr>
        <th>Minimum DLL Version</th>
        <td>shell32.dll<a name="DLL_Versions"> version 4.0</a> or later</td>
    </tr>
    <tr>
        <th>Custom Implementation</th>
        <td>No</td>
    </tr>
    <tr>
        <th>Header</th>
        <td>shlobj.h</td>
    </tr>
    <tr>
        <th>Import library</th>
        <td>shell32.lib</td>
    </tr>
    <tr>
        <th>Minimum operating systems</th>
        <td> Windows NT&nbsp;4.0, Windows&nbsp;95</td>
    </tr>
    <tr>
        <th>Unicode</th>
        <td>Implemented as               ANSI and Unicode versions.</td>
    </tr>
</table><img src ="http://www.cnblogs.com/smartstone/aggbug/1274238.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42130/" target="_blank">[新闻]Google十年市值达1500亿美元 创造奇迹</a>]]></description></item><item><title>CTreeCtrl的右键菜单</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270581.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Mon, 18 Aug 2008 11:31:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270581.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1270581.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270581.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1270581.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1270581.html</trackback:ping><description><![CDATA[//获取到鼠标点中的位置<br />
<br />
POINT pt;<br />
<br />
GetCursorPos(&amp;pt);<br />
<br />
UINT uFlags;<br />
<br />
//将屏幕坐标转化为客户区坐标<br />
<br />
ScreenToClient(&amp;pt); <br />
<br />
MapWindowPoints(&amp;m_ctrlClassTree, &amp;pt,1);<br />
<br />
//获取鼠标点中位置的item<br />
<br />
HTREEITEM hItem = m_ctrlClassTree.HitTest(pt,&amp;uFlags);<br />
<br />
if ((hItem != NULL) &amp;&amp; (TVHT_ONITEM &amp; uFlags))<br />
<br />
{<br />
<br />
&nbsp;&nbsp; //选中点中的item<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_ctrlClassTree.Select(hItem, TVGN_CARET);<br />
<br />
}<br />
<br />
//必不可少，将客户区坐标转化为屏幕坐标<br />
<br />
ClientToScreen(&amp;pt);<br />
<br />
//弹出右键菜单<br />
<br />
m_menu.GetSubMenu(0)-&gt;TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,pt.x+15,pt.y+15,this);<br />
<br />
依据设备坐标的原点和用途，可以将Windows下使用的设备坐标系统分为三种：工作区坐标系统，窗口坐标系统和屏幕坐标系统。<br />
<br />
（1）工作区坐标系统：<br />
<br />
工作区坐标系统是最常见的坐标系统，它以窗口客户区左上角为原点(0,0)，主要用于窗口客户区绘图输出以及处理窗口的一些消息。鼠标消息WM_LBUTTONDOWN、WM_MOUSEMOVE传给框架的消息参数以及CDC一些用于绘图的成员都是使用工作区坐标。<br />
<br />
（2）屏幕坐标系统：<br />
<br />
屏幕坐标系统是另一类常用的坐标系统，以屏幕左上角为原点（0,0）。以CreateDC(&#8220;DISPLAY&#8221; , ...)或GetDC(NULL)取得设备上下文时，该上下文使用的坐标系就是屏幕坐标系。<br />
<br />
一些与窗口的工作区不相关的函数都是以屏幕坐标为单位，例如设置和取得光标位置的函数SetCursorPos()和GetCursorPos()；由于光标可以在任何一个窗口之间移动，它不属于任何一个单一的窗口，因此使用屏幕坐标。弹出式菜单使用的也是屏幕坐标。另外，CreateWindow、MoveWindow、SetWindowPlacement()等函数用于设置窗口相对于屏幕的位置，使用的也是屏幕坐标系统。<br />
<br />
（3）窗口坐标系统：<br />
<br />
窗口坐标系统以窗口左上角为坐标原点,它包含了窗口控制菜单、标题栏等内容。一般情况下很少在窗口标题栏上绘图，因此这种坐标系统很少使用。<br />
<br />
三类设备坐标系统关系如下图所示：<br />
<br />
T7_12.tif (166822 bytes)<br />
<br />
MFC提供ClientToScreen()、ScreenToClient()两个函数用于完成工作区坐标和屏幕坐标之间的转换工作。<br />
<br />
void ScreenToClient( LPPOINT lpPoint ) const;<br />
<br />
void ScreenToClient( LPRECT lpRect ) const;<br />
<br />
void ClientToScreen( LPPOINT lpPoint ) const;<br />
<br />
void ClientToScreen( LPRECT lpRect ) const;<br />
<br />
其实，我们在前面介绍弹出式菜单时已经使用了ClientToScreen函数。在那里，由于弹出式菜单使用的是屏幕坐标，因此当处理弹出式菜单快捷键shift+F10时，如果要在窗口左上角(5,5)处显示快捷菜单，就必须先调用ClientToScreen函数将客户区坐标（5,5）转化为屏幕坐标。<img src ="http://www.cnblogs.com/smartstone/aggbug/1270581.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42129/" target="_blank">[新闻]GMail:回过头来支持IE6</a>]]></description></item><item><title>用_splitpath  函数可以分解出路径，文件名，扩展名，msdn的例子</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270579.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Mon, 18 Aug 2008 11:23:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270579.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1270579.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/18/1270579.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1270579.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1270579.html</trackback:ping><description><![CDATA[<div>
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">#include &lt;stdlib.h&gt; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">#include &lt;stdio.h&gt; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">&nbsp;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">int</span> main(<span style="color: #0000ff;">void</span>) </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">{ </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">char</span> path_buffer[_MAX_PATH]; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">char</span> drive[_MAX_DRIVE]; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">char</span> dir[_MAX_DIR]; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">char</span> fname[_MAX_FNAME]; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">char</span> ext[_MAX_EXT]; </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    _makepath(path_buffer, <span style="color: #006080;">"c "</span>, <span style="color: #006080;">"""sample""crt"" "</span>, <span style="color: #006080;">"makepath "</span>, <span style="color: #006080;">"c "</span> ); <span style="color: #008000;">// C4996 </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #008000;">// Note: _makepath is deprecated; consider using _makepath_s instead </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    printf( <span style="color: #006080;">"Path created with _makepath: %s"n"n "</span>, path_buffer ); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    _splitpath( path_buffer, drive, dir, fname, ext ); <span style="color: #008000;">// C4996 </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #008000;">// Note: _splitpath is deprecated; consider using _splitpath_s instead </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    printf(<span style="color: #006080;">"Path extracted with _splitpath:"n "</span>); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    printf(<span style="color: #006080;">"Drive: %s"n"</span>, drive ); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    printf(<span style="color: #006080;">"Dir: %s"n"</span>, dir ); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    printf(<span style="color: #006080;">"Filename: %s"n"</span>, fname ); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    printf(<span style="color: #006080;">"Ext: %s"n"</span>, ext ); </pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">}</pre>
</div>
</div><img src ="http://www.cnblogs.com/smartstone/aggbug/1270579.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42129/" target="_blank">[新闻]GMail:回过头来支持IE6</a>]]></description></item><item><title>mfc中CImageList的使用简介 </title><link>http://www.cnblogs.com/smartstone/archive/2008/08/08/1263858.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Fri, 08 Aug 2008 08:22:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/08/1263858.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1263858.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/08/1263858.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1263858.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1263858.html</trackback:ping><description><![CDATA[<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">图像列表控制（<font face="Times New Roman">CImageList</font>）是相同大小图像的一个集合，每个集合中均以<font face="Times New Roman">0</font>为图像的索引序号基数，图像列表通常由大图标或位图构成，其中包含透明位图模式。可以利用<font face="Times New Roman">WINDOWS32</font>位应用程序接口函数<font face="Times New Roman">API</font>来绘制、建立和删除图像，并能实现增加、删除、替换和拖动图像等操作。图像列表控制提供了控制图像列表的基本方法，这些方法在<font face="Times New Roman">WINDOWS95</font>及以后版本才能实现。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">一、图像控制的对象结构</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">1 </font>图像控制的数据成员</p>
<p style="margin: 0cm 0cm 0pt 21pt; text-indent: 21pt"><font face="Times New Roman">m_hImageList </font>连接图像对象的控制句柄</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">2 </font>图像控制的建立方法</p>
<p style="margin: 0cm 0cm 0pt 21pt; text-indent: 21pt"><font face="Times New Roman">CimageList</font>＆<font face="Times New Roman">imageList</font>建立图像控制对象结构</p>
<p style="margin: 0cm 0cm 0pt 21pt; text-indent: 21pt"><font face="Times New Roman">Create </font>初始化图像列表并绑定对象</p>
<p style="margin: 0cm 0cm 0pt">图像控制的建立方法如下：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">BOOL Create( UINT nBitmapID, int cx, int nGrow, COLORREF crMask );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">BOOL Create( LPCTSTR lpszBitmapID, int cx, int nGrow, COLORREF crMask );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">BOOL Create( CImageList&amp; imagelist1, int nImage1, CImageList&amp; imagelist2,int nImage2,int dx, int dy );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其中各项参数的含义为：<font face="Times New Roman">cx</font>定义图像的宽度，单位为象素；<font face="Times New Roman">cy</font>定义图象的高度，单位为象素；<font face="Times New Roman">nFlags</font>确定建立图像列表的类型，可以是以下值的组合：<font face="Times New Roman"> ILC_COLOR</font>、<font face="Times New Roman">ILC_COLOR4</font>、<font face="Times New Roman">ILC_COLOR8</font>、<font face="Times New Roman">ILC_COLOR16</font>、<font face="Times New Roman">ILC_COLOR24</font>、<font face="Times New Roman">ILC_COLOR32</font>、<font face="Times New Roman"> ILC_COLORDDB</font>和<font face="Times New Roman">ILC_MASK</font>；<font face="Times New Roman">nInitial</font>用来确定图像列表包含的图像数量；<font face="Times New Roman">nGrow</font>用来确定图像列表可控制的图像数量。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">NbitmapID </font>用来确定图像列表联系的位图标志值；<font face="Times New Roman">crMask</font>表示颜色屏蔽位；</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">LpszBitmapID </font>用来确定包含位图资源的标识串；</p>
<p style="margin: 0cm 0cm 0pt 21pt"><font face="Times New Roman">imagelist1 </font>指向图像列表控制对象的一个指针；<font face="Times New Roman">nImage1</font>图像列表<font face="Times New Roman">1</font>中包含的图像数量；<font face="Times New Roman">imagelist2</font>指向图像列表控制对象的一个指针；<font face="Times New Roman">nImage2</font>图像列表<font face="Times New Roman">2</font>中包含的图像数量；<font face="Times New Roman">dx</font>表示以象素为单位的图像宽度；<font face="Times New Roman">dy</font>表示以象素为单位的图像高度。</p>
<p style="margin: 0cm 0cm 0pt">同样，图像控制的建立也包括两个步骤，首先建立图像列表结构，然后建立图像列表控制。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">3 </font>图像控制的属性类</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">图像控制的属性类包括返回<font face="Times New Roman">m_hImageList.</font>控制句柄<font face="Times New Roman">GetSafeHandle</font>、取得图像列表中的图像数量<font face="Times New Roman">GetImageCount</font>、设置图像列表的背景颜色<font face="Times New Roman">SetBkColor</font>、取得图像列表的背景颜色<font face="Times New Roman">SetBkColor</font>和取得图像的有关信息<font face="Times New Roman">SetBkColor</font>。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">4 </font>图像控制的操作方法</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">图像控制的操作方法包括将一个图像列表绑定到一个对象上<font face="Times New Roman">Attach</font>、将对象上的图像列表解除绑定并返回句柄<font face="Times New Roman">Detach</font>、删除一个图像列表<font face="Times New Roman">DeleteImageList</font>、将一个图像增加到图像列表中<font face="Times New Roman">Add</font>和将一个图像从图像列表中删除<font face="Times New Roman">Remove</font>等。</p>
<p style="margin: 0cm 0cm 0pt">二、图像控制的应用技巧</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">对于图像控制，同样不能单独使用，必须与列表控制、树控制和标签控制相互结合应用，下面分别介绍其具体应用技巧。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">1 </font>图像控制在列表控制中的应用技巧</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">1.1 </font>设置图像控制<font face="Times New Roman">CListCtrl::SetImageList</font>的调用格式如下：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList* SetImageList( CImageList* pImageList, int nImageList );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其返回值是指向前一个图像列表控制的一个指针，如果不存在前一个图像列表则为<font face="Times New Roman">NULL</font>；其中参数<font face="Times New Roman">pImageList</font>是指向图像列表的标识，<font face="Times New Roman">nImageList</font>是图像列表的类型，可以是如下值：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">LVSIL_NORMAL </font>用大图标方式进行图像列表；</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">LVSIL_SMALL </font>用小图标方式进行图像列表；</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">LVSIL_STATE </font>以图像状态进行图像列表；</p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman">1.2 </font>取得图像控制<font face="Times New Roman">CListCtrl::GetImageList</font>的调用格式如下：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList* GetImageList( int nImageList ) const;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其返回值为指向图像列表控制的指针，其中<font face="Times New Roman">nImageList</font>用来确定取得返回值的图像列表的值，其取值与设置图像列表函数相同。</p>
<p style="margin: 0cm 0cm 0pt">③图像控制在列表控制中的应用示例</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList Cil1,Cil2; //</font>定义大小图标像列表</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CVCLISTApp *pApp=(CVCLISTApp *)AfxGetApp();//</font>取得列表控制程序</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Create(32,32,TRUE,2,2);//</font>建立<font face="Times New Roman">32</font>位图像控制</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Add(pApp-&gt;LoadIcon(IDI_GJ));//</font>增加选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Add(pApp-&gt;LoadIcon(IDI_XS));//</font>增加非选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil2.Create(16,16,TRUE,2,2); //</font>建立<font face="Times New Roman">16</font>位图像控制</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil2.Add(pApp-&gt;LoadIcon(IDI_GJ));//</font>增加选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil2.Add(pApp-&gt;LoadIcon(IDI_XS));//</font>增加非选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">m_ListCtrl.SetImageList(&amp;Cil1,LVSIL_NORMAL);//</font>设置大图标控制</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">m_ListCtrl.SetImageList(&amp;Cil2,LVSIL_SMALL);//</font>设置小图标控制</p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman">2 </font>图像控制在树控制中的应用技巧</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">2.1 </font>设置图像控制<font face="Times New Roman">CTreeCtrl::SetImageList</font>的调用格式如下：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList* SetImageList( CImageList * pImageList, int nImageListType );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其返回值为指向前前一个图像列表的指针，否则为<font face="Times New Roman">NULL</font>；参数<font face="Times New Roman">pImageList</font>为指向图像列表的标识，如果<font face="Times New Roman">pImageList</font>为<font face="Times New Roman">NULL</font>则所有的图像都将从树控制中被清除；<font face="Times New Roman">nImageListType</font>为图像列表设置的类型，可以是如下值之一：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">TVSIL_NORMAL </font>设置正常图像列表，其中包括选中和非选中两种图标；</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">TVSIL_STATE </font>设置图像列表状态，指用户自定义状态；</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">2.2 </font>取得图像控制<font face="Times New Roman">CTreeCtrl::GetImageList</font>的调用格式如下：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList* GetImageList( UINT nImage );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">如果调用成功则返回图像列表控制指针，否则为<font face="Times New Roman">NULL</font>；<font face="Times New Roman">nImage</font>为取得返回值的图像列表类型，其取值和取得图像列表控制完全相同。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">2.3 </font>图像控制在树控制中的应用示例</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList Cil1,Cil2;//</font>定义大小图标像列表</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CVCTREEApp *pApp=(CVCTREEApp *)AfxGetApp();//</font>获取应用程序指针</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Create(16,16,ILC_COLOR,2,2);//</font>建立图像控制</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Add(pApp-&gt;LoadIcon(IDI_PM));//</font>增加选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">Cil1.Add(pApp-&gt;LoadIcon(IDI_CJ));//</font>增加非选中状态图像</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">m_TreeCtrl.SetImageList(&amp;Cil1,TVSIL_NORMAL);//</font>设置图像控制列表</p>
<p style="margin: 0cm 0cm 0pt">然后在树控制的结构定义中进行如下设置：</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">TCItem.item.iImage=0; //</font>设置未选中图像索引号</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">TCItem.item.iSelectedImage=1;//</font>设置选中时图像引号</p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman">3 </font>图像控制在控制中的应用技巧</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">1.</font>设置图像控制<font face="Times New Roman">CTabCtrl::SetImageList</font>的调用格式</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">CImageList * SetImageList( CImageList * pImageList );</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其返回值为指向前一个图像列表的指针，如果不存在前一个图像列表则为<font face="Times New Roman">NULL</font>；<font face="Times New Roman">pImageList</font>为标识<font face="Times New Roman">TAB</font>控制的图像列表指针。</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">2 </font>取得图像控制<font face="Times New Roman">CTabCtrl::GetImageList</font>的调用格式</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font face="Times New Roman">HIMAGELIST GetImageList() const;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 21pt">其返回值为指向<font face="Times New Roman">TAB</font>控制的图像列表指针，如果调用不成功则为<font face="Times New Roman">NULL</font>。</p>
<img src ="http://www.cnblogs.com/smartstone/aggbug/1263858.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42128/" target="_blank">[新闻]Google十年大变样</a>]]></description></item><item><title>安装Windows补丁批处理文件</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/06/1261917.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Wed, 06 Aug 2008 04:51:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/06/1261917.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1261917.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/06/1261917.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1261917.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1261917.html</trackback:ping><description><![CDATA[<div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">echo&nbsp;off<br />
del&nbsp;list.log&nbsp;/q<br />
echo&nbsp;正在检测已经的安装补丁<br />
pause&nbsp;<br />
for&nbsp;/f&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">delims=-&nbsp;tokens=2</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;%%i&nbsp;in&nbsp;('dir&nbsp;*-kb*.exe&nbsp;/b&nbsp;/on')&nbsp;do&nbsp;REG&nbsp;QUERY&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">HKLM\SOFTWARE\Microsoft\Windows&nbsp;NT\CurrentVersion\HotFix\%%i</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&gt;nul&nbsp;||&nbsp;dir&nbsp;/b&nbsp;*%%i*.exe&nbsp;&gt;&gt;list.log&nbsp;&amp;&amp;&nbsp;cls&nbsp;&amp;&amp;&nbsp;echo&nbsp;正在检测已经的安装补丁<br />
cls<br />
for&nbsp;/f&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">eol=o&nbsp;eol=O&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;%%j&nbsp;in&nbsp;(list.log)&nbsp;do&nbsp;echo&nbsp;正在安装补丁%%j&nbsp;&nbsp;&amp;&amp;&nbsp;%%j&nbsp;/quiet&nbsp;/norestart<br />
echo&nbsp;安装了的补丁（list.log）：&amp;&nbsp;type&nbsp;list.log&nbsp;|&nbsp;more<br />
pause<br />
del&nbsp;list1.log&nbsp;/q</span></div>
<p>&nbsp;</p>
<p>保存文件为Setup.bat，运行。</p>
<img src ="http://www.cnblogs.com/smartstone/aggbug/1261917.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42127/" target="_blank">[新闻]谷歌十年创新路</a>]]></description></item><item><title>MSDN October 2001 for Visual Studio 6.0（附测试说明）</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261235.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Tue, 05 Aug 2008 09:27:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261235.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1261235.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261235.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1261235.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1261235.html</trackback:ping><description><![CDATA[<p>MSDN Library 2001年October英文版的光盘镜像，是支持Visual Studio 6的最后一个MSDN版本，如果使用的是VS6以上的版本就不必下载了！</p>
<p><br />
</p>
<p><img alt="MSDN-Library6.jpg" src="http://img.verycd.com/posts/0511/post-142533-1130934860.jpg" name="post_img" /></p>
<p>DVD版本（1.5GB）：</p>
<p><span style="color: red; text-decoration: underline;">ed2k://|file|MSDN_Oct_2001.iso|1558814720|df9843995248f3f88a273f3458f5c4f3|/</span>&nbsp;</p>
<p>经测试，DVD版本的会有一些问题，比如不能使用Ctrl+C的快捷键、链接脚本错误等等。 <br />
</p>
<p>&nbsp;</p>
<p>3CD版本</p>
<p>eMule下载地址：<br />
</p>
<p>CD1（570.5MB）：<span style="text-decoration: underline;"><span style="color: #0000ff;"><span style="color: #0000ff; text-decoration: underline;">ed2k://|file|DNQ130ENU1.iso|598161408|3e4abe51782eba064b36de74e8b2cfd4|/</span></span></span> <br />
</p>
<p>CD2（573.5MB）：<span style="text-decoration: underline;"><span style="color: #0000ff;"><span style="color: #0000ff; text-decoration: underline;">ed2k://|file|DNQ130ENU2.iso|601362432|2729e046d0a11a7c9b8704f369411b86|/</span></span></span></p>
<p>CD3（612.6MB）：<span style="color: #0000ff; text-decoration: underline;">ed2k://|file|DNQ130ENU3.iso|642330624|d4ff9fa62b140a51737c840fac8290dc|/</span> </p>
<p>&nbsp;</p>
<p>经测试，3CD版本的也会出现链接脚本错误等问题。 <br />
</p>
<p>&nbsp;</p>
<p>FTP下载地址：</p>
<p><a href="ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_1.iso">ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_1.iso</a></p>
<p><a href="ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_2.iso">ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_2.iso</a></p>
<p><a href="ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_3.iso">ftp://202.112.84.90/pub2/Development/Microsoft%20Development/Visual%20Studio/MSDN2001_10/msdn200110_3.iso</a></p>
<p>&nbsp;</p>
<p>还有一个MSDN版本，并非October 2001 版本，供选择下载。</p>
<p>&nbsp;</p>
<p>2CD版本（VB部分的帮助已汉化）<br />
</p>
<p>MSDN Library DVD Part1： <br />
<a href="http://ftp.sdshiyan.cn/soft/program/DN60ACHS1.rar" target="_blank">http://ftp.sdshiyan.cn/soft/program/DN60ACHS1.rar</a><br />
MSDN Library DVD Part2： <br />
</p>
<p><a href="http://ftp.sdshiyan.cn/soft/program/DN60ACHS2.rar" target="_blank">http://ftp.sdshiyan.cn/soft/program/DN60ACHS2.rar</a></p>
<p><br />
</p>
<p>2CD版本可能不包含示例代码，示例代码又个单独的安装包，网络上没找到，不过个人有一个，需要的与我联系。</p>
<p><br />
</p>
<p>建议都使用迅雷下载，否则可能下载不了。<br />
</p>
<p><br />
</p>
<p> </p><img src ="http://www.cnblogs.com/smartstone/aggbug/1261235.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42126/" target="_blank">[新闻]十年回顾：Google的互联网经济</a>]]></description></item><item><title>如何用CreateNewFrame() 函数创建其他视图</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261136.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Tue, 05 Aug 2008 08:56:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261136.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1261136.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261136.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1261136.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1261136.html</trackback:ping><description><![CDATA[<p><span style="font-size: 8pt; font-family: 宋体"><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><span style="font-size: 14pt"><span style="font-family: 宋体"><strong></strong></span></span>CDocTemplate::CreateNewFrame() </span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数在使用</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">MFC</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">编写的多文档应用程序（</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">MDI</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">）中为文档（</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">Document</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">）创建其他视图（</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">Views</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">），</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CreateNewFrame() </span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数原型如下：</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"> </span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">CFrameWnd * CDocTemplate::CreateNewFrame(CDocument *, CFrameWnd *)</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">要调用该函数，需要指定一个</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CDocument</span></strong> <span style="font-size: 8pt; line-height: 150%; font-family: 宋体">对象指针（确定函数将要创建什么视图）和一个框架窗口指针（用于复制该窗口的属性），一般第二个参数为</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">NULL</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">。</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><br />
</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">当应用程序调用</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CreateNewFrame()</span></strong> <span style="font-size: 8pt; line-height: 150%; font-family: 宋体">，该函数创建一个新的框架窗口，并在该窗口中创建一个视图。</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">为了更好地理解如何使用</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CreateNewFrame()</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">，可以看看下面两个例子。</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><br />
</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">第一个例子是</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">MFC</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">源代码中的</span><em><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">WINMDI.CPP</span></em><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">文件。</span><em><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">WINMDI.CPP</span></em> <span style="font-size: 8pt; line-height: 150%; font-family: 宋体">定义了</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CMIDFrameWnd::OnWindowNew()</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数，该函数调用</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CreateNewFrame()</span></strong> <span style="font-size: 8pt; line-height: 150%; font-family: 宋体">用于为一个指定的文档添加其他的框架和视图。每次当用户选择</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">New</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">菜单时，应用程序调用</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">OnWindowNew()</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">。</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><br />
<strong>OnWindowNew()</strong> </span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数包含如下两行重要的代码：</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"> </span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">CFrameWnd * pFrame = pTemplate-&gt;CreateNewFrame(pDocument, pActiveChild);<br />
pTemplate-&gt;InitialUpdateFrame(pFrame, pDocument);</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">该代码创建并显示新框架窗口和文档视图。</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><br />
</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">另一个例子是</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">MFC</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">源代码中的</span><em><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">DOCMULTI.CPP</span></em><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">文件。</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CMultiDocTemplate::OpenDocumentFile()</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数包含下列代码：</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">CFrameWnd * pFrame = CreateNewFrame(pDocument, NULL);</span></p>
<p style="line-height: 150%" align="left"><strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">注意：</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">第二个参数是</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">NULL </span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">是因为</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">OpenDocumentFile() </span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数的设计假设程序员对复制包含该文档视图的其他框架不感兴趣。</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"><br />
<strong>CHKBOOK</strong> </span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">例子也示范了如何为文档创建附加框架和视图，在</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"> <em>CHKBOOK.CPP</em></span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">中，</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana"> <strong>CChkBookApp::OpenDocumentFile()</strong> </span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">函数包含下列代码：</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">CChkBookDoc * pDoc = (CChkBookDoc*)CWinApp::OpenDocumentFile(lpszFileName);<br />
if (pDoc == NULL)</span></p>
<p style="text-indent: 21pt; line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">return NULL;<br />
</span><span style="font-size: 8pt; color: #339966; line-height: 150%; font-family: 'Courier New'">//The line below is not required.</span><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'"><br />
CMDIChildWnd * pframe = ((CMDIFrameWnd *)AfxGetApp()-&gt;m_pMainWnd)-&gt;MDIGetActive();<br />
CFrameWnd * pNewFrame = m_pCheckViewTemplate-&gt;CreateNewFrame(pDoc, NULL);<br />
if (pNewFrame == NULL)</span></p>
<p style="text-indent: 21pt; line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">return pDoc;<br />
m_pCheckViewTemplate-&gt;InitialUpdateFrame(pNewFrame, pDoc);</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">当你使用</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CreateNewFrame()</span></strong><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">时有两点需要考虑：</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">一、</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">CDocTemplate::CreateNewFrame()</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">的源代码是在</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">DOCTEMPL.CPP</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">中，它包含下列代码：</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">if (!pFrame-&gt;LoadFrame(m_nIDResource,</span></p>
<p style="margin: 0cm 0cm 0pt 21pt; text-indent: 21pt; line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles</span></p>
<p style="margin: 0cm 0cm 0pt 21pt; text-indent: 21pt; line-height: 150%" align="left"><span style="font-size: 8pt; color: blue; line-height: 150%; font-family: 'Courier New'">NULL, &amp;context)</span></p>
<p style="line-height: 150%" align="left"><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">由于上述代码创建框架窗口时父窗口为</span><strong><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">NULL</span></strong> <span style="font-size: 8pt; line-height: 150%; font-family: 宋体">，</span><span style="font-size: 8pt; line-height: 150%; font-family: Verdana">MFC</span><span style="font-size: 8pt; line-height: 150%; font-family: 宋体">使用应用程序主窗口作为其父窗口。</span></p>
<p><span style="font-size: 8pt; font-family: 宋体">二、</span><strong><span style="font-size: 8pt; font-family: Verdana">CreateNewFrame()</span></strong> <span style="font-size: 8pt; font-family: 宋体">同时创建框架和视图，而不仅仅只创建视图。</span></p>
</span>
<img src ="http://www.cnblogs.com/smartstone/aggbug/1261136.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42126/" target="_blank">[新闻]十年回顾：Google的互联网经济</a>]]></description></item><item><title>CDocTemplate::CreateNewFrame</title><link>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261046.html</link><dc:creator>鄧</dc:creator><author>鄧</author><pubDate>Tue, 05 Aug 2008 07:52:00 GMT</pubDate><guid>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261046.html</guid><wfw:comment>http://www.cnblogs.com/smartstone/comments/1261046.html</wfw:comment><comments>http://www.cnblogs.com/smartstone/archive/2008/08/05/1261046.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/smartstone/comments/commentRss/1261046.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/smartstone/services/trackbacks/1261046.html</trackback:ping><description><![CDATA[<p><span style="font-size: 18pt"><span style="font-family: Arial"><span style="font-size: 18pt; font-family: ">CDocTemplate::CreateNewFrame</span> </span></span></p>
<p><strong>virtual CFrameWnd*</strong> <strong>CreateNewFrame(</strong> <strong>CDocument*</strong> <em>pDoc</em><strong>,</strong> <strong>CFrameWnd*</strong> <em>pOther</em> <strong>);</strong></p>
<p class="label"><strong>返回值</strong></p>
<p>一个指向新建框架窗口的指针，出现错误时为 <strong>NULL</strong>.</p>
<p class="label"><strong>参数</strong></p>
<p class="dt"><em>pDoc</em></p>
<p class="indent">新框架窗口应该引用的文档，可以是 <strong>NULL</strong>.</p>
<p class="dt"><em>pOther</em></p>
<p class="indent">新框架窗口的父框架窗口，可以是 <strong>NULL</strong>.</p>
<p class="label"><strong>备注</strong></p>
<p><strong>CreateNewFrame</strong> 使用 <strong>CRuntimeClass</strong> 对象传递给构造器以创建一个带有附加的视图和文档的新框架窗口。如果 <em>pDoc</em>&nbsp;参数是 <strong>NULL</strong>, 框架输出一个 TRACE 消息.</p>
<p><em>pOther</em> 参数用于实现窗口新命令。它提供一个框架窗口用于模型化新框架窗口。新框架窗口通常在后台创建。调用这个函数以在标准框架的新建文件和打开文件实现的外部创建框架窗口.</p>
<img src ="http://www.cnblogs.com/smartstone/aggbug/1261046.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42126/" target="_blank">[新闻]十年回顾：Google的互联网经济</a>]]></description></item></channel></rss>