D
doud
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, jpeg, inifiles, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
tt,ff: integer;
initpjk: Tinifile;
ckyxbt,wjmc,zdlj,dqlj: string;
zdys,ysddsj: string;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var ycz: hwnd; // 目标窗口句柄
filename: string; // ini 文件名
begin
try
Filename:=ExtractFilePath(Paramstr(0))+'tpjk.ini'; // 指定当前目录下的 tpjk.ini
initpjk:=tinifile.create(filename);
ckyxbt:=initpjk.readstring('运行参数','窗口运行标题','');
zdys:=initpjk.readstring('运行参数','指定延时','');
ysddsj:=initpjk.readstring('运行参数','延迟等待时间','');
wjmc:=initpjk.readstring('运行参数','文件名称','');
zdlj:=initpjk.readstring('路径','指定路径','');
dqlj:=initpjk.readstring('路径','当前路径','');
label1.caption:=ckyxbt;
label2.caption:=zdys;
label3.caption:=ysddsj;
label4.caption:=wjmc;
label5.caption:=zdlj;
ycz:=findwindow(nil,pchar(ckyxbt)); // 得到目标窗口句柄
tt:=gettickcount;
if ycz=0 then
begin
if dqlj='是' then
winexec(pchar(wjmc),SW_minimize)
else
winexec(pchar(trim(zdlj)+trim(wjmc)),SW_minimize);
ff:=tt;
end
else
begin
messagebox(0,'此程序已经运行','提示',mb_iconwarning);
end;
except
begin
messagebox(0,'读tpjk错误,请检查','提示',mb_iconINFORMATION);
initpjk.destroy;
close;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var bb: integer;
jb: hwnd;
begin
bb:=gettickcount;
jb:=findwindow(nil,pchar(ckyxbt));
if (bb-tt)/1000>strtoint(zdys) then
if jb<>0 then begin
showwindow(jb,sw_minimize);
initpjk.destroy;
close;
end;
if (bb-tt)/1000>strtoint(ysddsj) then begin
// messagebox(0,'目标程序无法运行,请检查路径或调整延迟等待时间','超时',mb_iconERROR);
initpjk.destroy;
close;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// initpjk.destroy;
end;
end.
此段程序想读取 TPJK.INI 中的参数,但修改TPJK.INI 后,经常无法取得
正确的值,对TPJK.INI 多次存盘后有时可读对,其余均为前次设置。
谢谢!!(急死了)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, jpeg, inifiles, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
tt,ff: integer;
initpjk: Tinifile;
ckyxbt,wjmc,zdlj,dqlj: string;
zdys,ysddsj: string;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var ycz: hwnd; // 目标窗口句柄
filename: string; // ini 文件名
begin
try
Filename:=ExtractFilePath(Paramstr(0))+'tpjk.ini'; // 指定当前目录下的 tpjk.ini
initpjk:=tinifile.create(filename);
ckyxbt:=initpjk.readstring('运行参数','窗口运行标题','');
zdys:=initpjk.readstring('运行参数','指定延时','');
ysddsj:=initpjk.readstring('运行参数','延迟等待时间','');
wjmc:=initpjk.readstring('运行参数','文件名称','');
zdlj:=initpjk.readstring('路径','指定路径','');
dqlj:=initpjk.readstring('路径','当前路径','');
label1.caption:=ckyxbt;
label2.caption:=zdys;
label3.caption:=ysddsj;
label4.caption:=wjmc;
label5.caption:=zdlj;
ycz:=findwindow(nil,pchar(ckyxbt)); // 得到目标窗口句柄
tt:=gettickcount;
if ycz=0 then
begin
if dqlj='是' then
winexec(pchar(wjmc),SW_minimize)
else
winexec(pchar(trim(zdlj)+trim(wjmc)),SW_minimize);
ff:=tt;
end
else
begin
messagebox(0,'此程序已经运行','提示',mb_iconwarning);
end;
except
begin
messagebox(0,'读tpjk错误,请检查','提示',mb_iconINFORMATION);
initpjk.destroy;
close;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var bb: integer;
jb: hwnd;
begin
bb:=gettickcount;
jb:=findwindow(nil,pchar(ckyxbt));
if (bb-tt)/1000>strtoint(zdys) then
if jb<>0 then begin
showwindow(jb,sw_minimize);
initpjk.destroy;
close;
end;
if (bb-tt)/1000>strtoint(ysddsj) then begin
// messagebox(0,'目标程序无法运行,请检查路径或调整延迟等待时间','超时',mb_iconERROR);
initpjk.destroy;
close;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// initpjk.destroy;
end;
end.
此段程序想读取 TPJK.INI 中的参数,但修改TPJK.INI 后,经常无法取得
正确的值,对TPJK.INI 多次存盘后有时可读对,其余均为前次设置。
谢谢!!(急死了)