將 TListView 的欄標標題列從預設立體 (Raised) 改為扁平 (Flat) 風格,視覺更現代化。
SendMessage(Handle, LVM_GETHEADER, 0, 0)。GetWindowLong(hHeader, GWL_STYLE)。HDS_BUTTONS (值 $0002) 樣式位:Style := Style xor $2。SetWindowLong + SetWindowPos。unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const LVM_GETHEADER = $1000 + 31;
var hHeader: THandle; Style: DWORD;
begin
hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);
Style := GetWindowLong(hHeader, GWL_STYLE);
Style := Style xor $2; // 切換 HDS_BUTTONS
SetWindowLong(hHeader, GWL_STYLE, Style);
SetWindowPos(ListView1.Handle, 0, 0, 0, 0, 0,
SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME);
end;
end.
uses 加入 CommCtrl (或 ComCtrls 已包含)。THeaderControl 等含 Header 的控件。