这个就是我的主程序(问题在我今天发的第一个帖子中)
这个就是我的主程序(问题在我今天发的第一个帖子中) Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061117132223208.html
Hook.dll代码在我今天发的第一个帖子中
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure WMCOPYDATA(Var Msg:TMessage);message WM_COPYDATA;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function StartSpyMessage(AHSpyWnd, AHRevWnd: THandle): Boolean; stdcall;external 'hook.dll';
procedure StopSpyMessage;stdcall;external 'hook.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
MWnd:THandle;
CWnd:THandle;
EWnd:THandle;
begin
memo1.Lines.Clear;
MWnd:=FindWindow(nil,'BMML Window: COM1 Stack'); //获取窗口句柄
CWnd:=FindWindowEx(MWnd,0,'AfxMDIFrame40',nil); //获取一级句柄
EWnd:=FindWindowEx(CWnd,0,'Edit',nil); //获取Edit控件句柄
If EWnd=0 then
showmessage('程序没运行')
Else
memo1.Lines.Add(inttostr(EWnd));
if StartSpyMessage(EWnd,form1.Handle) then
showmessage('启动成功');
end;
procedure TForm1.WMCOPYDATA(var Msg: TMessage);
Var
Data:CopyDataStruct;
S:String;
begin
Data:=PCopyDataStruct(Msg.LParam)^;
with Data do
Begin
S:='数据类别代码'+inttostr(cbData)+' '+'消息实际数据'+PChar(lpData);
end;
Memo2.Lines.Add(s);
end;
end.
http://www.delphi2007.net/DelphiAPI/html/delphi_20061117132223208.html
Hook.dll代码在我今天发的第一个帖子中
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure WMCOPYDATA(Var Msg:TMessage);message WM_COPYDATA;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function StartSpyMessage(AHSpyWnd, AHRevWnd: THandle): Boolean; stdcall;external 'hook.dll';
procedure StopSpyMessage;stdcall;external 'hook.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
MWnd:THandle;
CWnd:THandle;
EWnd:THandle;
begin
memo1.Lines.Clear;
MWnd:=FindWindow(nil,'BMML Window: COM1 Stack'); //获取窗口句柄
CWnd:=FindWindowEx(MWnd,0,'AfxMDIFrame40',nil); //获取一级句柄
EWnd:=FindWindowEx(CWnd,0,'Edit',nil); //获取Edit控件句柄
If EWnd=0 then
showmessage('程序没运行')
Else
memo1.Lines.Add(inttostr(EWnd));
if StartSpyMessage(EWnd,form1.Handle) then
showmessage('启动成功');
end;
procedure TForm1.WMCOPYDATA(var Msg: TMessage);
Var
Data:CopyDataStruct;
S:String;
begin
Data:=PCopyDataStruct(Msg.LParam)^;
with Data do
Begin
S:='数据类别代码'+inttostr(cbData)+' '+'消息实际数据'+PChar(lpData);
end;
Memo2.Lines.Add(s);
end;
end.
该程序的确可以拦截那个程序中Edit控件的消息,但显示的却为空的
里面主要是用到WM_COPYDATA消息来传递我要的消息,因为对消息操作不熟悉,所以不知道在怎么写了
Hook.dll中拦截到消息以后,通过WM_COPYDATA消息发送到我的主程序
在主程序中我写了一个消息过程,也的确是收到效果,可就是得到的是空的,麻烦高手们帮我看看问题出在那里了