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. 
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3