用ShellExecute这个API函数先要Uses ShellAPI;HINSTANCE ShellExecute( HWND hwnd, // handle to parent window LPCTSTR lpOperation, // pointer to string that specifies operation to perform LPCTSTR lpFile, // pointer to filename or folder name string LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters LPCTSTR lpDirectory, // pointer to string that specifies default directory INT nShowCmd // whether file is shown when opened );
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
ShellExec() //要uses ShellApi
CreateProcess()
自己看一下帮助
hwnd:窗体的句柄;
lpOperation:打开程序执行的操作,共预留有"open","explore","print"三种方式,此参数可以省略,此时将依据打开的文件(lpFile)的类型执行相应的操作,比如:如果lpFile为一文本文件,那么将会在与该文件相关联的程序中打开它;
lpFile:文件名;
lpParamerters:打开文件时所需的参数;
lpDirectory:文件名所在的路径,当然,一般来说,在Windows中登
"记记"过的程序(如WinWord)不必提供此参数;
nShowCmd:打开文件后程序窗体如何显示。
该函数的详细文档请读者朋友参阅相应帮助。其次,我们来举一个例子(以"记事本"为例):
procedure TForm1.OpenBtnClick(Sender:TObject);
begin
ShellExecute(handle,'open','notepad.exe',nil,nil,SW_ShowNormal);
end;
那就直接用文件名了, 也可用相对路径