如何在程序里设置文件打开的关联程序??? rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有篇文章写过http://www.lshdic.com/bbs/files.asp?dex=软件开发交流论坛&page=1&myclass=296内容:如果你的程序是同文件操作有关,比如说你自定义了一个文件类型,用你的程序才能打开它并查看其中的内容。你有没有想过在你的文件同你的程序之间建立关联,这样不必每次都要先启动程序,再打开文件了。用户可直接点选你的文件,而不必每次都要面对一个“打开方式”对话框。其实要做到这一点,只须调用API函数就行了。下面的代码向你演示如何实现这一功能。首先在窗体的通用声明段中加入下面的代码:Option Explicit Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, _ ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, _ ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long ' Return codes from Registration functions. Const ERROR_SUCCESS = 0& Const ERROR_BADDB = 1& Const ERROR_BADKEY = 2& Const ERROR_CANTOPEN = 3& Const ERROR_CANTREAD = 4& Const ERROR_CANTWRITE = 5& Const ERROR_OUTOFMEMORY = 6& Const ERROR_INVALID_PARAMETER = 7& Const ERROR_ACCESS_DENIED = 8& Private Const HKEY_CLASSES_ROOT = &H80000000 Private Const MAX_PATH = 260& Private Const REG_SZ = 1在窗体的Click事件中加入下面的代码 Private Sub Form_Click() Dim sKeyName As String 'Holds Key Name in registry. Dim sKeyValue As String 'Holds Key Value in registry. Dim ret& 'Holds error status if any from API calls. Dim lphKey& 'Holds created key handle from RegCreateKey. 'This creates a Root entry called "MyApp". sKeyName = "MyApp" sKeyValue = "My Application" ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) 'This creates a Root entry called .BAR associated with "MyApp". sKeyName = ".BAR" sKeyValue = "MyApp" ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) 'This sets the command line for "MyApp". sKeyName = "MyApp" sKeyValue = "c:\mydir\my.exe %1" ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, _ sKeyValue, MAX_PATH) End Sub 按F5运行程序并在窗体上点击一下鼠标,然后退出程序从开始菜单中运行REGEDIT,你可在HKEY_CLASSES_ROOT下找到.bar和MyApp两个子项,结构如下所示: .bar = MyApp MyApp = My Application | -- Shell | -- open | -- command = c:\mydir\my.exe %1 在vb中如何把access的数据用曲线图表达出来?最好有例子! 有个需求,请各位高手给点灵感,谢谢 菜鸟请教:如何删除msflexgrid控件的记录? 高手请进,十万火急 寻找光标停在某一标题时手的图标 问一个关于动态数组的问题 请问一个问题:关于动态建立控件的问题! 请教:如何在VB里对某一个文件夹下的所有文件包括若干级子目录全部遍历一遍? IT 人员要找同行做老婆吗??? 如何用代码更改一个exe文件的图标?(要多少分由你定) crystal报表要刷新几遍才能出现结果? 如何在一个程序的设计中,建立一个文件?以便被这个程序调用???
ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, _
ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long ' Return codes from Registration functions.
Const ERROR_SUCCESS = 0&
Const ERROR_BADDB = 1&
Const ERROR_BADKEY = 2&
Const ERROR_CANTOPEN = 3&
Const ERROR_CANTREAD = 4&
Const ERROR_CANTWRITE = 5&
Const ERROR_OUTOFMEMORY = 6&
Const ERROR_INVALID_PARAMETER = 7&
Const ERROR_ACCESS_DENIED = 8& Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const MAX_PATH = 260&
Private Const REG_SZ = 1在窗体的Click事件中加入下面的代码 Private Sub Form_Click() Dim sKeyName As String 'Holds Key Name in registry.
Dim sKeyValue As String 'Holds Key Value in registry.
Dim ret& 'Holds error status if any from API calls.
Dim lphKey& 'Holds created key handle from RegCreateKey. 'This creates a Root entry called "MyApp".
sKeyName = "MyApp"
sKeyValue = "My Application"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) 'This creates a Root entry called .BAR associated with "MyApp".
sKeyName = ".BAR"
sKeyValue = "MyApp"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) 'This sets the command line for "MyApp".
sKeyName = "MyApp"
sKeyValue = "c:\mydir\my.exe %1"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, _
sKeyValue, MAX_PATH)
End Sub 按F5运行程序并在窗体上点击一下鼠标,然后退出程序从开始菜单中运行REGEDIT,你可在HKEY_CLASSES_ROOT下找到.bar和MyApp两个子项,结构如下所示: .bar = MyApp
MyApp = My Application
|
-- Shell
|
-- open
|
-- command = c:\mydir\my.exe %1