program Project1;
uses
Windows, Messages, CommCtrl, SysUtils;
var
WndClassEx : TWndClassEx;
Form, LV : hwnd;
MMsg: Msg;
item : tLVITEM;
LVSize: Integer;
isSorted: Boolean;
Const
LVID = 13;
function LV_GetItemText(hList : HWND; Index, SubItem : Integer) : String;
var
Buf : array [0..MAX_PATH] of Char;
begin
ZeroMemory(@Buf, SizeOf(Buf));
ListView_GetItemText(hList, Index, SubItem, Buf, SizeOf(Buf));
if Buf[0] <> #0 then
Result := Buf;
end;
function CompareFunc(lParam1, lParam2, SortType : Longint) : Integer; stdcall;
var
lvi : LV_ITEM;
Size1,
Size2 : Integer;
Column : Word;
St1, St2 : String;
begin
Column := LOWORD(SortType);
lvi.mask := LVIF_TEXT;
if Column = 0 then
begin
Result := AnsiCompareText(LV_GetItemText(LV, lParam1, 0), LV_GetItemText(LV, lParam2, 0));
end
else if Column = LVSize + 1 then
{begin
try
Size1 := StrToInt(Copy(LV_GetItemText(LV, lParam1, Column), 1, Pos(' ', LV_GetItemText(LV, lParam1, Column)) - 1));
Size2 := StrToInt(Copy(LV_GetItemText(LV, lParam2, Column), 1, Pos(' ', LV_GetItemText(LV, lParam2, Column)) - 1));
Result := Size1 - Size2;
except
Result := 0;
end;
end
else }
begin
St1 := LV_GetItemText(LV, lParam1, Column);
St2 := LV_GetItemText(LV, lParam2, Column);
Result := AnsiCompareText(St1, St2);
if (St1 = '') or (St2 = '') then
Result := 0;
end; // SetWindowText(Form, IntToStr(LVSize)); }
if isSorted then
Result := Result
else
Result := -Result;
end;
Function WinProc(Forma: hwnd; Msg: UINT; wparam: WParam; LParam: LPARAM): lresult; Stdcall;
Var
lvc : TLVColumn;
I, zz, B : Integer;
rect : TRect;
Begin
Result := 0;
Case Msg Of
WM_GETMINMAXINFO:
begin
PMinMaxInfo(LParam)^.ptMinTrackSize := Point(300, 300);
end;
WM_CREATE:
begin
GetClientRect(Forma, Rect);
LV :=CreateWindowEx(WS_EX_CLIENTEDGE,'SysListView32', '1', WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHOWSELALWAYS or LVS_SINGLESEL
, 0, 35, Rect.Right ,Rect.Bottom - 105,Forma, LVID, HInstance, nil);
SendMessage(lv, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT or LVS_EX_GRIDLINES or LVS_EX_INFOTIP);
lvc.fmt := LVCFMT_CENTER;
lvc.mask := LVCF_TEXT or LVCF_WIDTH;
lvc.pszText := '0';
lvc.cx := 250;
lvc.iSubItem := 0;
ListView_InsertColumn(lv, 0, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '1';
lvc.cx := 60;
lvc.iSubItem := 1;
ListView_InsertColumn(LV, 1, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '2';
lvc.cx := 50;
lvc.iSubItem := 2;
ListView_InsertColumn(LV, 2, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '3';
lvc.cx := 100;
lvc.iSubItem := 3;
ListView_InsertColumn(LV, 3, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '4';
lvc.cx := 100;
lvc.iSubItem := 4;
ListView_InsertColumn(LV, 4, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '5';
lvc.cx := 100;
lvc.iSubItem := 5;
ListView_InsertColumn(LV, 5, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.pszText := '6';
lvc.cx := 100;
lvc.iSubItem := 6;
ListView_InsertColumn(LV, 6, lvc);
lvc.mask := lvc.mask or LVCF_FMT or LVCF_SUBITEM;
lvc.fmt := LVCFMT_LEFT;
lvc.pszText := '7';
lvc.cx := LVSCW_AUTOSIZE_USEHEADER;//250;
lvc.iSubItem := 7;
ListView_InsertColumn(LV, 7, lvc);
end;
WM_SIZE:
Begin
GetClientRect(Form, Rect);
SetWindowPos(LV, 0, 0, 35, Rect.Right, Rect.Bottom - 82, SWP_NOZORDER);
SendMessage(LV, LVM_SETCOLUMNWIDTH, 7, LVSCW_AUTOSIZE_USEHEADER);
End;
WM_NOTIFY:
begin
if PNMHDR(lParam).hwndFrom = LV then
case {PNMHDR}PNMLISTVIEW(lParam)^.hdr.code of
LVN_COLUMNCLICK:
begin
if (LVSize = PNMLISTVIEW(lParam).iSubItem) then
isSorted := not isSorted
else
isSorted := False;
LVSize := PNMLISTVIEW(lParam).iSubItem;
ListView_SortItems(LV, @CompareFunc, PNMLISTVIEW(lParam).iSubItem);
end;
end;
end;
WM_SHOWWINDOW:
begin
for zz := 0 to 10 do
begin
FillChar(item, sizeof(item), 0 );
item.mask := LVIF_TEXT;
item.iItem := ListView_GetItemCount(lv);
item.pszText := PChar(inttostr(zz));
ListView_InsertItem(LV, Item);
for b := 1 to 7 do
begin
item.iSubItem := b;
item.pszText := PChar(inttostr(random(100)));
ListView_SetItem(LV, item);
end;
end;
end;
WM_DESTROY:
begin
PostQuitMessage(0);
end;
Else
Result := DefWindowProc(Forma, Msg, WParam, LParam);
End;
End;
Procedure WinMain;
Begin
FillChar(WndClassEx, SizeOf(TWndClassEx), 0);
WndClassEx.cbSize := SizeOf(TWndClassEx);
WndClassEx.lpszClassName := 'APIWindow';
WndClassEx.style := CS_HREDRAW Or CS_VREDRAW;
WndClassEx.hInstance := HInstance;
WndClassEx.lpfnWndProc := @WinProc;
WndClassEx.cbClsExtra := 0;
WndClassEx.cbWndExtra := 0;
WndClassEx.hIcon := LoadIcon(HInstance, MakeIntResource('MAINICON'));
WndClassEx.hIconSm := LoadIcon(HInstance, MakeIntResource('MAINICON'));
WndClassEx.hCursor := LoadCursor(0, IDC_ARROW);
WndClassEx.hbrBackground := COLOR_BTNFACE + 1;
WndClassEx.lpszMenuName := NIL;
If RegisterClassEx(WndClassEx) = 0 Then
MessageBox(0, 'Невозможно зарегистрировать класс окна1', 'Ошибка', MB_OK Or MB_ICONHAND)
Else
Begin
Form := CreateWindowEx(0, WndClassEx.lpszClassName, '123', WS_OVERLAPPEDWINDOW, 500,100, 420, 400, 0, 0, HInstance, NIL);
If Form = 0 Then
MessageBox (0, 'Окно1 не создалось!', 'Ошибка', MB_OK Or MB_ICONHAND)
Else
Begin
ShowWindow (Form, SW_SHOWNORMAL);
While GetMessage(MMsg, 0, 0, 0) Do
Begin
TranslateMessage(MMsg);
DispatchMessage(MMsg);
End;
Halt(MMsg.WParam);
End;
End;
End;
begin
WinMain;
end.