Delphi中ShellExecute的妙用
2016-12-19 09:59
309 查看
请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。
ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。
有几个API函数都可以实现这些功能,但是在大多数情况下ShellExecute是更多的被使用的,同时它并不是太复杂。下面举例说明它的用法。
开始一个新的应用程序
ShellExecute(Handle, 'open', PChar('c:/test/app.exe'), nil, nil, SW_SHOW);
打开记事本,并打开一个文件(系统能识别记事本应用程序的路径,因此我们不必使用绝对路径)
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:/test/readme.txt'), nil, SW_SHOW);
打印一个文档
ShellExecute(Handle, 'print', PChar('c:/test/test.doc'), nil, nil, SW_SHOW);
注意:可能你会看到word暂时的被打开,但它会自动关闭。
打开一个HTML页面
ShellExecute(Handle, 'open', PChar('http://www.festra.com/'),
nil, nil, SW_SHOW);
你能通过一个已经注册的文件类型来打开应用程序
ShellExecute(Handle, 'open', PChar('c:/test/readme.txt'), nil, nil, SW_SHOW);
用windows Explorer 打开一个目录
ShellExecute(Handle, 'explore', PChar('c:/windows)', nil, nil, SW_SHOW);
运行一个DOS命令并立即返回
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);
运行一个DOS命令并保持DOS窗口存在
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);
ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。
有几个API函数都可以实现这些功能,但是在大多数情况下ShellExecute是更多的被使用的,同时它并不是太复杂。下面举例说明它的用法。
开始一个新的应用程序
ShellExecute(Handle, 'open', PChar('c:/test/app.exe'), nil, nil, SW_SHOW);
打开记事本,并打开一个文件(系统能识别记事本应用程序的路径,因此我们不必使用绝对路径)
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:/test/readme.txt'), nil, SW_SHOW);
打印一个文档
ShellExecute(Handle, 'print', PChar('c:/test/test.doc'), nil, nil, SW_SHOW);
注意:可能你会看到word暂时的被打开,但它会自动关闭。
打开一个HTML页面
ShellExecute(Handle, 'open', PChar('http://www.festra.com/'),
nil, nil, SW_SHOW);
你能通过一个已经注册的文件类型来打开应用程序
ShellExecute(Handle, 'open', PChar('c:/test/readme.txt'), nil, nil, SW_SHOW);
用windows Explorer 打开一个目录
ShellExecute(Handle, 'explore', PChar('c:/windows)', nil, nil, SW_SHOW);
运行一个DOS命令并立即返回
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);
运行一个DOS命令并保持DOS窗口存在
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);
相关文章推荐
- ::GetModuleFileName函数的一个妙用
- 鼠标中键在Firefox中的妙用
- socket篇:select函数的妙用
- 同义词的妙用
- managed vc++ 妙用
- SplashScreenSource的妙用
- 妙用bat文件
- linux下shell命令date的妙用
- c# 扩展方法奇思妙用高级篇五:ToString(string format) 扩展
- #ifdef的妙用
- C++ STL fstream的一个妙用
- c#扩展方法奇思妙用变态篇三:switch/case组扩展
- 位运算的妙用
- php中ASCⅡ码的妙用
- SSDT Hook的妙用-对抗ring0 inline hook
- dynamic_cast的妙用
- Hibernate之HQL妙用
- 妙用JavaScript实现网页的任意缩放
- c#扩展方法奇思妙用 ASP.NET MVC 篇:巧用扩展方法优先级,美化所有页面 TextBoxFor 文本框
- (void)(&x == &y)妙用