procedure TForm1.FormCreate(Sender: TObject);
var
Ghwnd:hwnd;
begin
Ghwnd:=FindWindow('ZClient Window','祈祷');
GetWindowThreadProcessID(Ghwnd,@dwProcId); //获得进程ID
mytest:=testr.Create(false); //创建mytest线程end;
mytest:=testr.Create(false); //创建mytest线程
创建线程代码失效了一样,没创建线程,原因不知道呀
而
procedure TForm1.Button1Click(Sender: TObject);
begin
mytest:=testr.Create(false);
end;把创建线程的代码放到Button中却没问题。。原因何在?请赐教。谢谢。
var
Ghwnd:hwnd;
begin
Ghwnd:=FindWindow('ZClient Window','祈祷');
GetWindowThreadProcessID(Ghwnd,@dwProcId); //获得进程ID
mytest:=testr.Create(false); //创建mytest线程end;
mytest:=testr.Create(false); //创建mytest线程
创建线程代码失效了一样,没创建线程,原因不知道呀
而
procedure TForm1.Button1Click(Sender: TObject);
begin
mytest:=testr.Create(false);
end;把创建线程的代码放到Button中却没问题。。原因何在?请赐教。谢谢。
Classes,SysUtils,windows,myDLl;type
testr = class(TThread)
private
{ Private declarations }
procedure GetInfo;
protected
procedure Execute; override;
end;
var
Ghwnd:hwnd;implementation{ Important: Methods and properties of objects in visual components 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; }{ testr }procedure testr.Execute;
begin
{ Place thread code here }
while not Terminated do//当线程不终止时一址循环
begin
GetInfo;
Sleep(500);
end;
end;//得到信息
procedure testr.GetInfo;
var
proHandle: hwnd;
num: Cardinal;
BaseMan: dword;//人物基址
DXue: Cardinal;
//Name: array[0..32] of Widechar;begin
proHandle := OpenProcess(PROCESS_ALL_ACCESS, false, dwProcId);
ReadProcessMemory(proHandle, Pointer(base), @BaseMan, 4, Num);//一级基址
ReadProcessMemory(proHandle, Pointer(BaseMan + $1c), @BaseMan, 4, Num); //人物基址
ReadProcessMemory(proHandle, Pointer(BaseMan + $28), @BaseMan, 4, Num); //人物基址
ReadProcessMemory(proHandle, Pointer(BaseMan + $278), @DXue, 4, Num);//当前血 Form1.Edit3.Text:= IntToStr(DXue); //人物等级 CloseHandle(proHandle);
end;end.这个是线程的执行代码
的问题
begin
{ Place thread code here }
while not Terminated do//当线程不终止时一址循环
begin
Synchronize(GetInfo); //这里修改了
Sleep(500);
end;
end;