dcsimg
December 8, 2016
Hot Topics:

Create a Registry Control

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Add a Usercontrol (cReg). Add the following code to it's General Declarations procedure:

'Function for removing a key
Public Function fDeleteValue(ByVal HKey As Long, _
       ByVal strPath As String, _
       ByVal strValue As String)
Dim keyhand As Long
'Open it
r = RegOpenKey(HKey, strPath, keyhand)
'Delete it
r = RegDeleteValue(keyhand, strValue)
'Close it
r = RegCloseKey(keyhand)
End Function

 color="#FF00FF">'Function for getting a string
Public Function fGetstring(HKey As Long, _
       strPath As String, strValue As String)
Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
'Open it
r = RegOpenKey(HKey, strPath, keyhand)
'Query the registry
lResult = RegQueryValueEx(keyhand, strValue, _
          0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
  strBuf = String(lDataBufSize, " ")
  lResult = RegQueryValueEx(keyhand, strValue, _
            0&, 0&, ByVal strBuf, lDataBufSize)
  If lResult = ERROR_SUCCESS Then
    intZeroPos = InStr(strBuf, Chr$(0))
	If intZeroPos > 0
  Then
    fGetstring = Left$(strBuf, intZeroPos - 1)
  Else
    fGetstring = strBuf
  End If
End If
End If
End Function

'Function for saving a string
Public Sub fSaveString(HKey As Long, _
                       strPath As String, _
                       strValue As String, _
                       strdata As String)

Dim keyhand As Long
Dim r As Long

'Create it
r = RegCreateKey(HKey, strPath, keyhand)
'Set it 
r = RegSetValueEx(keyhand, strValue, 0, _
    REG_SZ, ByVal strdata,Len(strdata))
'Close it
r = RegCloseKey(keyhand)
End Sub

Private Sub UserControl_Initialize()
'Set the width and height values
UserControl.Width = UserControl.Picture.Width
UserControl.Height = UserControl.Picture.Height
End Sub

Private Sub UserControl_Resize()
'Reset the width and height values
UserControl.Width = UserControl.Picture.Width
UserControl.Height = UserControl.Picture.Height
End Sub




Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel