如何制作平面式列頭的Listview
新建一應(yīng)用程序,在窗體上放置一個ListView控件和一個按鈕控件,然后粘貼以下代碼,代碼中的有關(guān)API和常量參考Windows單元,方法是按是Ctrl鍵,然后單擊鼠標(biāo)左鍵
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);
  private
    { Private declarations }
  public
    { Public declarations }
  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;
  SetWindowLong(hHeader, GWL_STYLE, style);
  SetWindowPos(ListView1.Handle, Form1.Handle, 0, 0, 0, 0,SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME);
end;
 
end.
新聞熱點
疑難解答