想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的如何直接开启一个文件教程,一起来看看吧!超容易上手~
【 tulaoshi.com - 编程语言 】
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 LongConst SW_SHOW = 5ret = ShellExecute(me.hWnd, "open" , "文件完整路径及名称","", "", SW_SHOW
事实上有一个更快的方式,便是使用Start指令,这个指令用法简单
eg. Start mydoc.doc
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)故,在vb中便是使用 Shell "start mydoc.doc"
如何查看某个文件是和谁相关联呢?例如:.txt是由哪个程式开启,
1.查[HKEY_CLASSES_ROOT.txt]
取预设值,如本人电脑预设值为 "txtfile"
2.查[HKEY_CLASSES_ROOTtxtfileshellopencommand]
取预设值,如本人电脑预设值为 "C:WINDOWSNOTEPAD.EXE %1"
如此可知.txt 是内定由NotePad.exe所执行。
注:若step 1.取得的预设值是 "xxxx",则step 2.便是查
[HKEY_CLASSES_ROOTxxxxshellopencommand]的预设值
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)来源:http://www.tulaoshi.com/n/20160219/1613300.html