beetlegis
路人甲
路人甲
  • 注册日期2004-02-18
  • 发帖数34
  • QQ
  • 铜币138枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2007回复:2

如何直接开启一个文件

楼主#
更多 发布于:2004-04-07 13:18


Shell 是用来执行外部的可执行文件

如果是一个文件,那要用ShellExecute来启动预设的程式来开启文件
注释:HINSTANCE ShellExecute(

注释: HWND hwnd, // handle to parent window
注释: LPCTSTR lpOperation, // pointer to string that specifies

operation to perform
注释: LPCTSTR lpFile, // pointer to filename string

注释: LPTSTR 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
注释: );

例:.doc 是由word或wordpad来开启
Declare Function ShellExecute Lib "shell32.dll" Alias

"ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _

ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Const SW_SHOW = 5
ret = ShellExecute(me.hWnd, "open" , "文件完整路径及名称","", "", SW_SHOW

事实上有一个更快的方式,便是使用Start指令,这个指令用法简单
eg. Start mydoc.doc

故,在vb中便是使用 Shell "start mydoc.doc"
如何查看某个文件是和谁相关联呢?例如:.txt是由哪个程式开启,

1.查[HKEY_CLASSES_ROOT\.txt]
取预设值,如本人电脑预设值为 "txtfile"

2.查[HKEY_CLASSES_ROOT\txtfile\shell\open\command]
取预设值,如本人电脑预设值为 "C:\WINDOWS\NOTEPAD.EXE %1"

如此可知.txt 是内定由NotePad.exe所执行。
注:若step 1.取得的预设值是 "xxxx",则step 2.便是查

[HKEY_CLASSES_ROOT\xxxx\shell\open\command]的预设值

喜欢0 评分0
wind7809
路人甲
路人甲
  • 注册日期2004-10-16
  • 发帖数48
  • QQ
  • 铜币82枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-11-13 18:27
shelleexec
举报 回复(0) 喜欢(0)     评分
cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29655枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
2楼#
发布于:2004-11-18 09:02
<P>在网页里面用</P><P>atixci的也可以</P>
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
举报 回复(0) 喜欢(0)     评分
游客

返回顶部