Re: CListCtrl sort not working




"Tom Serface" <tom.nospam@xxxxxxxxxxxxx> ha scritto nel messaggio
news:DC7E5B5D-BD6F-4AE2-B396-D70EC982C617@xxxxxxxxxxxxxxxx
This article should help you:

http://support.microsoft.com/kb/250614

The article pointed by Tom is of course a good start.

However, it has some problems, IMHO.

For example:

The comparing function SortFunc in the aforementioned article uses the
obsolete strcmp function to compare strings.
I don't like this way of comparing strings.

I believe that it fails in Unicode builds, where LPTSTR expands to wchar_t*.
The author of the article should have used _tcscmp for coherence with
Unicode builds.

Moreover, I don't like the fact that the author of the article uses raw
TCHAR* pointers for string. I believe that using a robust class for strings
like CString is a better choice.

I also don't like the fact that in the article a raw C-style vector of
pointers is used to store the custom data for each list item. I do prefer
using STL std::vector as a container, instead of a fixed-size raw C-style
array storing pointers.

Moreover, in the OnItemclickList1 handler associated to HDN_ITEMCLICK, the
author casts to NMLISTVIEW*, but I would instead prefer to cast to
NMHEADER*, as from MSDN documentation for HDN_ITEMCLICK:

HDN_ITEMCLICK Notification

http://msdn2.microsoft.com/en-us/library/bb775286(VS.85).aspx

// Author's code - IMHO, bad:
NMLISTVIEW *pLV = (NMLISTVIEW *) pNMHDR;

// Better code casting to NMHEADER*
LPNMHEADER phdr = reinterpret_cast< LPNMHEADER >( pNMHDR );

I wrote a demo app to show sorting of list controls, using the corrections I
pointed here.
I used Visual C++ 9 (VS2008).

The VC9 solution can be downloaded here, with source code:
http://www.geocities.com/giovanni.dicanio/vc/TestSortListCtrl.zip

Here's a screenshot:
http://www.geocities.com/giovanni.dicanio/vc/TestSortListCtrl.jpg

HTH,
Giovanni




.



Relevant Pages

  • Re: map.find doesnt find
    ... Basically the map.findmethod fails to find a match for a key that I ... The method is comparing pointers to determine if the objects are ... In my case the map key is of type const wchar_t* so this is ... Key type is a pointer so mapcompares those pointers, ...
    (microsoft.public.vc.stl)
  • Re: 74HC123 and long pulse
    ... Multiple memory banks, weak instruction ... existing C code because pointers don't work well with multiple memory ... You're comparing a PIC to a real CPU. ... Do you actually need to use C (with pointers, ...
    (sci.electronics.design)
  • Re: C vs. C++
    ... example, unlike C, C++ has a portable mechanism for comparing ... unrelated pointers. ... where to get memory. ...
    (comp.lang.c)
  • Re: dynamic_cast
    ... pointers rather than retrieving and comparing type_info objects. ... Pointers can normally be compared in a single operation, ... inheritance tree -- the typical expectation is that inheritance trees ... list of vtable pointers, you'd create a hash-table indexed by the value ...
    (comp.lang.cpp)
  • Re: casting &Byte[] to long value
    ... you are comparing two UInt32* pointers which should ... but I dislike the need of extra variables (due to ...
    (microsoft.public.dotnet.languages.vc)

Quantcast