Автор: Maks150988
Дата сообщения: 12.06.2008 12:14
Есть код вида:
Код: program sample;
uses
Windows, Messages, CommCtrl;
{$R dialog.res}
const
RC_DIALOG = 101;
RC_ICON = 101;
ID_LISTBOX = 101;
var
hApp : Integer;
ListWnd : THandle;
ListIco : hIcon;
ListDC : hDC;
RectLB : TRect;
TextLB : array [0..$400] of Char;
function AppFuncProc(hWnd : HWND; uMsg : UINT; wParam, lParam : Integer) : BOOL; stdcall;
var
I : Integer;
begin
Result := TRUE;
case uMsg of
WM_MEASUREITEM :
case wParam of
ID_LISTBOX :
begin
with PMEASUREITEMSTRUCT(lParam)^ do
begin
itemHeight := 18;
end;
end;
end;
WM_DRAWITEM :
case wParam of
ID_LISTBOX :
begin
ListWnd := PDRAWITEMSTRUCT(lParam).hwndItem;
RectLB := PDRAWITEMSTRUCT(lParam).rcItem;
ListDC := PDRAWITEMSTRUCT(lParam).hDC;
if (Integer(PDRAWITEMSTRUCT(lParam).ItemID) > - 1) then
begin
ListIco := LoadImage(hInstance, MAKEINTRESOURCE(RC_ICON), IMAGE_ICON, 16, 16, 0);
if ((PDRAWITEMSTRUCT(lParam).itemState and ODS_SELECTED) <> 0) then
begin
FillRect(ListDC, RectLB, GetSysColorBrush(COLOR_HIGHLIGHT));
SetBkColor(ListDC, GetSysColor(COLOR_HIGHLIGHT));
SetTextColor(ListDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
end
else
begin
FillRect(ListDC, RectLB, GetSysColorBrush(COLOR_WINDOW));
SetBkColor(ListDC, GetSysColor(COLOR_WINDOW));
SetTextColor(ListDC, GetSysColor(COLOR_WINDOWTEXT));
end;
DrawIconEx(ListDC, RectLB.Left + 2, RectLB.Top + 1, ListIco, 16, 16, 0, 0, DI_NORMAL);
RectLB.Left := RectLB.Left + 22;
SendMessage(ListWnd, LB_GETTEXT, PDRAWITEMSTRUCT(lParam).ItemID, LongInt(@TextLB[0]));
DrawText(ListDC, @TextLB[0], - 1, RectLB, DT_SINGLELINE or DT_VCENTER);
DeleteObject(ListIco);
end;
if ((PDRAWITEMSTRUCT(lParam).itemState and ODS_FOCUS) <> 0) then DrawFocusRect(ListDC, PDRAWITEMSTRUCT(lParam).rcItem);
end;
end;
WM_INITDIALOG :
begin
hApp := hWnd;
for I := 0 to 7 do SendMessage(GetDlgItem(hApp, ID_LISTBOX), LB_ADDSTRING, 0, Integer(PChar('ListBox String Ownerdraw !!!')));
end;
WM_DESTROY, WM_CLOSE : PostQuitMessage(0);
else
Result := FALSE;
end;
end;
begin
InitCommonControls;
DialogBox(hInstance, MAKEINTRESOURCE(RC_DIALOG), 0, @AppFuncProc);
end.