Z
zhoupj
Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
我已做了BUOONT1的程序,button2的怎么做呢,不懂了,请高手帮忙啊,程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Timer1: TTimer;
Edit3: TEdit;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure CreateParams(Var Params:TCreateParams);
procedure Wndpro(Var Message:TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.CreateParams(var Params: TCreateParams);
var
str:string;
begin
inherited CreateParams(Params);
str:=Form1.Caption;
Params.Caption:=Pchar(str);
end;
procedure TForm1.Wndpro(var Message: TMessage);
var
processhnd:Thandle;
numrc:dword;
begin
processhnd:=Openprocess(PROCESS_VM_READ,False,Message.WParam);
Readprocessmemory(processhnd,ptr(Message.LParam),@(unit2.ssaa),Sizeof(unit2.ssaa),numrc);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
edit1.text:=inttostr(unit2.ssaa.single);
edit2.text:=inttostr(unit2.ssaa.a);
edit3.text:=inttostr(unit2.ssaa.b);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
unit2.test.create;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//怎么写呢,这里不会了
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls;
type
test = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
public
Constructor Create;
end;
const
my_definemsg=WM_user+1001;
type
Ta=Packed record
single:Longword;
a:integer;
b:integer;
end;
var
ssaa:Ta;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure test.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ test }
constructor test.Create;
begin
inherited Create(Suspended);
FreeOnTerminate:=True;
end;
procedure test.Execute;
var
i,j:integer;
wnd:Hwnd;
begin
{ Place thread code here }
for i:=0 to 10000000 do
begin
ssaa.a:=i;
for j:=0 to 1000000do
begin
ssaa.b:=j;
//生成监控信息
wnd:=FindWindow(nil,'Form1');
if wnd<>0 then
begin
ssaa.single:= GetCurrentProcessID;
SendMessage(wnd ,my_definemsg,GetCurrentProcessID,Lparam(@ssaa));
end;
//生成监控信息 结束
end;
end;
end;
end.