📄 vcc75.htm
字号:
<html>
<head>
<title>c++系列</title>
<meta content="text/html; charset=gb2312" http-equiv=Content-Type>
</head>
<p align="center"><script src="../../1.js"></script></a>
<body bgcolor="#ffffff" leftmargin="5" topmargin="1" marginheight="5" marginwidth="5">
<div align=center>
<table border=0 cellpadding=0 cellspacing=0 width=680 align="center">
<tbody>
<tr>
<td width=200 height="59">
</tr>
</tbody>
</table>
<table border=1 bordercolordark=#ffffff bordercolorlight=#ffffff cellpadding=0
cellspacing=0 width=685 align="center" height="70">
<tbody>
<tr>
<td bgcolor=#F9D23C height=14>
<div align=center class=H1><font color="#FFFFFF">List BoxCheck List Box</font></div>
</td>
</tr>
<tr valign=top>
<td class=H1 height=51>
<p align="left"> <span class="unnamed1">ListBox窗口用来列出一系列的文本,每条文本占一行。创建一个列表窗口可以使用成员函数:
<br>
BOOL CListBox::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT&
rect, CWnd* pParentWnd, UINT nID = 0xffff ); <br>
其中dwStyle将指明该窗口的风格,除了子窗口常用的风格WS_CHILD,WS_VISIBLE外,你可以针对列表控件指明专门的风格。
</span></small> </p>
<ul>
<li class="unnamed1"><small>LBS_MULTIPLESEL 指明列表框可以同时选择多行</small>
<li class="unnamed1"><small>LBS_EXTENDEDSEL 可以通过按下Shift/Ctrl键选择多行</small>
<li class="unnamed1"><small>LBS_SORT 所有的行按照字母顺序进行排序</small> </li>
</ul>
<p></p>
<p class="unnamed1"><small>在列表框生成后需要向其中加入或是删除行,可以利用: <br>
int AddString( LPCTSTR lpszItem )添加行, <br>
int DeleteString( UINT nIndex )删除指定行, <br>
int InsertString( int nIndex, LPCTSTR lpszItem )将行插入到指定位置。 <br>
void ResetContent( )可以删除列表框中所有行。 <br>
通过调用int GetCount( )得到当前列表框中行的数量。 </small></p>
<p class="unnamed1"><small>如果需要得到/设置当前被选中的行,可以调用int GetCurSel( )/int SetCurSel(int
iIndex)。如果你指明了选择多行的风格,你就需要先调用int GetSelCount( )得到被选中的行的数量,然后int GetSelItems(
int nMaxItems, LPINT rgIndex )得到所有选中的行,参数rgIndex为存放被选中行的数组。通过调用int GetLBText(
int nIndex, LPTSTR lpszText )得到列表框内指定行的字符串。</small></p>
<p class="unnamed1"> 此外通过调用int FindString( int nStartAfter, LPCTSTR
lpszItem )可以在当前所有行中查找指定的字符传的位置,nStartAfter指明从那一行开始进行查找。 <br>
int SelectString( int nStartAfter, LPCTSTR lpszItem )可以选中包含指定字符串的行。</small></p>
<p class="unnamed1"><small>在MFC 4.2版本中添加了CCheckListBox类,该类是由CListBox派生并拥有CListBox的所有功能,不同的是可以在每行前加上一个检查框。必须注意的是在创建时必须指明LBS_OWNERDRAWFIXED或LBS_OWNERDRAWVARIABLE风格。</small></p>
<p class="unnamed1"><small>通过void SetCheckStyle( UINT nStyle )/UINT GetCheckStyle(
)可以设置/得到检查框的风格,关于检查框风格可以参考4.1 Button中介绍。通过void SetCheck( int nIndex,
int nCheck )/int GetCheck( int nIndex )可以设置和得到某行的检查状态,关于检查框状态可以参考4.1
Button中介绍。</small></p>
<p class="unnamed1"> 最后介绍一下列表框几种常用的消息映射宏:</small>
<ul>
<li class="unnamed1"><small>ON_LBN_DBLCLK 鼠标双击</small>
<li class="unnamed1"><small>ON_EN_ERRSPACE 输入框无法分配内存时产生</small>
<li class="unnamed1"><small>ON_EN_KILLFOCUS / ON_EN_SETFOCUS 在输入框失去/得到输入焦点时产生</small>
<li class="unnamed1"><small>ON_LBN_SELCHANGE 选择的行发生改变</small> </li>
</ul>
<small>使用以上几种消息映射的方法为定义原型如:afx_msg void memberFxn(
);的函数,并且定义形式如ON_Notification( id, memberFxn )的消息映射。如果在对话框中使用列表框,Class
Wizard会自动列出相关的消息,并能自动产生消息映射代码。 </small> </span>
<p></p>
<div align="left"> </div>
</td>
</tr>
</tbody>
</table>
</div>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -