CListCtrl::SortItems problem
-
I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain:
void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); }
int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }
-
I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain:
void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); }
int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }
-
I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain:
void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); }
int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }
Two problems. First, change
SortItems ( SortFunction, (LPARAM) m_cListCtrl )
to
SortItems ( SortFunction, (LPARAM) &m_cListCtrl ) // add ampersand
Second, you are thinking
lParam1
andlParam2
are the item indexes, but they are not, they are the lParam data associated with the two items being compared. They are always 0 because you probably don't use those data members. --Mike-- PROCRASTINATION: Hard work often pays off after time, but laziness always pays off now. BUY MY SOFTWARE!! (please?) RightClick-Encrypt - file encryption w/Explorer plugins | 1ClickPicGrabber - web page picture grabber for IE My IntarWeb Homepgae!!!11