public filepath:string; filehandle:thandle; { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin if opendialog1.Execute then begin edit1.Text:=opendialog1.FileName; filepath:=edit1.Text; filehandle:=WinExec(pansichar(filepath),SW_SHOWNORMAL); end; end;
procedure TForm1.Button2Click(Sender: TObject); begin if filehandle<>0 then SendMessage(filehandle,WM_CLOSE,0,0) else showmessage(’文件没有找到!’); end;
function GetLongFileName(Const FileName : String) : String; var aInfo: TSHFileInfo; begin if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then Result:= String(aInfo.szDisplayName) else Result:= FileName; end;
procedure TForm1.Button1Click(Sender: TObject); begin if opendialog1.Execute then begin edit1.Text:=opendialog1.FileName; files:= opendialog1.FileName ; filepath:=edit1.Text; filehandle:=WinExec(pansichar(filepath),SW_SHOWNORMAL); end; Edit2.text:= GetLongFileName(files); end;
procedure TForm1.Button2Click(Sender: TObject); begin filehandle := FindWindow(nil, pansichar(Edit2.text)); if filehandle <> 0 then SendMessage(filehandle, WM_CLOSE, 0, 0) else Application.MessageBox('沒有打開“樂透彩中獎號碼”!','提示', MB_IconInformation+MB_OK); end;
----------------------------------------------