📄 subject_50865.htm
字号:
<p>
序号:50865 发表者:西风 发表日期:2003-08-27 11:35:14
<br>主题:在CListCtrl中排序时,如何在callback 函数中取得被比较的2行的文本或文本指针?
<br>内容:各位:请问在CListCtrl中排序时,如何在callback 函数中取得被比较的2行的文本或文本指针?(不能另外开缓冲区保存文本,因为CListCtrl已经帮你保存了一份,如果这样做无疑是浪费内存)
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:iamhere 回复日期:2003-08-27 11:46:11
<br>内容:给你看看MSDN上的例子,还是比较清楚的:<BR>Example<BR><BR>// Sort the item in reverse alphabetical order.<BR>static int CALLBACK <BR>MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)<BR>{<BR> // lParamSort contains a pointer to the list view control.<BR> // The lParam of an item is just its index.<BR> CListCtrl* pListCtrl = (CListCtrl*) lParamSort;<BR> CString strItem1 = pListCtrl->GetItemText(lParam1, 0);<BR> CString strItem2 = pListCtrl->GetItemText(lParam2, 0);<BR><BR> return strcmp(strItem2, strItem1);<BR>}<BR><BR>void snip_CListCtrl_SortItems()<BR>{<BR> // The pointer to my list view control.<BR> extern CListCtrl* pmyListCtrl;<BR><BR> // Sort the list view items using my callback procedure.<BR> pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);<BR>}<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:西风 回复日期:2003-08-27 14:07:26
<br>内容:谢谢iamhere,这个例子我看过,按代码的意思lParam1,lParam2是index of the item ,但实际上lParam1,lParam2是被比较的两行的Item Data,如果在排序前将Item data设为index of the item,排序的过程会导致index of the item变动,与Item data无法对应。你知道怎么做可以避免这个情况发生码?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:iamhere 回复日期:2003-08-27 14:35:33
<br>内容:我想你有一点弄错了,这个lParam1和lParam2并非index of the item ,而是the item data ,这个值是可以通过SetItemData来设定的(默认是0),因此在排序的过程中并不会变化!<BR>所以MSDN上的例子其实还应该要有隐含的条件:<BR>对每一个Item,假定其Index为nIndex,需要在排序之前调用:<BR>pmyListCtrl->SetItemData( nIndex , nIndex )<BR><BR>补充一点:也就是说只要要使你的Item data和Item Index建立其一定的联系就可以了<BR>2003-8-27 16:00:51
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -