Q&A

  • 자신의 프로그램 후킹 (강좌 따라하기)
팁/테크에 있는 강민주님의 '자신의 프로그램 후킹' 강좌를 보고 따라해 봤습니다.

(http://www.delphi.co.kr/zboard/view.php?id=tips&page=1&sn1=&divpage=1&sn=off&ss=on&sc=off&keyword=후킹&select_arrange=headnum&desc=asc&no=346)

그런데 마우스 버튼 눌러도 아무런 반응이 없네요.

소스 보시고 도움 부탁드립니다.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    function AppHookFunc(var Message: TMessage) : Boolean;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.AppHookFunc(var Message : TMessage) : Boolean;
begin
Result := False;
if Message.Msg = WM_LBUTTONDOWN then begin
  ShowMessage('aa');
  Result := True;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.HookMainWindow(AppHookFunc);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.UnHookMainWindow(AppHookFunc);
end;

end.
1  COMMENTS
  • Profile
    도끼로이마까 2005.04.19 21:05

    말 그대로 Application 객체의 윈도우를 후킹하는것이지..폼을 후킹하는것이 아닙니다.
    폼의 특정 메시지를 가로채고 싶으시면,,,

    <!--CodeS-->
        TForm1 = class(TForm)
        private
        ...
        procedure WMLButtonDown(var msg: TWMLButtonDown); message WM_LBUTTONDOWN;
        ...
        end;
    <!--CodeE-->

    위와 같이 type절 Form 클래스에 선언하시고 구현부에서 아래와 같이 구현하시면됩니다.
    <!--CodeS-->
    procedure TForm1.WMLButtonDown(var msg: TWMLButtonDown);
    begin
      //custom action
      inherited;
    end;
    <!--CodeE-->