 |
| View previous topic :: View next topic |
| Author |
Message |
Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Aug 31st, 2004 07:45 AM Post subject: cRegistry Class with Examples |
|
|
Hello!
I recently wanted to have registry reading capability in my app. i found a registry module on the forums originally posted by forums...! It was good but it did not solved my purpose so i serached on the net and here's something what i found.
The cRegistry class is an easy, self-contained way to get complete access to the Windows registry. Simple methods allow you to create, enumerate and delete keys and values in the registry, without restriction. You can even read/write binary data to the registry. To see how powerful this library is, download the attached .zip file.
Hope this helps! P.S: Examples are in the reply!
Thanks! _________________ Code Snippets, Tutorials, Utilities, Controls
Low cost Web Hosting
Hosting starts at as low as $4 per year!
Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags! |
|
| Back to top |
|
Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Aug 31st, 2004 07:49 AM Post subject: |
|
|
Here is a brief summary of typical uses of the class:
To get a String Value from the Registry
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.ClassKey = HKEY_LOCAL_MACHINE
.SectionKey = "Software\MyApp\Tips"
.ValueKey = "Tip1"
.ValueType = REG_SZ
sTip = .Value
End With[/vb:1:fa156ea68e]To get a Numeric Value from the Registry
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.ClassKey = HKEY_LOCAL_MACHINE
.SectionKey = "Software\MyApp\Tips"
.ValueKey = "TipCount"
.ValueType = REG_DWORD
lTipCount = .Value
End With[/vb:1:fa156ea68e]To Save a Form's position to the Registry
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.ClassKey = HKEY_CURRENT_USER
' You don't need to check if this key already exists
' - the class will create it for you
.SectionKey = "Software\" & App.EXEName & "\" & frmThis.Name
.ValueKey = "Maximized"
.ValueType = REG_DWORD
.Value = (frmThis.WindowState = vbMaximized)
If (frmThis.WindowState <> vbMaximized)
.ValueKey = "Left"
.Value = frmThis.Left
.ValueKey = "Top"
.Value = frmThis.Top
.ValueKey = "Width"
.Value = frmThis.Width
.ValueKey = "Height"
.Value = frmThis.Height
End If
End With[/vb:1:fa156ea68e]To Get All The SubKeys of a Key
Note you can also get all the values for a key in a similar way, except you use EnumerateValues instead of EnumerateSections.
[vb:1:fa156ea68e]Dim c As New cRegistry
Dim sKeys() As String, iKeyCount As Long
With c
.ClassKey = HKEY_LOCAL_MACHINE
.SectionKey = "Software"
.EnumerateSections(sKeys(), iKeyCount)
For iKey = 1 To iKeyCount
Debug.Print sKeys(iKey)
Next iKey
End With[/vb:1:fa156ea68e]To Delete a Key
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.ClassKey = HKEY_LOCAL_MACHINE
.SectionKey = "Software\MyApp\Tips"
.DeleteKey
End With[/vb:1:fa156ea68e]To Delete a Value
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.ClassKey = HKEY_LOCAL_MACHINE
.SectionKey = "Software\MyApp\Tips"
.ValueKey = "Tip1"
.DeleteValue
End With[/vb:1:fa156ea68e]To Associate a File of type .CCD with your executable
[vb:1:fa156ea68e]Dim c As New cRegistry
With c
.CreateEXEAssociation _
App.Path & "\" & App.EXEName, _
"CCarDesign.Project", _
"Custom Car Designer Project", _
"CCD"
End With[/vb:1:fa156ea68e]To Read BINARY values from the registry
Binary values are returned as a variant of type byte array. This code demonstrates how to format the returned value into a string of hexadecimal values, similar to the display provided in RegEdit:
[vb:1:fa156ea68e]Dim cR As New cRegistry
Dim iByte As Long
Dim vR As Variant
With cR
.ClassKey = HKEY_CURRENT_USER
.SectionKey = "Control Panel\Appearance"
.ValueKey = "CustomColors"
vR = .Value
If .ValueType = REG_BINARY Then
' Read through the byte array and output it as a series of hex values:
For iByte = LBound(vR) To UBound(vR)
sOut = sOut & "&H"
If (iByte < &H10) Then
sOut = sOut & "0"
End If
sOut = sOut & Hex$(vR(iByte)) & " "
Next iByte
Else
sOut = vR
End If
Debug.Print sOut
End With[/vb:1:fa156ea68e]To Set BINARY values from the registry
Similarly, to store binary values in the registry, cRegistry.cls expects a byte array of the binary values you wish to store. This example (rather uselessly!) stores all the Red, Green, Blue values of each of VB's QBColors into a binary array:
[vb:1:fa156ea68e]Dim cR As New cRegistry
Dim i As Long
Dim lC As Long
Dim bR As Byte
Dim bG As Byte
Dim bB As Byte
Dim bOut() As Byte
' Create a binary array containing all the Red,Green,Blue values of the QBColors:
ReDim bOut(0 To 15 * 3 - 1) As Byte
For i = 1 To 15
' Get the Red, Green, Blue for the QBColor at index i:
lC = QBColor(i)
bR = (lC And &HFF&)
bG = ((lC And &HFF00&) \ &H100&)
bB = ((lC And &HFF0000) \ &H10000)
' Add Red, Green, Blue to the byte array to store:
bOut((i - 1) * 3) = bR
bOut((i - 1) * 3 + 1) = bG
bOut((i - 1) * 3 + 2) = bB
Next i
' Store it:
With cR
.ClassKey = HKEY_CURRENT_USER
.SectionKey = "software\vbaccelerator\cRegistry\Binary Test"
.ValueKey = "QBColors"
.ValueType = REG_BINARY
.Value = bOut()
End With[/vb:1:fa156ea68e] _________________ Code Snippets, Tutorials, Utilities, Controls
Low cost Web Hosting
Hosting starts at as low as $4 per year!
Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags! |
|
| Back to top |
|
BadBoyTazz4Ever Newbie

Joined: 24 Feb 2005 Posts: 7 Location: Pretoria, ZA
|
Posted: Feb 25th, 2005 02:31 AM Post subject: Re: cRegistry Class with Examples |
|
|
| Avis wrote: | Hello!
To see how powerful this library is, download the attached .zip file.
Hope this helps! P.S: Examples are in the reply!
Thanks! |
I can't seem to find the link (or i'm looking into the back of my own eye-lids???) Can you just point it out to me please...  _________________ I Live In My Own Little World. But It's OK. They Know Me Here.
[img]http://www.net-forums.net/fred/sig/stat.php?pic=1&username=BadBoyTazz4Ever" alt="Project Fred Stats" border="0"[/img] |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Feb 26th, 2005 09:16 PM Post subject: |
|
|
The attachment seems to have gotten lost in one of the forum upgrades, sorry  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|