Sortowanie ListView_SortItems w WinApi

0

Potrzebuję sortować ListView ale nie mam pojęcia jak to zrobić aby w mojej funkcji do sortowania pojawiły mi się w Item1,Item2 wartości ???
Co jest nie tak lub czego mi brakuje???


uses
  Windows,Messages,commctrl,CommDlg ;

var
ListView1:Hwnd;
kolumna:LV_COLUMN;
wiersz :LV_ITEM;




function SortFunc(Item1,Item2,Column:Lparam):integer stdCall;
var
  www:pchar;
 S1,
 S2 : string;
begin
{  result:=1;}
end;




    WM_NOTIFY:
          begin
           if PNMLVCustomDraw(LParam)^.nmcd.hdr.code=LVN_COLUMNCLICK then
             begin
               ListView_SortItems(listview1,pfnlvcompare(@Sortfunc),(PNMListView(Lparam)^.iSubItem));
               exit;
             end;
	  end;

Zdaje sobie sprawę , że temat trudny ale może ...

Z góry podziękowania dla życzliwych.

0

Czy naprawdę nikt na tym się nie zna ???
Jestem wielce zasmucony.

To podajcie mi chociaż gdzie mógłbym na ten temat poczytać , znaleźć jakiekolwiek informacje.

0

use F1, dżordż

The comparison function has the following form:

int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort);

The lParam1 parameter is the 32-bit value associated with the first item being compared; and the lParam2 parameter is the value associated with the second item. These are the values that were specified in the lParam member of the items' LV_ITEM structure when they were inserted into the list. The lParamSort parameter is the same value passed to the LVM_SORTITEMS message.
The comparison function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent.

0

Wszystko jest fajnie opisy i te sprawy, ale jak to się ma do DELPHI??? Jak to zastosować??? Borland załącza kawał dokumentacji Microsoftu ale nic nie pisze jak to przekonwertować do DELPHI!!!
Może jakieś pomysły???

Ja nad tym problemem siedzę już trzy miesiące i stoję. Wszędzie piszą, że <url>4programmers.net</url> jest to największy portal o programowaniu więc myślę , że ktoś podejmie się tego aby rozwiązać ten problem i potraktuje to jako wyzwanie.

0

No i udało się dzięki koledze z netu , który mi pomógł.
Podziękowania dla Arkadiusza Pawlika
[email protected]

uses
  Windows,Messages,commctrl,CommDlg ;

var
ListView1:Hwnd;
kolumna:LV_COLUMN;
wiersz :LV_ITEM;
obracanie:boolean;
sortowanie: array[0..21] of boolean;


function StrPas(const Str: PChar): string;
begin
  Result := Str;
end;

procedure UpdatelParams;
var
i:longint;
begin
 for i :=0 to ListView_GetItemCount(ListView1)-1 do
   begin
     wiersz.mask:=LVIF_PARAM;
     wiersz.iItem:=i;
     wiersz.iSubItem:=0;
     wiersz.lParam:=wiersz.iItem;
     ListView_SetItem(ListView1,wiersz);
   end;
end;


function SortFunc(Item1,Item2,Column:{longint}lparam):integer stdCall;
var
 K1,
 K2 : array[0..255] of char;
 S1,S2:string;
 I1,
 I2,i3 :integer;
begin
  if obracanie then
     begin
       result:=1;
       exit;
     end;
   ListView_GetItemText(listview1,integer(Item1),Column,@K1[0],SizeOf(K1));
   ListView_GetItemText(listview1,integer(Item2),Column,@K2[0],SizeOf(K2));
   S1:=StrPas(K1);
   S2:=StrPas(K2);

   case Column of
      0 :
        begin
        end;
1,7,9,10,11,12,14   :
        begin
          i1:=pos(',',s1);
          if i1=0 then s1:=s1+',0000';
          i1:=pos(',',s1);
          i3:=4-(length(s1)-i1);
          for i2:=1 to i3 do s1:=s1+'0';
          S1 := StringOfChar('0', 15) + S1;
          i1:=pos(',',s2);
          if i1=0 then s2:=s2+',0000';
          i1:=pos(',',s2);
          i3:=4-(length(s2)-i1);
          for i2:=1 to i3 do s2:=s2+'0';
          S2 := StringOfChar('0', 15) + S2;
          S1 := Copy(S1, Length(S1) - 15, 16);
          S2 := Copy(S2, Length(S2) - 15, 16);
        end;
2,3,4,5,6,8,13,15,16,17,18,19       :
        begin

        end;
     end;

  if Column >= 0 then
    begin
      if S1 = S2 then Result := 0;
      if S1 < S2 then Result := -1;
      if S1 > S2 then Result := 1;
    end;
end;




    WM_NOTIFY:
          begin
           if PNMLVCustomDraw(LParam)^.nmcd.hdr.code=LVN_COLUMNCLICK then
             begin
//jesli raz juz posortowalismy do drugi raz tylko obracamy liste
               if not sortowanie[PNMListView(Lparam)^.iSubItem] then
                 begin
                   for i:=0 to 21 do sortowanie[i]:=false; //ilosc kolumn
                   sortowanie[PNMListView(Lparam)^.iSubItem]:=true;
                   obracanie:=false;
                 end
                  else
                   obracanie:=true;

               UpdatelParams; //zaladowanie do LParam aktualnych wartosci
               ListView_SortItems(listview1,pfnlvcompare(@Sortfunc),(PNMListView(Lparam)^.iSubItem));
               UpdatelParams; //zaladowanie do LParam aktualnych wartosci

               exit;
             end;
          end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1