右键卡卡转圈圈…Delphi执行外部程式 ShellExec API习作
前言动机:
电脑内软体愈灌愈多,有些会在右键添个捷径。于是,每次点右键 ”快捷键” 总是在绕圈圈,等到天长地久、地老天荒,尤其是刚开机之后、”电脑总管”更严重。或许是我电脑中毒? 还是机器太旧?
于是,想写个”档案总管”试试。
先看看如何在FileListBox中点选档案时,执行外部程式吧。
环境:Win 10 64x Delphi RAD10.4
下载 Source+执行档
部份程式码:
引用 uses ShellAPI;
procedure TForm1.doExec(fPath:string);begin //--- 执行外部程式 ( 依系统已设定之连结开启 ) ShellExecute(Handle, 'open', PChar(fPath),nil, nil, SW_SHOW);end;procedure TForm1.btnCloseClick(Sender: TObject);begin Close;end;procedure TForm1.btnExecClick(Sender: TObject);var fTmp,fullPath, fDir,YesNo : string; flag : Boolean;begin fDir := DirectoryListBox1.Directory; fTmp := FileListBox1.Items[FileListBox1.ItemIndex]; fullPath := fDir+'\'+fTmp; memFD.Lines.Add(fullPath); //--- 档案当然都存在 just for debug flag := FileExists(fullPath); if flag then YesNo := 'File Exist' else YesNo := 'File Not Exist'; memFD.Lines.Add(YesNo); //--- shellExec --- doExec(fullPath);end;