P
phenix_sd
Unregistered / Unconfirmed
GUEST, unregistred user!
请看第五段
我想用WH_GETMESSAGE类型的钩子截获WM_GETTEXT消息,设好钩子后
我向form1发送了一个WM_GETTEXT消息,在edit1里显示出来,在钩子里
截获消息,将消息里的字符串显示在edit2中,但edit2显示不出来.....
unit Unit_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;//设钩子
Button2: TButton;//发消息
Edit1: TEdit;
Button4: TButton;//取消钩子,退出
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hhk:hHook;
function GetTextHookProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
implementation
{$R *.dfm}
function GetTextHookProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
var //str:array[0..255] of char;
buffer:TMSG;
begin
buffer:=PMSG(lParam)^;
if nCode<0 then result:=CallNextHookEx(hhk,nCode,wParam,lParam)
else if buffer.message=WM_GETTEXT then
begin
form1.Edit2.Text:=PChar(buffer.lParam)^;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hhk:=SetWindowsHookEx(WH_GETMESSAGE,GetTextHookProc,Hinstance,0);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
UnHookWindowsHookEx(hhk);
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
var str:array[0..255] of char;
begin
Sendmessage(form1.Handle,WM_GETTEXT,256,integer(@str));
edit1.Text:=str;
end;
end.
我想用WH_GETMESSAGE类型的钩子截获WM_GETTEXT消息,设好钩子后
我向form1发送了一个WM_GETTEXT消息,在edit1里显示出来,在钩子里
截获消息,将消息里的字符串显示在edit2中,但edit2显示不出来.....
unit Unit_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;//设钩子
Button2: TButton;//发消息
Edit1: TEdit;
Button4: TButton;//取消钩子,退出
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hhk:hHook;
function GetTextHookProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
implementation
{$R *.dfm}
function GetTextHookProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
var //str:array[0..255] of char;
buffer:TMSG;
begin
buffer:=PMSG(lParam)^;
if nCode<0 then result:=CallNextHookEx(hhk,nCode,wParam,lParam)
else if buffer.message=WM_GETTEXT then
begin
form1.Edit2.Text:=PChar(buffer.lParam)^;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hhk:=SetWindowsHookEx(WH_GETMESSAGE,GetTextHookProc,Hinstance,0);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
UnHookWindowsHookEx(hhk);
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
var str:array[0..255] of char;
begin
Sendmessage(form1.Handle,WM_GETTEXT,256,integer(@str));
edit1.Text:=str;
end;
end.