虽说MSDN代码是微软的高手写的,很正确很权威.不过它有时候也有很龌龊的一面,为了不影响到广大的青少年和小朋友们,下面举例说明: MSDN为VS2005版,查询函数CListBox::DeleteString的说明如下
Deletes the item in position nIndex from the list box.
int DeleteString(
UINT nIndex
); |
Parameters
-
nIndex
-
Specifies the zero-based index of the string to be deleted.
Return Value
A count of the strings remaining in the list. The return value is LB_ERR if nIndex specifies an index greater than the number of items in the list.
Remarks
All items following nIndex now move down one position. For example, if a list box contains two items, deleting the first item will cause the remaining item to now be in the first position. nIndex=0 for the item in the first position.
Example
Copy Code | |
---|---|
// The pointer to my list box. extern CListBox* pmyListBox; // Delete every other item from the list box. for (int i=0;i < pmyListBox->GetCount()/*每次大小都减一*/;i++) { pmyListBox->DeleteString( i ); |
正确的做法应该是
for (int i(pmyListBox->GetCount()-1);i >=0;--i) { pmyListBox->DeleteString( i ); }
以上只是为了说明DeleteString的用法,如果想达到上述目的,
可以while(LB_ERR!=pComBox->DeleteString(0));
或者更直接pComBox->ResetContent();