?? vcc75.htm
字號(hào):
<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窗口用來(lái)列出一系列的文本,每條文本占一行。創(chuàng)建一個(gè)列表窗口可以使用成員函數(shù):
<br>
BOOL CListBox::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT&
rect, CWnd* pParentWnd, UINT nID = 0xffff ); <br>
其中dwStyle將指明該窗口的風(fēng)格,除了子窗口常用的風(fēng)格WS_CHILD,WS_VISIBLE外,你可以針對(duì)列表控件指明專門(mén)的風(fēng)格。
</span></small> </p>
<ul>
<li class="unnamed1"><small>LBS_MULTIPLESEL 指明列表框可以同時(shí)選擇多行</small>
<li class="unnamed1"><small>LBS_EXTENDEDSEL 可以通過(guò)按下Shift/Ctrl鍵選擇多行</small>
<li class="unnamed1"><small>LBS_SORT 所有的行按照字母順序進(jìn)行排序</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>
通過(guò)調(diào)用int GetCount( )得到當(dāng)前列表框中行的數(shù)量。 </small></p>
<p class="unnamed1"><small>如果需要得到/設(shè)置當(dāng)前被選中的行,可以調(diào)用int GetCurSel( )/int SetCurSel(int
iIndex)。如果你指明了選擇多行的風(fēng)格,你就需要先調(diào)用int GetSelCount( )得到被選中的行的數(shù)量,然后int GetSelItems(
int nMaxItems, LPINT rgIndex )得到所有選中的行,參數(shù)rgIndex為存放被選中行的數(shù)組。通過(guò)調(diào)用int GetLBText(
int nIndex, LPTSTR lpszText )得到列表框內(nèi)指定行的字符串。</small></p>
<p class="unnamed1"> 此外通過(guò)調(diào)用int FindString( int nStartAfter, LPCTSTR
lpszItem )可以在當(dāng)前所有行中查找指定的字符傳的位置,nStartAfter指明從那一行開(kāi)始進(jìn)行查找。 <br>
int SelectString( int nStartAfter, LPCTSTR lpszItem )可以選中包含指定字符串的行。</small></p>
<p class="unnamed1"><small>在MFC 4.2版本中添加了CCheckListBox類,該類是由CListBox派生并擁有CListBox的所有功能,不同的是可以在每行前加上一個(gè)檢查框。必須注意的是在創(chuàng)建時(shí)必須指明LBS_OWNERDRAWFIXED或LBS_OWNERDRAWVARIABLE風(fēng)格。</small></p>
<p class="unnamed1"><small>通過(guò)void SetCheckStyle( UINT nStyle )/UINT GetCheckStyle(
)可以設(shè)置/得到檢查框的風(fēng)格,關(guān)于檢查框風(fēng)格可以參考4.1 Button中介紹。通過(guò)void SetCheck( int nIndex,
int nCheck )/int GetCheck( int nIndex )可以設(shè)置和得到某行的檢查狀態(tài),關(guān)于檢查框狀態(tài)可以參考4.1
Button中介紹。</small></p>
<p class="unnamed1"> 最后介紹一下列表框幾種常用的消息映射宏:</small>
<ul>
<li class="unnamed1"><small>ON_LBN_DBLCLK 鼠標(biāo)雙擊</small>
<li class="unnamed1"><small>ON_EN_ERRSPACE 輸入框無(wú)法分配內(nèi)存時(shí)產(chǎn)生</small>
<li class="unnamed1"><small>ON_EN_KILLFOCUS / ON_EN_SETFOCUS 在輸入框失去/得到輸入焦點(diǎn)時(shí)產(chǎn)生</small>
<li class="unnamed1"><small>ON_LBN_SELCHANGE 選擇的行發(fā)生改變</small> </li>
</ul>
<small>使用以上幾種消息映射的方法為定義原型如:afx_msg void memberFxn(
);的函數(shù),并且定義形式如ON_Notification( id, memberFxn )的消息映射。如果在對(duì)話框中使用列表框,Class
Wizard會(huì)自動(dòng)列出相關(guān)的消息,并能自動(dòng)產(chǎn)生消息映射代碼。 </small> </span>
<p></p>
<div align="left"> </div>
</td>
</tr>
</tbody>
</table>
</div>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -