⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teach_road_45.htm

📁 教程资料编程c语言编程教程资料编程c语言编程
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="闻怡洋 wyy_cq@21cn.com">
<title>Visual C++/MFC开发指南</title>
<SCRIPT LANGUAGE='JavaScript' SRC='../navigate_bar.js'></SCRIPT>
<link REL="stylesheet" HREF="../main.css">


</head>
<SCRIPT LANGUAGE='JavaScript'>write_body();</SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>write_bar();</SCRIPT>

<p align="center"><a
HREF="http://www.0828.com/pay/cgi-bin/random.cgi?job=go&id=820"
target="_blank">
<img SRC="http://www.0828.com/pay/cgi-bin/random.cgi?id=820" BORDER="0"
width="468" height="60"></a><br>
<font size="2"><a href="http://www.0828.com/pay/index.html"><img border="0"
src="http://www.0828.com/pay/code.gif" width="468" height="15"></a><br>
<small>你每点一下上面的广告我就能有更多的上网时间为大家寻找资料</small></font>
</p>

<table width=98% cellspacing="0" cellpadding="0" align=center><!--整体框架-->
<tr><td>

<table border=0 width="100%" cellspacing="0" cellpadding="2"><!--标记放置区域-->
<tr>
	<td width="30%" align="center" bgcolor="#003D84" valign=middle><img src=../img/brand_200_60.gif width=200 height=60 alt="LOGO1"></td>
	<td width="70%" align="center" bgcolor="#003D84" valign=middle><img src=../img/logo_400_60.gif width=400 height=60 alt="LOGO2"></td>
</tr>
<tr>
	<td colspan="2" bgcolor="#0080C0" align=center><font color=white>您当前位置</font> <a href=../index.htm><font color=white>首页</font></a> <a href=index.htm><font color=white>开发教程</font></a> <font class=eng color=white>4.5 List Box/Check List Box</font><SCRIPT LANGUAGE='JavaScript'>write_command();</SCRIPT></font></td>
</tr>
</table><!--标记放置区域 END-->

<table border=0 width=100% cellspacing="0" cellpadding="0">
<tr>
<td><!--begin-->

<br>
<p align=center><big><font class=eng>4.5 List Box/Check List Box</font></big></p>
<table border=0 align=center width=100%>
<tr><td>
<small>
<p>ListBox窗口用来列出一系列的文本,每条文本占一行。创建一个列表窗口可以使用成员函数:
<br>BOOL CListBox::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff );
<br>其中dwStyle将指明该窗口的风格,除了子窗口常用的风格WS_CHILD,WS_VISIBLE外,你可以针对列表控件指明专门的风格。
<ul>
<li>LBS_MULTIPLESEL 指明列表框可以同时选择多行</li>
<li>LBS_EXTENDEDSEL 可以通过按下Shift/Ctrl键选择多行</li>
<li>LBS_SORT 所有的行按照字母顺序进行排序</li>
</ul>
</p>
<p>在列表框生成后需要向其中加入或是删除行,可以利用:
<br>int AddString( LPCTSTR lpszItem )添加行,
<br>int DeleteString( UINT nIndex )删除指定行,
<br>int InsertString( int nIndex, LPCTSTR lpszItem )将行插入到指定位置。
<br>void ResetContent( )可以删除列表框中所有行。
<br>通过调用int GetCount( )得到当前列表框中行的数量。
</p>
<p>如果需要得到/设置当前被选中的行,可以调用int GetCurSel( )/int SetCurSel(int iIndex)。如果你指明了选择多行的风格,你就需要先调用int GetSelCount( )得到被选中的行的数量,然后int GetSelItems( int nMaxItems, LPINT rgIndex )得到所有选中的行,参数rgIndex为存放被选中行的数组。通过调用int GetLBText( int nIndex, LPTSTR lpszText )得到列表框内指定行的字符串。</p>
<p>此外通过调用int FindString( int nStartAfter, LPCTSTR lpszItem )可以在当前所有行中查找指定的字符传的位置,nStartAfter指明从那一行开始进行查找。
<br>int SelectString( int nStartAfter, LPCTSTR lpszItem )可以选中包含指定字符串的行。</p>
<p>在MFC 4.2版本中添加了CCheckListBox类,该类是由CListBox派生并拥有CListBox的所有功能,不同的是可以在每行前加上一个检查框。必须注意的是在创建时必须指明LBS_OWNERDRAWFIXED或LBS_OWNERDRAWVARIABLE风格。</p>
<p>通过void SetCheckStyle( UINT nStyle )/UINT GetCheckStyle( )可以设置/得到检查框的风格,关于检查框风格可以参考<a href=teach_road_41.htm>4.1 Button</a>中介绍。通过void SetCheck( int nIndex, int nCheck )/int GetCheck( int nIndex )可以设置和得到某行的检查状态,关于检查框状态可以参考<a href=teach_road_41.htm>4.1 Button</a>中介绍。</p>
<p>最后介绍一下列表框几种常用的消息映射宏:<ul>
<li>ON_LBN_DBLCLK  鼠标双击</li>
<li>ON_EN_ERRSPACE 输入框无法分配内存时产生</li>
<li>ON_EN_KILLFOCUS / ON_EN_SETFOCUS 在输入框失去/得到输入焦点时产生</li>
<li>ON_LBN_SELCHANGE 选择的行发生改变</li>
</ul>
使用以上几种消息映射的方法为定义原型如:afx_msg void memberFxn( );的函数,并且定义形式如ON_Notification( id, memberFxn )的消息映射。如果在对话框中使用列表框,Class Wizard会自动列出相关的消息,并能自动产生消息映射代码。
</p>
</small>
</td>
</tr>
<tr><td>
<small>
<p align=center><a href=index.htm#charpter4>返回</a></p>
</small>
</td></tr>
</table>
<p align=center><small>版权所有 闻怡洋 <a href=http://www.vchelp.net/>http://www.vchelp.net/</a></small></p>

</td><!--end-->
</tr>
</table>

</td></tr></table><!--整体框架 END-->


<!-- 耐特付费广告代码开始 不得修改. -->
<center><script language="javascript">
<!--
  var date = new Date();
  var ra = date.getTime() % 1000;
  var ua = document.URL;
  document.write("<iframe src='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' width=468 height=60 scrolling=no marginwidth=0 marginheight=0 frameborder=0 vspace=0 hspace=0 >");
  document.write("<a href='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' target='_blank'>");
  document.write("<img src='http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560' width=468 height=60 border=0></a>");
  document.write("</iframe>");
//-->
</script>
<noscript>
<a target="_blank" href="http://www.china-free.com/cgi-bin/ad/random.cgi?id=560">
<img src="http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560" width="468" height="60" border="0"></a>
</noscript>
<br><a HREF="http://www.china-free.com/ad" target="_blank"><img SRC="http://www.china-free.com/ad/bd.gif" BORDER="0"  ></a><br>
<small>你每点一下上面的广告我就能有更多的上网时间为大家寻找资料</small></center>
<!-- 耐特付费广告代码结尾. -->


<SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT>

</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -