delphi教程

Delphi中ListView列宽改变时的消息响应

位置:首页 > delphi教程 > 高级教程,2015-10-15
Delphi中ListView列宽改变时的消息响应unit Unit1;  interface  uses  Windows, Messages, SysUti
Delphi中ListView列宽改变时的消息响应


unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls, ComCtrls,CommCtrl; 
 
type 
 PHD_NOTIFY=^HD_NOTIFY; 
 TForm1 = class(TForm) 
  ListView1: TListView; 
  Button1: TButton; 
  procedure FormDestroy(Sender: TObject); 
  procedure Button1Click(Sender: TObject); 
 private 
  { Private declarations } 
  oldProc: TWndMethod; 
  procedure NewProc(var Message: TMessage); 
 public 
  { Public declarations } 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
procedure TForm1.NewProc(var Message: TMessage); 
var hn:PHD_NOTIFY; 
begin 
 if message.Msg=WM_NOTIFY then 
 begin 
  hn:=PHD_NOTIFY(Message.LParam); 
  if(hn^.Hdr.code=HDN_BEGINTRACKA)or(hn^.hdr.code=HDN_BEGINTRACKW) then 
  begin 
   // Message.Result  :=  1;   加入这一行就使的列头不能改变宽度 
   //  如果要在拖动完成后作处理,可以判断hn->hdr.code是否 
   //  等于HDN_ENDTRACKA或HDN_ENDTRACKW,然后作处理。 
   ShowMessage('hehe'); 
  end 
  else 
   ListView1.Dispatch(Message); 
 end;  
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
 ListView1.WindowProc:=OldProc; 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
 OldProc:= ListView1.WindowProc; 
 ListView1.WindowProc:= NewProc; 
end; 
 
end.

TAGS:Delphi ListView

猜你喜欢

NewHot