如何在 Windows操作系统中改变文件打开方式
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String, strData As String) As Boolean
Dim lResult As Long
Dim lValueType As Long
Dim strBuf As String
Dim lDataBufSize As Long
RegQueryStringValue = False
On Error GoTo 0
lResult = OSRegQueryValueEx(hKey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = OSRegQueryValueEx(hKey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = True
strData = StripTerminator(strBuf)
End If
End If
End If
End Function
5、双击Command1,编写Click事件代码。
Private Sub Command1_Click()
Dim hKey As Long
Dim MyReturn As Long
Dim MyData As String
MyReturn = OSRegOpenKey(HKEY_CLASSES_ROOT, ".exc", hKey)
MyReturn = RegQueryStringValue(hKey, "", MyData)
MyReturn = OSRegOpenKey(HKEY_CLASSES_ROOT, MyData + "\shell\open\command", hKey)
MyReturn = RegSetStringValue(hKey, "", "c:\visio.exe 1%", False)
If MyReturn Then
MsgBox "改变文件打开方式成功!", vbInformation, "请注意"
Else
MsgBox "改变文件打开方式失败!", vbExclamation, "请注意"
End If
OSRegCloseKey (hKey)
End Sub
6、按F5运行程序,在简体中文Windows95/NT/98、VB5.0/6.0环境中调试
《如何在 Windows操作系统中改变文件打开方式(第3页)》