别让MSDN忽悠了你

虽说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.

Collapse imageReturn 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.

Collapse imageRemarks

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.

Collapse imageExample

 CopyCode imageCopy 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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值