如何拦截系统的wm_paint消息,听说要通过WH_CALLWNDPROC的hook实现,
主要是想得到桌面刷新或重画的消息。
请写出必要的代码,先谢了!

解决方案 »

  1.   

    OldWndProc: function(h: hwnd; m: tmsg; w: wparam; l: lparam): integer; stdcall;function NewWndProc(h: hwnd; m: tmsg; w: wparam; l: lparam): integer; stdcall;varhdc: Integer;beginResult := OldWndProc(h,m,w,l);if h=WM_PAINT thenbeginhdc := GetDC(h);Rectangle(hdc,100,100,300,300);ReleaseDC(h,hdc);end;end;procedure TForm1.FormCreate(Sender: TObject);varhwnd: Integer;retv: Integer;beginhwnd := GetDeskTopWindow;OldWndProc := Pointer(GetWindowLong(hwnd,GWL_WNDPROC));retv := SetWindowLong(hwnd,GWL_WNDPROC,Integer(@NewWndProc));end; //retv 老是为零procedure TForm1.FormDestroy(Sender: TObject);varhwnd: Integer;retv: Integer;beginhwnd := GetDeskTopWindow;retv := SetWindowLong(hwnd,GWL_WNDPROC,Integer(@OldWndProc));end; 
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure MyMessage(var Msg: TMsg; var Handled: Boolean) ;
      public
        { Public declarations }
      end;var
      Form1: TForm1 ;
      i : Integer ;implementation{$R *.dfm}procedure TForm1.MyMessage(var Msg : TMsg ;var Handled : Boolean) ;
    begin
      Inc(i) ;
      if Msg.message = WM_Paint then
        if (i mod 2) = 0  then
          Caption := 'WM_Paint'
        Else
          Caption := 'Paint_WM' ;
    end ;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := MyMessage ;
    end;end.
      

  3.   

    private
        procedure WMpaint(var Msg:TMessage);message WM_paint;
        { Private declarations }
      public
        { Public declarations }
      end;
    procedure TfrmMain.WMSyscommand(var Msg:Tmessage);
    begin
      inherited;
      if msg.wParam=要的拦消息   then 做什么事.. 
    end;
      

  4.   

    贴错:
    private
        procedure WMpaint(var Msg:TMessage);message WM_paint;
        { Private declarations }
      public
        { Public declarations }
      end;
    procedure TfrmMain.WMpaint(var Msg:Tmessage);
    begin
      inherited;
      if msg.wParam=要的拦消息   then 做什么事.. 
    end;
      

  5.   

    好像都不能拦截到系统的WM_PAINT消息