Форум: "Начинающим";
Текущий архив: 2005.10.16;
Скачать: [xml.tar.bz2];
ВнизИмена колонок TListView. Delphi 7. Найти похожие ветки
← →
worldmen © (2005-09-07 17:22) [0]Можно ли в TListView, в наименовании колонок писать в две строки?
Если можно, то как?
← →
Турист (2005-09-09 00:14) [1]Вроде, работает
type
TMyListView = class(TListView)
private
FListViewHeaderHandle: HWnd;
FListViewHeaderInstance: Pointer;
FListViewHeaderWndProc: Pointer;
protected
procedure HeaderWndProc(var Message: TMessage);
procedure WMDrawItem(var Message: TWMDrawItem); message WM_DRAWITEM;
procedure WMParentNotify(var Message: TWMParentNotify); message WM_PARENTNOTIFY;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
end;
TListView = class(TMyListView);
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TMyListView.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
FListViewHeaderInstance := MakeObjectInstance(HeaderWndProc);
end;
destructor TMyListView.Destroy;
begin
if FListViewHeaderHandle <> 0 then
SetWindowLong(FListViewHeaderHandle, GWL_WNDPROC, LongInt(FListViewHeaderWndProc));
FreeObjectInstance(FListViewHeaderInstance);
inherited Destroy
end;
procedure TMyListView.WMParentNotify(var Message: TWMParentNotify);
begin
with Message do
if (Event = WM_CREATE) and (FListViewHeaderHandle = 0) then
begin
FListViewHeaderHandle := ChildWnd;
FListViewHeaderWndProc := Pointer(GetWindowLong(FListViewHeaderHandle, GWL_WNDPROC));
SetWindowLong(FListViewHeaderHandle, GWL_WNDPROC, LongInt(FListViewHeaderInstance));
end;
inherited;
end;
procedure TMyListView.WMDrawItem(var Message: TWMDrawItem);
begin
with Message.DrawItemStruct^ do begin
FillRect(hDC, rcItem, GetStockObject(BLACK_BRUSH));
DrawFrameControl(hDC, rcItem, DFC_BUTTON, DFCS_BUTTONPUSH);
DrawText(hDC, PChar(Columns[itemID].Caption), -1, rcItem, DT_CENTER)
end
end;
procedure TMyListView.HeaderWndProc(var Message: TMessage);
var
i: Integer;
HDItem: THDItem;
begin
try
with Message do begin
case Msg of
WM_NCDESTROY:
begin
Result := CallWindowProc(FListViewHeaderWndProc, FListViewHeaderHandle, Msg, WParam, LParam);
FListViewHeaderHandle := 0;
FListViewHeaderWndProc := nil;
Exit;
end;
end;
Result := CallWindowProc(FListViewHeaderWndProc, FListViewHeaderHandle, Msg, WParam, LParam);
if Msg = HDM_LAYOUT then begin
with PHDLayout(LParam)^ do begin
Rect.Top := Rect.Top + WindowPos.cy;
WindowPos.cy := WindowPos.cy + WindowPos.cy
end;
FillChar(HDItem, SizeOf(HDItem), 0);
HDItem.Mask := HDI_FORMAT;
HDItem.fmt := HDF_OWNERDRAW;
for i := 0 to Columns.Count - 1 do
SendMessage(FListViewHeaderHandle, HDM_SETITEM, i, LongInt(@HDItem))
end
end;
except
Application.HandleException(Self)
end
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
with ListView1 do
for i := 0 to Columns.Count - 1 do
Columns[i].Caption := Columns[i].Caption + #13#10 + Columns[i].Caption
end;
← →
worldmen © (2005-09-16 09:41) [2]Да, работает.
Только пири изменении размера колонки, имя колонки превращается в одну строку.
Страницы: 1 вся ветка
Форум: "Начинающим";
Текущий архив: 2005.10.16;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.066 c