我改了改你给出的代码,试试!
说明:
运行PDemo.exe后,你会发现Delphi IDE的菜单、窗体上的一些组件的Caption及
Explorer的主菜单的文字都已经变成了'AAA',这说明PDemo已经实现了对其它程
序的截获。
不过这样的示例其实用处不大,要实现真正的屏幕取词,要做的工作还很多,而
在Win9x下,这种方法其实并不可行,因为Win9x系统的核心是16位KERNEL、GDI、
USER,它们不是Win32的PE文件格式,因此会漏截很大一部分的文本输出。
另外,还需要解决间接调用和动态调用输出函数情况的截获问题。
DLL部分代码:
library MYAPIDLL;
uses
HookAPI in 'HookAPI.pas';
exports
InstallMsgHook,
UninstallMsgHook;
begin
end.
主程序代码:
program PDemo;
uses
Forms,
Demo in 'Demo.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Demo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Panel1: TPanel;
GroupBox1: TGroupBox;
Edit1: TEdit;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure InstallMsgHook; stdcall; external 'MYAPIDLL.dll';
procedure UninstallMsgHook; stdcall; external 'MYAPIDLL.dll';
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
InstallMsgHook;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UninstallMsgHook;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
end;
end.