home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / regicon / form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-11-19  |  16.3 KB  |  486 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "RegiCon Test"
  4.    ClientHeight    =   4230
  5.    ClientLeft      =   2265
  6.    ClientTop       =   3045
  7.    ClientWidth     =   7365
  8.    Height          =   4635
  9.    Left            =   2205
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    ScaleHeight     =   4230
  13.    ScaleWidth      =   7365
  14.    Top             =   2700
  15.    Width           =   7485
  16.    Begin VB.CommandButton cmdIsKey 
  17.       Caption         =   "Does Key Exist?"
  18.       Height          =   375
  19.       Left            =   5400
  20.       TabIndex        =   27
  21.       Top             =   840
  22.       Width           =   1815
  23.    End
  24.    Begin VB.CommandButton cmdExit 
  25.       Caption         =   "Exit"
  26.       Height          =   375
  27.       Left            =   5400
  28.       TabIndex        =   17
  29.       Top             =   3240
  30.       Width           =   1815
  31.    End
  32.    Begin VB.CommandButton cmdIsItem 
  33.       Caption         =   "Does Item Exist?"
  34.       Height          =   375
  35.       Left            =   5400
  36.       TabIndex        =   16
  37.       Top             =   2760
  38.       Width           =   1815
  39.    End
  40.    Begin VB.CommandButton cmdDeleteKeyItem 
  41.       Caption         =   "Delete Item"
  42.       Height          =   375
  43.       Left            =   5400
  44.       TabIndex        =   15
  45.       Top             =   2400
  46.       Width           =   1815
  47.    End
  48.    Begin VB.CommandButton cmdGetKeyItem 
  49.       Caption         =   "Get Item"
  50.       Height          =   375
  51.       Left            =   5400
  52.       TabIndex        =   14
  53.       Top             =   2040
  54.       Width           =   1815
  55.    End
  56.    Begin VB.CommandButton cmdSetKeyItem 
  57.       Caption         =   "Set Item"
  58.       Height          =   375
  59.       Left            =   5400
  60.       TabIndex        =   13
  61.       Top             =   1680
  62.       Width           =   1815
  63.    End
  64.    Begin VB.CommandButton cmdDeleteKey 
  65.       Caption         =   "Delete Key"
  66.       Height          =   375
  67.       Left            =   5400
  68.       TabIndex        =   12
  69.       Top             =   480
  70.       Width           =   1815
  71.    End
  72.    Begin VB.CommandButton cmdCreateKey 
  73.       Caption         =   "Create Key"
  74.       Height          =   375
  75.       Left            =   5400
  76.       TabIndex        =   11
  77.       Top             =   120
  78.       Width           =   1815
  79.    End
  80.    Begin VB.TextBox txtItemValue 
  81.       Height          =   285
  82.       Left            =   1200
  83.       MultiLine       =   -1  'True
  84.       TabIndex        =   10
  85.       Text            =   "Form1.frx":0000
  86.       Top             =   3240
  87.       Width           =   3975
  88.    End
  89.    Begin VB.Frame Frame1 
  90.       Caption         =   "Data Type"
  91.       Height          =   1215
  92.       Left            =   1200
  93.       TabIndex        =   9
  94.       Top             =   1920
  95.       Width           =   3975
  96.       Begin VB.OptionButton optType 
  97.          Caption         =   "DWord MSB"
  98.          Height          =   255
  99.          Index           =   8
  100.          Left            =   2640
  101.          TabIndex        =   26
  102.          Top             =   800
  103.          Width           =   1215
  104.       End
  105.       Begin VB.OptionButton optType 
  106.          Caption         =   "DWord LSB"
  107.          Height          =   255
  108.          Index           =   7
  109.          Left            =   2640
  110.          TabIndex        =   25
  111.          Top             =   520
  112.          Width           =   1215
  113.       End
  114.       Begin VB.OptionButton optType 
  115.          Caption         =   "Link"
  116.          Height          =   255
  117.          Index           =   6
  118.          Left            =   2640
  119.          TabIndex        =   24
  120.          Top             =   240
  121.          Width           =   1215
  122.       End
  123.       Begin VB.OptionButton optType 
  124.          Caption         =   "Not Defined"
  125.          Height          =   255
  126.          Index           =   5
  127.          Left            =   1080
  128.          TabIndex        =   23
  129.          Top             =   800
  130.          Width           =   1455
  131.       End
  132.       Begin VB.OptionButton optType 
  133.          Caption         =   "Expand String"
  134.          Height          =   255
  135.          Index           =   4
  136.          Left            =   1080
  137.          TabIndex        =   22
  138.          Top             =   520
  139.          Width           =   1455
  140.       End
  141.       Begin VB.OptionButton optType 
  142.          Caption         =   "Multi-line String"
  143.          Height          =   255
  144.          Index           =   3
  145.          Left            =   1080
  146.          TabIndex        =   21
  147.          Top             =   240
  148.          Width           =   1455
  149.       End
  150.       Begin VB.OptionButton optType 
  151.          Caption         =   "Binary"
  152.          Height          =   255
  153.          Index           =   2
  154.          Left            =   120
  155.          TabIndex        =   20
  156.          Top             =   800
  157.          Width           =   975
  158.       End
  159.       Begin VB.OptionButton optType 
  160.          Caption         =   "DWord"
  161.          Height          =   255
  162.          Index           =   1
  163.          Left            =   120
  164.          TabIndex        =   19
  165.          Top             =   520
  166.          Width           =   975
  167.       End
  168.       Begin VB.OptionButton optType 
  169.          Caption         =   "String"
  170.          Height          =   255
  171.          Index           =   0
  172.          Left            =   120
  173.          TabIndex        =   18
  174.          Top             =   240
  175.          Value           =   -1  'True
  176.          Width           =   975
  177.       End
  178.    End
  179.    Begin VB.TextBox txtItemName 
  180.       Height          =   285
  181.       Left            =   1200
  182.       TabIndex        =   8
  183.       Top             =   1560
  184.       Width           =   3975
  185.    End
  186.    Begin VB.TextBox txtSubKey 
  187.       Height          =   285
  188.       Left            =   1200
  189.       TabIndex        =   7
  190.       Top             =   1080
  191.       Width           =   3975
  192.    End
  193.    Begin VB.TextBox txtKey 
  194.       Height          =   285
  195.       Left            =   1200
  196.       TabIndex        =   6
  197.       Text            =   "SOFTWARE\test"
  198.       Top             =   600
  199.       Width           =   3975
  200.    End
  201.    Begin VB.ComboBox cboRoot 
  202.       Height          =   315
  203.       Left            =   1200
  204.       TabIndex        =   5
  205.       Top             =   120
  206.       Width           =   3975
  207.    End
  208.    Begin RegistryControl.RegiCon RegiCon1 
  209.       Left            =   360
  210.       Top             =   2040
  211.       _ExtentX        =   847
  212.       _ExtentY        =   847
  213.    End
  214.    Begin VB.Label Label5 
  215.       Alignment       =   1  'Right Justify
  216.       Caption         =   "Value:"
  217.       Height          =   255
  218.       Left            =   360
  219.       TabIndex        =   4
  220.       Top             =   3240
  221.       Width           =   735
  222.    End
  223.    Begin VB.Label Label4 
  224.       Alignment       =   1  'Right Justify
  225.       Caption         =   "Item:"
  226.       Height          =   255
  227.       Left            =   120
  228.       TabIndex        =   3
  229.       Top             =   1560
  230.       Width           =   855
  231.    End
  232.    Begin VB.Label Label3 
  233.       Alignment       =   1  'Right Justify
  234.       Caption         =   "Sub-Key:"
  235.       Height          =   255
  236.       Left            =   120
  237.       TabIndex        =   2
  238.       Top             =   1080
  239.       Width           =   975
  240.    End
  241.    Begin VB.Label Label2 
  242.       Alignment       =   1  'Right Justify
  243.       Caption         =   "Key:"
  244.       Height          =   255
  245.       Left            =   240
  246.       TabIndex        =   1
  247.       Top             =   600
  248.       Width           =   855
  249.    End
  250.    Begin VB.Label Label1 
  251.       Alignment       =   1  'Right Justify
  252.       Caption         =   "Root-Key:"
  253.       Height          =   255
  254.       Left            =   120
  255.       TabIndex        =   0
  256.       Top             =   120
  257.       Width           =   975
  258.    End
  259. Attribute VB_Name = "Form1"
  260. Attribute VB_Creatable = False
  261. Attribute VB_Exposed = False
  262. Private Sub Command3_Click()
  263. End Sub
  264. Option Explicit
  265. Private Sub cmdCreateKey_Click()
  266.     If Trim$(txtKey.Text) = "" Then
  267.         MsgBox "Must specify a Key", vbInformation, "No Key"
  268.         Exit Sub
  269.     End If
  270.     '
  271.     'When you use the SetEntry method without
  272.     'specifying a KeyItemName, an empty key is created
  273.     'in the registry
  274.     RegiCon1.RootKey = cboRoot.ListIndex
  275.     RegiCon1.Key = txtKey.Text
  276.     RegiCon1.KeyItemName = ""
  277.     RegiCon1.SetEntry
  278. End Sub
  279. Private Sub cmdDeleteKey_Click()
  280.     If Trim$(txtKey.Text) = "" Then
  281.         MsgBox "Must specify a Key", vbInformation, "No Key"
  282.         Exit Sub
  283.     End If
  284.     If txtSubKey.Text = "" Then
  285.         MsgBox "You have chosen to delete a key directly off of a RootKey!" & vbCr & vbCrLf _
  286.             & "Although you can create keys directly off of HKEY_CLASSES_ROOT or HKEY_CURRENT_USER," & vbCrLf _
  287.             & "deleting a key from a root key is NOT normal and this sample will NOT delete this key!" & vbCr & vbCrLf _
  288.             & "Normally you should use the SubKey property to specify which portion of the multikey to delete (see the Help File)." & vbCr & vbCrLf _
  289.             , vbExclamation, "Delete Prevented By Sample!"
  290.         Exit Sub
  291.     Else
  292.         If MsgBox("Are you sure you want to delete the subkey '" & txtSubKey.Text & "' from the key '" & txtKey.Text & "'?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete Key") = vbNo Then
  293.             Exit Sub
  294.         End If
  295.     End If
  296.     '
  297.     'To delete a Key and any of its subkeys and items,
  298.     'set Key to the parent key of the subkey to delete;
  299.     'set the SubKey to the key that you want to delete;
  300.     '
  301.     'To delete an entire key, do NOT specify a KeyItemName, otherwise
  302.     'the control will only delete the item
  303.     RegiCon1.RootKey = cboRoot.ListIndex
  304.     RegiCon1.Key = txtKey.Text
  305.     RegiCon1.SubKey = txtSubKey.Text
  306.     RegiCon1.KeyItemName = ""
  307.     RegiCon1.DeleteEntry
  308.     txtSubKey.Text = ""
  309.     txtItemValue.Text = ""
  310. End Sub
  311. Private Sub cmdDeleteKeyItem_Click()
  312.     If Trim$(txtKey.Text) = "" Then
  313.         MsgBox "Must specify a Key", vbInformation, "No Key"
  314.         Exit Sub
  315.     ElseIf Trim$(txtItemName) = "" Then
  316.         MsgBox "Must specify an Item", vbInformation, "No Item"
  317.         Exit Sub
  318.     End If
  319.     If MsgBox("Are you sure you want to delete the item '" & txtItemName.Text & "'?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete Item") = vbNo Then
  320.         Exit Sub
  321.     End If
  322.     'to delete an item from a key, specify
  323.     'the key and set the KeyItemName to the item
  324.     'that you want to delete
  325.     RegiCon1.RootKey = cboRoot.ListIndex
  326.     RegiCon1.Key = txtKey.Text
  327.     RegiCon1.KeyItemName = txtItemName.Text
  328.     RegiCon1.DeleteEntry
  329.     txtItemName.Text = ""
  330.     txtItemValue.Text = ""
  331. End Sub
  332. Private Sub cmdExit_Click()
  333.     Unload Me
  334. End Sub
  335. Private Sub cmdGetKeyItem_Click()
  336.     Dim str As String
  337.     Dim i As Integer
  338.     txtItemValue.Text = ""
  339.     If Trim$(txtKey.Text) = "" Then
  340.         MsgBox "Must specify a Key", vbInformation, "No Key"
  341.         Exit Sub
  342.     ElseIf Trim$(txtItemName) = "" Then
  343.         MsgBox "Must specify an Item", vbInformation, "No Item"
  344.         Exit Sub
  345.     End If
  346.     '
  347.     'to retrieve an item, specify the
  348.     'Key and KeyItemName, then call the
  349.     'GetEntry method. The KeyItemType and
  350.     'KeyItemValue properties will contain the
  351.     'data type and value, respectively.
  352.     '
  353.     'If unable to open/locate the item, the type
  354.     'will be REG_NONE and the value will be null
  355.     RegiCon1.RootKey = cboRoot.ListIndex
  356.     RegiCon1.Key = txtKey.Text
  357.     RegiCon1.KeyItemName = txtItemName.Text
  358.     RegiCon1.GetEntry
  359.     str = "Value: " & CStr(RegiCon1.KeyItemValue) & vbCr & vbCrLf
  360.     i = RegiCon1.KeyItemType
  361.     Select Case i
  362.         Case dtREG_SZ
  363.             str = str & "Type: REG_SZ"
  364.             optType(0).Value = True
  365.         Case dtREG_DWORD
  366.             str = str & "Type: REG_DWORD"
  367.             optType(1).Value = True
  368.         Case dtREG_BINARY
  369.             str = str & "Type: REG_BINARY"
  370.             optType(2).Value = True
  371.         Case dtREG_MULTI_SZ
  372.             str = str & "Type: REG_MULTI_SZ"
  373.             optType(3).Value = True
  374.         Case dtREG_EXPAND_SZ
  375.             str = str & "Type: REG_EXPAND_SZ"
  376.             optType(4).Value = True
  377.         Case dtREG_NONE
  378.             str = str & "Type: REG_NONE"
  379.             optType(5).Value = True
  380.         Case dtREG_LINK
  381.             str = str & "Type: REG_LINK"
  382.             optType(6).Value = True
  383.         Case dtREG_DWORD_LITTLE_ENDIAN
  384.             'this will never happen because REG_DWORD_LITTLE_ENDIAN
  385.             'and DWord are the same thing.
  386.             str = str & "Type: REG_DWORD_LITTLE_ENDIAN"
  387.             optType(7).Value = True
  388.         Case dtREG_DWORD_BIG_ENDIAN
  389.             str = str & "Type: REG_DWORD_BIG_ENDIAN"
  390.             optType(8).Value = True
  391.         Case Else
  392.             'list is not implemented
  393.             str = str & "Type: Other (" & CStr(i) & ")"
  394.             optType(5).Value = True
  395.     End Select
  396.     txtItemValue.Text = CStr(RegiCon1.KeyItemValue)
  397.     MsgBox str
  398. End Sub
  399. Private Sub cmdIsItem_Click()
  400.     If Trim$(txtKey.Text) = "" Then
  401.         MsgBox "Must specify a Key", vbInformation, "No Key"
  402.         Exit Sub
  403.     ElseIf Trim$(txtItemName) = "" Then
  404.         MsgBox "Must specify an Item", vbInformation, "No Item"
  405.         Exit Sub
  406.     End If
  407.     RegiCon1.RootKey = cboRoot.ListIndex
  408.     RegiCon1.Key = txtKey.Text
  409.     RegiCon1.KeyItemName = txtItemName.Text
  410.         
  411.     If (RegiCon1.IsEntry) Then
  412.         MsgBox "This IS an Item:" & vbCr & vbCrLf & "Key = " & txtKey.Text & vbCrLf & "Item = " & txtItemName
  413.     Else
  414.         MsgBox "This IS NOT an Item:" & vbCr & vbCrLf & "Key = " & txtKey.Text & vbCrLf & "Item = " & txtItemName
  415.     End If
  416. End Sub
  417. Private Sub cmdIsKey_Click()
  418.     If Trim$(txtKey.Text) = "" Then
  419.         MsgBox "Must specify a Key", vbInformation, "No Key"
  420.         Exit Sub
  421.     End If
  422.         
  423.     RegiCon1.RootKey = cboRoot.ListIndex
  424.     RegiCon1.Key = txtKey.Text
  425.     RegiCon1.KeyItemName = ""
  426.         
  427.     If (RegiCon1.IsEntry) Then
  428.         MsgBox "This IS an entry:" & vbCr & vbCrLf & "Key = " & txtKey.Text
  429.     Else
  430.         MsgBox "This IS NOT an entry:" & vbCr & vbCrLf & "Key = " & txtKey.Text
  431.     End If
  432. End Sub
  433. Private Sub cmdSetKeyItem_Click()
  434.     '
  435.     'To set a key item, call the SetEntry
  436.     'method after specifying a Key, KeyItemName,
  437.     'KeyItemType and appropriate KeyItemValue
  438.     If Trim$(txtKey.Text) = "" Then
  439.         MsgBox "Must specify a Key", vbInformation, "No Key"
  440.         Exit Sub
  441.     ElseIf Trim$(txtItemName) = "" Then
  442.         MsgBox "Must specify an Item", vbInformation, "No Item"
  443.         Exit Sub
  444.     End If
  445.     RegiCon1.RootKey = cboRoot.ListIndex
  446.     RegiCon1.Key = txtKey.Text
  447.     RegiCon1.KeyItemName = txtItemName.Text
  448.     RegiCon1.KeyItemValue = txtItemValue.Text
  449.     RegiCon1.SetEntry
  450. End Sub
  451. Private Sub Form_Load()
  452.     Dim TempString As String
  453.     cboRoot.AddItem "HKEY_LOCAL_MACHINE", 0
  454.     cboRoot.AddItem "HKEY_CURRENT_USER", 1
  455.     cboRoot.AddItem "HKEY_CURRENT_CONFIG", 2
  456.     cboRoot.AddItem "HKEY_USERS", 3
  457.     cboRoot.AddItem "HKEY_CLASSES_ROOT", 4
  458.     cboRoot.AddItem "HKEY_DYN_DATA", 5
  459.     cboRoot.ListIndex = 0
  460.     RegiCon1.KeyItemType = 0
  461.     Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  462.     TempString = "The following sample demonstrates the Mabry RegiCon OCX." & vbCr & vbCrLf & _
  463.                 "When using this sample, you have direct access to your system registry " & _
  464.                 "and you can add, delete, and change the contents of your current registry settings. " & vbCr & vbCrLf & _
  465.                 "You are STRONGLY encouraged to use this sample application " & _
  466.                 "to create some TEST keys and items, then edit and delete the test entries." & vbCr & vbCrLf & _
  467.                 "Further, a thorough understanding of the how the Key and SubKey properties work together to delete " & _
  468.                 "keys is highly recommended."
  469.                 
  470.     MsgBox TempString, vbInformation, "READ ME!"
  471. End Sub
  472. Private Sub optType_Click(Index As Integer)
  473.     Static i As Integer
  474.     If i = Index Then
  475.         Exit Sub
  476.     End If
  477.     If Index = 2 Or Index = 3 Then
  478.         txtItemValue.Height = 885
  479.     Else
  480.         txtItemValue.Height = 285
  481.     End If
  482.     RegiCon1.KeyItemType = Index
  483.     i = Index
  484.     txtItemValue.Text = ""
  485. End Sub
  486.