无论是用VC还是用Delphi,启动外部程序,
调用的都是相同的系统中的API函数,如下Delphi代码所示:
//登录按钮
procedure TForm1.Label_LoginClick(Sender: TObject);
beginRunOtherApp('C:\1.exe'); //启动1.exeend;//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;
