1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| procedure TForm1.Button1Click(Sender: TObject);
const
LVM_GETHEADER = LVM_FIRST + 31;
var
LF: TLogFont;
hHeader, hCurrFont, hOldFont, hHeaderFont: THandle;
begin
{to get the windows handle for header}
hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);
{to get the handle for header font}
hCurrFont := SendMessage(hHeader, WM_GETFONT, 0, 0);
{to get the LOGFONT with font details}
if GetObject(hCurrFont, SizeOf(LF), Addr(LF)) > 0 then
begin
{set our custom attributes. I set a bold and underlined font style}
LF.lfWeight := FW_BOLD;
LF.lfUnderline := 1;
{create a new font for the header control to use.
This font must NOT be deleted until it is no
longer required by the control, typically when
the application will be closed or when a new font
will be applied to header}
hHeaderFont := CreateFontIndirect(LF);
{to select the new font}
hOldFont := SelectObject(hHeader, hHeaderFont);
{to notify the listview header about changes}
SendMessage(hHeader, WM_SETFONT, hHeaderFont, 1);
end;
end; |
Partager