21. oktober 2001 - 12:45
#5
\'------------------------------------- Module1 -------------------------------------
Private Declare Function RegOpenKeyEx Lib \"advapi32.dll\" Alias \"RegOpenKeyExA\" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCreateKeyEx Lib \"advapi32.dll\" Alias \"RegCreateKeyExA\" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegQueryValueEx Lib \"advapi32.dll\" Alias \"RegQueryValueExA\" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Any) As Long
Private Declare Function RegSetValueEx Lib \"advapi32.dll\" Alias \"RegSetValueExA\" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib \"advapi32.dll\" (ByVal hKey As Long) As Long
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 RegDeleteValue Lib \"advapi32.dll\" Alias \"RegDeleteValueA\" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib \"advapi32.dll\" Alias \"RegOpenKeyA\" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib \"advapi32.dll\" Alias \"RegDeleteKeyA\" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Const REG_SZ = 1
Const REG_BINARY = 3
Const REG_DWORD = 4
Public Enum hKey
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum
Private Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Or REG_DWORD Then
Dim strData As Integer
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function
\'Ret = GetString(HKEY_CURRENT_USER, \"KeyPath\", \"StringName eller BinaryName\")
Function GetString(hKey As hKey, Path As String, Name As String) As String
Dim Ret As Long, ReturString As String
RegOpenKey hKey, Path, Ret
ReturString = RegQueryStringValue(Ret, Name)
RegCloseKey Ret
GetString = ReturString
End Function
\'SaveDWordValue HKEY_CURRENT_USER, \"KeyPath\", \"DWordName\", 999999999
Function SaveDWordValue(hKey As hKey, KeyPath As String, ValueName As String, DWordValue As Long)
Dim Ret As Long
If Val(DWordValue) > 999999999 Or Val(DWordValue) < 0 Then
Exit Function
End If
RegCreateKey hKey, KeyPath, Ret
RegSetValueEx Ret, ValueName, 0, REG_DWORD, DWordValue, Len(DWordValue)
RegCloseKey Ret
End Function
\'SaveStringValue HKEY_CURRENT_USER, \"KeyPath\", \"StringName\", \"ABC\"
Function SaveStringValue(hKey As hKey, KeyPath As String, ValueName As String, StringValue As String) As Long
Dim Ret, RetErr As Long
RegCreateKey hKey, KeyPath, Ret
RetErr = RegSetValueEx(Ret, ValueName, 0, REG_SZ, ByVal StringValue, Len(StringValue))
RegCloseKey Ret
End Function
\'SaveBinaryValue HKEY_CURRENT_USER, \"KeyPath\", \"BinaryName\", 255
Function SaveBinaryValue(hKey As hKey, KeyPath As String, ValueName As String, BinaryValue As Long)
Dim Ret As Long
If Val(BinaryValue) > 255 Or Val(BinaryValue) < 0 Then
Exit Function
End If
RegCreateKey hKey, KeyPath, Ret
RegSetValueEx Ret, ValueName, 0, REG_BINARY, CByte(BinaryValue), 4
RegCloseKey Ret
End Function
\'DeleteKeySetting HKEY_CURRENT_USER, \"KeyPath\", \"ValueName\"
Function DeleteKeySetting(hKey As hKey, KeyPath As String, ValueName As String)
Dim Ret As Long
RegCreateKey hKey, KeyPath, Ret
RegDeleteValue Ret, ValueName
RegCloseKey Ret
End Function
\'DeleteKeyPath HKEY_CURRENT_USER, \"KeyPath\"
Function DeleteKeyPath(hKey As hKey, KeyPath As String)
Dim Ret As Long
RegCreateKey hKey, KeyPath, Ret
RegDeleteKey Ret, \"\"
RegCloseKey Ret
End Function
\'------------------------------------- Module1 -------------------------------------
\'------------------------------------- Form1 -------------------------------------
Private Sub Form_Load()
Me.Caption = GetString(HKEY_CURRENT_USER, \"Control Panel\\International\", \"Locale\")
End Sub
\'------------------------------------- Form1 -------------------------------------