Sorting in list control
-
Hi, I created a shell extension that shows a dialog(MFC). The dialog have a list control and i tried to implement the sort functionality in it. The problem is when I call the ListView_SortItems or ListView_SortItemsEx of the list control, after the first call back returned from my application an exception is coming. Any solution for this? Thanks Naveen
-
Maybe posting relevant code will help. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
CPallini wrote:
Maybe posting relevant code will help.
thanks. void MainDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult) { ListView_SortItemsEx( m_list.m_hWnd, CompareFunc, (LPARAM)this ); *pResult = 0; } int MainDlg::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { return 1; }
nave
-
CPallini wrote:
Maybe posting relevant code will help.
thanks. void MainDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult) { ListView_SortItemsEx( m_list.m_hWnd, CompareFunc, (LPARAM)this ); *pResult = 0; } int MainDlg::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { return 1; }
nave
IMHO there are two strange things in your code (but I don't know how dangerous they are): - Why are you passing
this
pointer to the comparisono function (though it is perfectly legal) ? - Your comparison function it's wrong: it cannot order a set. I know it it a test function, but try to improve it. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
IMHO there are two strange things in your code (but I don't know how dangerous they are): - Why are you passing
this
pointer to the comparisono function (though it is perfectly legal) ? - Your comparison function it's wrong: it cannot order a set. I know it it a test function, but try to improve it. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
CPallini wrote:
Why are you passing this pointer to the comparisono function (though it is perfectly legal) ?
I removed the this pointer. Still the exception is ocurring( Actaully this code will work fine in simple mfc application. I have even tried this in an ocx )
CPallini wrote:
Your comparison function it's wrong: it cannot order a set. I know it it a test function, but try to improve it.
I know the current code will not do sorting. Just for making the code shorter i have removed the comparision codes.
nave
-
CPallini wrote:
Why are you passing this pointer to the comparisono function (though it is perfectly legal) ?
I removed the this pointer. Still the exception is ocurring( Actaully this code will work fine in simple mfc application. I have even tried this in an ocx )
CPallini wrote:
Your comparison function it's wrong: it cannot order a set. I know it it a test function, but try to improve it.
I know the current code will not do sorting. Just for making the code shorter i have removed the comparision codes.
nave
Naveen R wrote:
removed the this pointer. Still the exception is ocurring( Actaully this code will work fine in simple mfc application. I have even tried this in an ocx )
I expected the above behaviour. I was curious about...
Naveen R wrote:
I know the current code will not do sorting. Just for making the code shorter i have removed the comparision codes.
Maybe the bug it is in the not-posted code! :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Naveen R wrote:
removed the this pointer. Still the exception is ocurring( Actaully this code will work fine in simple mfc application. I have even tried this in an ocx )
I expected the above behaviour. I was curious about...
Naveen R wrote:
I know the current code will not do sorting. Just for making the code shorter i have removed the comparision codes.
Maybe the bug it is in the not-posted code! :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
no no Even the code that I posted causes exception. Simply returning the 1 itself is causing the exception.
nave
-
Hi, I created a shell extension that shows a dialog(MFC). The dialog have a list control and i tried to implement the sort functionality in it. The problem is when I call the ListView_SortItems or ListView_SortItemsEx of the list control, after the first call back returned from my application an exception is coming. Any solution for this? Thanks Naveen
Didn't get time to look into your code. Will do soon. :)
Nibu thomas A Developer Programming tips[^] My site[^]
-
IMHO this may happen 'cause you function isn't good for ordering. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Didn't get time to look into your code. Will do soon. :)
Nibu thomas A Developer Programming tips[^] My site[^]
-
Hi Nibu, pblm solved. The pblm was I didnt put the "CALLBACK" in the function declaration. Thats all. Thanks anyway.
nave
Naveen R wrote:
The pblm was I didnt put the "CALLBACK" in the function declaration.
Hmm Nice fix.
Nibu thomas A Developer Programming tips[^] My site[^]
-
I got the pblm solved. I missed the "CALLBACK" in the function declaration. Thanks anyway
nave