closing any program and getting the handle to close it or the window name...


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]

Posted by al_Lan on December 12, 2002 at 11:03:49:

this is what i have managed to do...
I'm trying to get this program to open and close half-life...

var
  Form1: TForm1;
  y : TDateTime;
  x : real;
  z , showtime : integer;
  CSHndl : Thandle;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
  code : integer;
begin
 y := time;
 y := y + strtotime(edit1.text);
 edit1.Text := timetostr(y);
 label3.caption := timetostr(y);
 x := ShellExecute(CSHndl,NIL,PChar(label1.caption), nil,nil,SW_SHOWNORMAL);
 z := 0;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
begin label2.caption := timetostr(time); if y < time then z := z + 1; if z = 1 then begin CSHndl := FindWindow(nil,'half-life'); If CSHndl <> 0 Then SendMessage(CSHndl, WM_SYSCOMMAND,SC_CLOSE,0); if application.messagebox('you''ve played too long Nic how about some work???'+#13'(to keep playing hit no...)', 'WORK BOY!',MB_YESNO+MB_ICONEXCLAMATION) = 7 then application.MessageBox('YOU SHALL NOT PLAY!','WORK BOY!',MB_OK+MB_ICONEXCLAMATION); application.terminate; showtime := 1; end; if showtime = 1 then begin
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
  z := 0;
  y := time + 20;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  opendialog1.Execute;
  label1.caption := opendialog1.FileName;
end;
end.

Related Articles and Replies:


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]