/////////////////////////////////////////////////////////////////////// //参数说明: //Handle:父窗口的句柄,defaultvalue = 0 //strFileName:要执行的文件,可以是可执行文件,也可以是任意个文件(shell将自己在register table中寻找关联的执行程序) //strParam:参数 //HasError:是否有错误 //strErrorMsg:错误信息 //hApp = Result:OS执行命令成功后,返回进程的ID,可用于OpenProcess... //另:ShellExecute在MSDN中的申明,是以后将作费,推荐使用ShellExecuteEx(32位API) function RunNotExe(Handle:Integer = 0;strFileName:String;strParam:String;var HasError:Boolean;var strErrorMsg:String;var hApp:Integer):Integer; var ErrorMsg:string; begin HasError:=False; Result:=ShellExecute(Handle,nil,pChar(strFileName),pChar(strParam),nil,SW_SHOWNORMAL); ErrorMsg:='系统提示:'+#13+#10; ErrorMsg:=ErrorMsg+'在运行文件:%s'+#13+#10; ErrorMsg:=ErrorMsg+' 参数:%s'+#13+#10; ErrorMsg:=ErrorMsg+'错误原因:'+#13+#10; ErrorMsg:=Format(ErrorMsg,[strFileName,strParam]); case Result of 0: //The operating system is out of memory or resources. begin HasError:=True; ErrorMsg:=ErrorMsg+'内存溢出!' end; ERROR_BAD_FORMAT: //The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). begin HasError:=True; ErrorMsg:=ErrorMsg+'这不是一个WIN32下的可执行文件!' end; SE_ERR_ACCESSDENIED: //The operating system denied access to the specified file. begin HasError:=True; ErrorMsg:=ErrorMsg+'由于你没有访问该文件的权限,操作失败!' end; SE_ERR_ASSOCINCOMPLETE: //The filename association is incomplete or invalid. begin HasError:=True; ErrorMsg:=ErrorMsg+'文件名无效!老兄,你的注册表有问题了!' end; SE_ERR_DDEBUSY: //The DDE transaction could not be completed because other DDE transactions were being processed. begin HasError:=True; ErrorMsg:=ErrorMsg+'DDE传送环境已被其它程序占用!' end; SE_ERR_DDEFAIL: //The DDE transaction failed. begin HasError:=True; ErrorMsg:=ErrorMsg+'DDE传送失败!' end; SE_ERR_DDETIMEOUT: //The DDE transaction could not be completed because the request timed out. begin HasError:=True; ErrorMsg:=ErrorMsg+'DDE传送超时!' end; SE_ERR_DLLNOTFOUND: //The specified dynamic-link library was not found. begin HasError:=True; ErrorMsg:=ErrorMsg+'所需的动态接连库(*.DLL)未找到!' end; SE_ERR_FNF: //The specified file was not found. begin HasError:=True; ErrorMsg:=ErrorMsg+'文件未找到!' end; SE_ERR_NOASSOC: //There is no application associated with the given filename extension. begin HasError:=True; ErrorMsg:=ErrorMsg+'无法打开一个这种后缀名的文件!'+#13+#10; ErrorMsg:=ErrorMsg+'噢,天呀!你放了些什么垃圾?:P'+#13+#10; end; SE_ERR_OOM: //There was not enough memory to complete the operation. begin HasError:=True; ErrorMsg:=ErrorMsg+'没有足够的内存完成该项操作!'+#13+#10; ErrorMsg:=ErrorMsg+'那么夸张!你多大的内存?换机器吧?:P'+#13+#10; end; SE_ERR_PNF: //The specified path was not found. begin HasError:=True; ErrorMsg:=ErrorMsg+'路径未找到!' end; SE_ERR_SHARE: //A sharing violation occurred. begin HasError:=True; ErrorMsg:=ErrorMsg+'公共冲突?不会吧?你打开什么文件呀?' end; end; strErrorMsg:=ErrorMsg; hApp:=Result; //返回Application的句柄 end;
procedure TFrmStart.SpeedButton15Click(Sender: TObject); var pp:pchar; begin pp:=Pchar(ExtractFilePath(Application.exeName)+'htm\考试大纲.htm'); Shellexecute(0,'open',pp,nil,nil,SW_SHOWNORMAL); end;
主要是加入shellapi单元 下来可以直接调用
在uses里加入shellapi;ShellExecute(,,, nil, nil,);
to SukerLord(SukerLord) (ShellExecute(0, 'open', 'http://www.csdn.net', nil, nil, SW_NORMAL); 这条语句不行呀。
Uses ShellAPI;ShellExecute(GetDesktopWindow,'open','mailto:[email protected]',nil,nil,1); 函数原型: function ShellExecute(hWnd: HWND; Operation, FileName, Parameters, Directory: PChar; ShowCmd: Integer): HINST; stdcall; 使用说明: hWnd A long value containing the window’s handle LpOperation A string specifying the operation the ShellExecute function is to perform. One of the following three values may be specified: Open—Indicates the file lpFile is to be opened. Under the Windows 95 operating system, this file may be a folder. Print—Indicates the file lpFile is to be printed. Explore—Indicates the folder specified in lpFile is to be explored. LpFile A string containing the name of the file to open, print, or explore. LpParameters Set to NULL if lpFile specifies a document file. If lpFile specifies an executable file, then lpParameters is a pointer to a string specifying the parameters that should be passed to the application. LpDirectory A string specifying the default directory’s name. NShowCmd If a document file is specified in lpFile, this should be set to a value of zero. If an executable file is specified in lpFile, this determines how the ShellExecute function displays the application after it is loaded. The following values may be used: SW_HIDE Hides the window and activates the executable file. SW_MAXIMIZE Maximizes the window. SW_MINIMIZE Minimizes the window. The next top-level window in the Z-order is activated. SW_RESTORE Activates the window even if it is hidden or minimized SW_SHOW Activates the window and displays it in its original size and at its original position. SW_SHOWMAXIMIZED Activates the window. The window is displayed as maximized. SW_SHOWMINIMIZED Activates the window. The window is displayed as minimized. SW_SHOWMINNOACTIVE Activates the window as minimized. The active window retains the focus. SW_SHOWNA Activates the window in its current state but the active window retains the focus. SW_SHOWNOACTIVATE Displays the window in its most recent size and in its most recent position. The active window retains the focus. SW_SHOWNORMAL Displays the window in its original size and at its original position. 属性、事件、方法程序 说明 ShellExecute 方法程序 试图运行 tcWorkDir 目录中的 tcFileName 文件。 语法:ShellExecute(tcFileName, tcWorkDir, tcOperation) 返回值:nSuccess 参数: tcFileName 指定所要运行的文件。 tcWorkDir 指定所要运行文件的路径。 tcOperation 指定所要进行的操作。 nSuccess 使用下列值指定运行是否成功。2 = 错误的关联(例如,无效的 URL) 29 = 加载应用程序失败 30 = 应用程序忙 31 = 无相关的应用程序大于 32 的值代表成功,并且返回运行应用程序的一个实例句柄。
LPCTSTR lpOperation, // 指明操作类型的传,可以是OPEN ,PRINT,EXPLORE LPCTSTR lpFile, // 需要执行的文件路径
LPCTSTR lpParameters, // 如果要执行的是个可执行文件,这个参数表示需要传递给执行文件的参数,如果是个稳当,则为NULL
LPCTSTR lpDirectory, // 指向默认目录
INT nShowCmd // 执行后文件窗体的显示方式
);更详细的内容,看看D的SDK帮助把
//参数说明:
//Handle:父窗口的句柄,defaultvalue = 0
//strFileName:要执行的文件,可以是可执行文件,也可以是任意个文件(shell将自己在register table中寻找关联的执行程序)
//strParam:参数
//HasError:是否有错误
//strErrorMsg:错误信息
//hApp = Result:OS执行命令成功后,返回进程的ID,可用于OpenProcess...
//另:ShellExecute在MSDN中的申明,是以后将作费,推荐使用ShellExecuteEx(32位API)
function RunNotExe(Handle:Integer = 0;strFileName:String;strParam:String;var HasError:Boolean;var strErrorMsg:String;var hApp:Integer):Integer;
var
ErrorMsg:string;
begin
HasError:=False;
Result:=ShellExecute(Handle,nil,pChar(strFileName),pChar(strParam),nil,SW_SHOWNORMAL); ErrorMsg:='系统提示:'+#13+#10;
ErrorMsg:=ErrorMsg+'在运行文件:%s'+#13+#10;
ErrorMsg:=ErrorMsg+' 参数:%s'+#13+#10;
ErrorMsg:=ErrorMsg+'错误原因:'+#13+#10;
ErrorMsg:=Format(ErrorMsg,[strFileName,strParam]); case Result of
0: //The operating system is out of memory or resources.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'内存溢出!'
end;
ERROR_BAD_FORMAT: //The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'这不是一个WIN32下的可执行文件!'
end;
SE_ERR_ACCESSDENIED: //The operating system denied access to the specified file.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'由于你没有访问该文件的权限,操作失败!'
end;
SE_ERR_ASSOCINCOMPLETE: //The filename association is incomplete or invalid.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'文件名无效!老兄,你的注册表有问题了!'
end;
SE_ERR_DDEBUSY: //The DDE transaction could not be completed because other DDE transactions were being processed.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'DDE传送环境已被其它程序占用!'
end;
SE_ERR_DDEFAIL: //The DDE transaction failed.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'DDE传送失败!'
end;
SE_ERR_DDETIMEOUT: //The DDE transaction could not be completed because the request timed out.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'DDE传送超时!'
end;
SE_ERR_DLLNOTFOUND: //The specified dynamic-link library was not found.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'所需的动态接连库(*.DLL)未找到!'
end;
SE_ERR_FNF: //The specified file was not found.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'文件未找到!'
end;
SE_ERR_NOASSOC: //There is no application associated with the given filename extension.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'无法打开一个这种后缀名的文件!'+#13+#10;
ErrorMsg:=ErrorMsg+'噢,天呀!你放了些什么垃圾?:P'+#13+#10;
end;
SE_ERR_OOM: //There was not enough memory to complete the operation.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'没有足够的内存完成该项操作!'+#13+#10;
ErrorMsg:=ErrorMsg+'那么夸张!你多大的内存?换机器吧?:P'+#13+#10;
end;
SE_ERR_PNF: //The specified path was not found.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'路径未找到!'
end;
SE_ERR_SHARE: //A sharing violation occurred.
begin
HasError:=True;
ErrorMsg:=ErrorMsg+'公共冲突?不会吧?你打开什么文件呀?'
end;
end;
strErrorMsg:=ErrorMsg;
hApp:=Result;
//返回Application的句柄
end;
var
pp:pchar;
begin
pp:=Pchar(ExtractFilePath(Application.exeName)+'htm\考试大纲.htm');
Shellexecute(0,'open',pp,nil,nil,SW_SHOWNORMAL);
end;
下来可以直接调用
这条语句不行呀。
ShellAPI;ShellExecute(GetDesktopWindow,'open','mailto:[email protected]',nil,nil,1);
函数原型:
function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): HINST; stdcall;
使用说明:
hWnd A long value containing the window’s handle
LpOperation A string specifying the operation the ShellExecute function is to perform. One of the following three values may be specified:
Open—Indicates the file lpFile is to be opened. Under the Windows 95 operating system, this file may be a folder.
Print—Indicates the file lpFile is to be printed.
Explore—Indicates the folder specified in lpFile is to be explored.
LpFile A string containing the name of the file to open, print, or explore.
LpParameters Set to NULL if lpFile specifies a document file. If lpFile specifies an executable file, then lpParameters is a pointer to a string specifying the parameters that should be passed to the application.
LpDirectory A string specifying the default directory’s name.
NShowCmd If a document file is specified in lpFile, this should be set to a value of zero. If an executable file is specified in lpFile, this determines how the ShellExecute function displays the application after it is loaded. The following values may be used:
SW_HIDE Hides the window and activates the executable file.
SW_MAXIMIZE Maximizes the window.
SW_MINIMIZE Minimizes the window. The next top-level window in the Z-order is activated.
SW_RESTORE Activates the window even if it is hidden or minimized
SW_SHOW Activates the window and displays it in its original size and at its original position.
SW_SHOWMAXIMIZED Activates the window. The window is displayed as maximized.
SW_SHOWMINIMIZED Activates the window. The window is displayed as minimized.
SW_SHOWMINNOACTIVE Activates the window as minimized. The active window retains the focus.
SW_SHOWNA Activates the window in its current state but the active window retains the focus.
SW_SHOWNOACTIVATE Displays the window in its most recent size and in its most recent position. The active window retains the focus.
SW_SHOWNORMAL Displays the window in its original size and at its original position.
属性、事件、方法程序 说明
ShellExecute 方法程序 试图运行 tcWorkDir 目录中的 tcFileName 文件。
语法:ShellExecute(tcFileName, tcWorkDir, tcOperation)
返回值:nSuccess
参数:
tcFileName 指定所要运行的文件。
tcWorkDir 指定所要运行文件的路径。
tcOperation 指定所要进行的操作。
nSuccess 使用下列值指定运行是否成功。2 = 错误的关联(例如,无效的 URL)
29 = 加载应用程序失败
30 = 应用程序忙
31 = 无相关的应用程序大于 32 的值代表成功,并且返回运行应用程序的一个实例句柄。