0
点赞
收藏
分享

微信扫一扫

Delphi启动外部程序


无论是用VC还是用Delphi,启动外部程序,

调用的都是相同的系统中的API函数,如下Delphi代码所示:


//登录按钮
procedure TForm1.Label_LoginClick(Sender: TObject);
begin

RunOtherApp('C:\1.exe'); //启动1.exe

end;

//Delphi启动其它程序函数
//参数appPath为要打开的程序的路径
procedure TForm1.RunOtherApp(appPath:String);
begin

//使用WinExec也可以打开程序,这里不用
//WinExec(Pchar(appPath),sw_normal);

//使用ShellExecute必须引用ShellAPI.pas单元:uses ShellAPI;
ShellExecute(0,'open',Pchar(appPath),nil,nil,SW_SHOWNORMAL);

//ShellExecute原型如下
//HINSTANCE ShellExecute(
// HWND hwnd,
// LPCTSTR lpVerb,
// LPCTSTR lpFile,
// LPCTSTR lpParameters,
//LPCTSTR lpDirectory,
// INT nShowCmd
//);

end;


​​​​


举报

相关推荐

0 条评论