delphi label.caption

来源:百度知道 编辑:UC知道 时间:2024/05/17 07:23:53
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Labhp: TLabel;
Labmp: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Hwnd: THandle;
pid: THandle;
hp, mp: Cardinal;
ProcessID: Thandle;
Esi: Cardinal;
Num: Cardinal;
const baseadr = $02A48F90; //一级基址

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Hwnd := FindWindow('QElementClient Window','口袋西游');
if Hwnd = 0 then
begin
Show

Hwnd := FindWindow('QElementClient Window', '口袋西游'); //获取窗口
if Hwnd = 0 then
begin
ShowMessage('游戏未启动');
end

else
begin
GetWindowThreadProcessId(Hwnd, pid); //进程ID
ProcessID := OpenProcess(PROCESS_ALL_ACCESS, false, pid); // 进程句柄
if ProcessID = 0 then
begin
ShowMessage('无法打开线程');
end;
ReadProcessMemory(ProcessID, Pointer(baseadr), @Esi, 4, Num);
ReadProcessMemory(ProcessID, Pointer(Esi + $278), @hp, 4, Num); //血

Labhp.Caption := inttostr(hp);
CloseHandle(ProcessID);
end;
end;
你的程序中begin,end不对应,当然会出错