#174209 - 2007-02-23 11:44 PM
Re: KiXforms.Net Learning Series - Windows Registry Run Project 01 - Lesson 03
[Re: Gargoyle]
|
Gargoyle
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
If Not @LogonMode Break On EndIf
;Declare Variables that will be used throughout Global $SO, $Nul
;Set Code Options to On
$SO=SetOption("NoMacrosInStrings", "ON") $SO=SetOption("NoVarsInStrings", "ON") $SO=SetOption("Explicit", "ON") $SO=SetOption("WrapAtEOL", "ON")
;Declare Variables for the form
DIM $MainMenu,$MenuItem1,$MenuItem2 DIM $Button_Text,$Button_Top[],$Lbl_Info DIM $Splitter DIM $Button_Click[],$ControlStackImageList
Global $System,$Form_Main,$ListView1,$ListView2,$Cmb_RegEntry,$Button[5],$Panel_ControlStack Global $Panel_MainChild,$Panel_ChildInMainChild,$ListView2Column[1],$ListView1Column[1] Global $ListView1Item[],$ListView2Item[]
;Array build information $Button_Text = "Exit","Delete","Refresh","Restore","Backup","Save" $Button_Top = 120,96,72,48,24,0 $Button_Click = "IWantOut()","Delete()","ListViewChange($CMB_RegEntry.SelectedIndex)", "Restore($CMB_RegEntry.SelectedIndex)","Backup($CMB_RegEntry.SelectedIndex)","Save($CMB_RegEntry.SelectedIndex)"
;Check for existence of KiXForms $System = CreateObject("Kixforms.System") If Not $System $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16) Quit() EndIf $nul = $System.Application.EnableVisualStyles
;Build the Form $Form_Main = $System.Form() $Form_Main.StartPosition = 1 $Form_Main.Size = $System.Size(600,400) $Form_Main.Text = "Project1 - Lesson 1" $Form_Main.SizeChanged = "Resize()" $Form_Main.Icon = $System.Icon.FromBase64String(FormImage())
;Build the menu bar $MainMenu = $System.MainMenu()
$MenuItem1 = $MainMenu.MenuItems.Add($System.MenuItem("File"))
$MenuItem2 = $MenuItem1.MenuItems.Add($System.MenuItem("Exit")) $MenuItem2.Click = "IWantOut()"
$Form_Main.Menu = $MainMenu
;Add Two Panels that will allow for splitting $Panel_MainChild = $System.Panel() $Panel_MainChild.Borderstyle = 1 $Panel_MainChild.Dock = 5 $Nul = $Form_Main.Controls.Add($Panel_MainChild)
;Now we can add the top Listview $ListView1 = $System.ListView() $ListView1.Dock = 5 $ListView1.GridLines = -1 ;True $ListView1.Checkboxes = -1 ;True $ListView1.View = $System.View_Details $nul = $Panel_MainChild.Controls.Add($ListView1)
;Add the ComboBox $CMB_RegEntry = $System.ComboBox() ;$CMB_RegEntry.DropDownWidth = 512 $CMB_RegEntry.IntegralHeight = 0 $CMB_RegEntry.ItemHeight = 13 $CMB_RegEntry.Dock = 1 $CMB_RegEntry.SelectedIndexChanged = "ListViewChange($CMB_RegEntry.SelectedIndex)" $nul = $Panel_MainChild.Controls.Add($CMB_RegEntry)
;Add in the Splitter $Splitter = $System.Splitter() $Splitter.Dock = 2 $Splitter.Height = 3 $nul = $Panel_MainChild.Controls.Add($Splitter)
;Add the secondary panel to the one just created $Panel_ChildinMainChild = $System.Panel() $Panel_ChildinMainChild.Borderstyle = 1 $Panel_ChildinMainChild.Dock = 2 $Nul = $Panel_MainChild.Controls.Add($Panel_ChildinMainChild)
;Insert the Bottom Listview $ListView2 = $System.ListView() $ListView2.GridLines = -1 ;True $ListView2.View = $System.View_Details $ListView2.Dock = 5 $nul = $Panel_ChildInMainChild.Controls.Add($ListView2)
;Add the Label $Lbl_Info = $System.Label() $Lbl_Info.BorderStyle = 1 $Lbl_Info.Dock = 1 $Lbl_Info.Text = "Entries to Delete" $Lbl_Info.TextAlign = 32 $nul = $Panel_ChildInMainChild.Controls.Add($Lbl_Info)
;Set up Column headers for ListViews $ListView2Column[0] = $ListView2.Columns.Add($System.ColumnHeader("Entry",100,$System.HorizontalAlignment_Left)) $ListView2Column[1] = $ListView2.Columns.Add($System.ColumnHeader("Value",100,$System.HorizontalAlignment_Center)) $ListView1Column[0] = $ListView1.Columns.Add($System.ColumnHeader("Entry",100,$System.HorizontalAlignment_Left)) $ListView1Column[1] = $ListView1.Columns.Add($System.ColumnHeader("Value",100,$System.HorizontalAlignment_Center))
;Add Control Stack containing panel $Panel_ControlStack = $System.Panel() $Panel_ControlStack.Borderstyle = 1 $Panel_ControlStack.Dock = 3 $Nul = $Panel_MainChild.Controls.Add($Panel_ControlStack)
;Build the ImageList for the ControlStack $ControlStackImageList = $System.Imagelist() $ControlStackImageList.ImageSize = $System.Size(16,16) $Nul = $ControlStackImageList.Images.AddStrip($System.Bitmap.FromBase64String(ControlStackImageList()))
;Build the Buttons for the Control Stack ;Buttons are built from the bottom up ;See definition of Button_Text[] Array for clarification For $SO = 0 to Ubound($Button) $Button[$SO] = $System.Button() $Button[$SO].Left = 0 $Button[$SO].TextAlign = 64 $Button[$SO].Top = $Button_Top[$SO] $Button[$SO].Text = $Button_Text[$SO] $Button[$SO].Click = $Button_Click[$SO] $Button[$SO].ImageList = $ControlStackImageList $Button[$SO].ImageAlign = 16 $Button[$SO].ImageIndex = $SO $Nul = $Panel_ControlStack.Controls.Add($Button[$SO]) Next
;Set the widths of everything to match the form $Panel_ControlStack.Width = 79 Resize() CMB_Fill() ; Unsure why we are using a function for this, but may assume it will ; be because of future development $CMB_RegEntry.SelectedIndex = 0 ; So that the combobox does not appear to be empty upon launch
$Form_Main.Show ;Displays the Form
While $Form_Main.Visible $Nul = Execute($Form_Main.DoEvents()) Loop Exit 0
;================================================================================================ ; Functions ;================================================================================================ Function Resize() DIM $Width If $Form_Main.Width => 600 $Width = $Form_Main.Width - 86 Else $Form_Main.Width = 600 EndIf If $Form_Main.Height < 400 $Form_Main.Height = 400 EndIf
EndFunction
;=====================================
Function IWantOut() Quit @ERROR EndFunction
;=====================================
Function CMB_Fill() Global $RegKey[1] $RegKey[0] = $CMB_RegEntry.Items.Add("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\") $RegKey[1] = $CMB_RegEntry.Items.Add("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\") EndFunction
;=====================================
Function ListViewChange($Index) DIM $Values,$Count,$Count2
;Clear out the listViews $ListView1.items.clear $Listview2.items.clear ;Build and array with all of the Key Values under the selected RegKey $Values = Arrayenumvalue($RegKey[$Index])
;Setup counters for the filling of items $Count = 0 ; Item Counter to build the Array of items contained within the listview $Count2 = 0 ; Row Counter so as to build the subitems in the listview
;Loop through the Key Values array and add to the ListView For Each $SO In $Values ReDIM Preserve $ListView1Item[$Count+1] ;Add the Key to the first column in the Listview $ListView1Item[$count] = $ListView1.items.Add($system.listviewitem($SO)) ;Add the Values of the specified key to the subitems list ;Increment the $Count by 1 so that it can be referenced as an individual item $ListView1Item[$count+1] = $Listview1.items.item($Count2).SubItems.Add($System.ListViewSubItem(ReadValue($RegKey[$Index],$SO))) $Count = $Count+10 $Count2 = $Count2+1 Next ;Disable the Save Button $Button[5].Enabled = 0 $Button[4].Enabled = -1 $Button[3].Enabled = -1 EndFunction
;=====================================
Function Delete() DIM $Item,$count
$count = 0 ;See what items are checked...
For $Item = 0 to Ubound($Listview1Item) If $Listview1Item[$Item].Checked = -1 Redim Preserve $Listview2Item[$item+1] $ListView2Item[$Item] = $Listview2.items.add($system.listviewitem($listview1item[$Item].text)) $Listview2item[$item+1] = $listview2.items.item($count).Subitems.add($system.listviewsubitem($listview1item[$item+1].text)) $Listview1item[$item].remove $count = $count+1 Endif $Item = $Item + 9 Next If $ListView2.items.count > 0 $Button[3].Enabled = 0 $Button[4].Enabled = 0 $Button[5].Enabled = -1 EndIf
EndFunction ;=====================================
Function SAVE($Index) Dim $Key
For $SO = 0 to $ListView2.Items.Count $Key = $Listview2.Items.Item($SO).Text $Nul = DelValue($RegKey[$index],$Key) Next
ListViewChange($Index)
EndFunction
;===================================== ;Courtesy Sealeopard UDF Function arrayenumvalue($regsubkey) DIM $retcode, $valuecounter, $currentvalue, $valuearray
If not KeyExist($regsubkey) Exit 87 EndIf
$valuecounter=0 Do $currentvalue=EnumValue($regsubkey,$valuecounter) If not @ERROR ReDIM preserve $valuearray[$valuecounter] $valuearray[$valuecounter]=$currentvalue $valuecounter=$valuecounter+1 EndIf Until @ERROR
$arrayenumvalue=$valuearray Exit 0 EndFunction
;===================================== Function Backup($Index) ;Backup all entries in the top ListView to the repective "RunBackup" key DIM $Key,$Value For $SO = 1 To $ListView1.Items.Count ;Retrieve the Key Value from the ListView $Key = $Listview1.Items.Item($SO).text ;Retrieve the value from the Subitems of the ListView $Value = $ListView1.Items.Item($SO).subItems.Item(1).text ;I tried putting the $Key and $Value directly in the WriteValue, but it ;continually gave me invaled method / function call
$Nul = WriteValue($RegKey[$index]+"RunBackup",$Key,$Value,REG_SZ) Next
ListViewChange($Index)
EndFunction
;===================================== Function Restore($Index) ;Restore all entries from the "RunBackup" Key to the Selected Key DIM $Key, $Value For Each $Key In ArrayEnumvalue($RegKey[$Index]+"Runbackup") $Value = ReadValue($RegKey[$Index]+"RunBackup",$Key) $Nul = WriteValue($RegKey[$Index],$Key,$Value,REG_SZ) Next ListViewChange($Index) EndFunction
;=====================================
;================================================================================================ ; Image Strings ;================================================================================================ Function ControlStackImageList() $ControlStackImageList = " iVBORw0KGgoAAAANSUhEUgAAAGAAAAAQCAYAAADpunr5AAAACXBIWXMAAA7DAAAO wwHHb6hkAAAGmElEQVR4nO2YW2wU5xmGv5vcRFGVq14lUitVucAkWTxSaKOgWKIH kcgVAdGGQhungRVNIpTWmKQgYqMSWpI0NJUWexrAFBI7DjQGLT4sxudl7bWXGIxh fWBNfdj1OevYpix22KcX49md3Z2xHUBqVfWTXmk08//fq/99//m+f0bk//HfEX+p HOWPJdcXxf6iLv4X+f/j8YFzkGg0ilnc/hqmbmvI+8cgfyhsTxDhTroQVYQ76XLX 4twLf0IoKt/6UREPPHMMUVTzcYpq/cxqrBFJkbPfRUZGEdPT04vC5Wpn48ZaMjOT 8vz5dB9zc3Omi4/MQfiWhk2V8JsTfbyd3xJL8HW6YMSSFpYU98JvFOpXJ6f4eTk8 VgQPHhg3F23lEWR1Sfy+ovLtzFOp4xQVefYTZIsXyQsir7cjK4+kjPsmBpw7d8Xc gHc/6yYSicQWHo1qi/8qoi18eFrD34pDfHg0SHbO8YQE/1ohGGEm8ly6cEfR3pbk Z2b8XeEbrDqTwTNnMuicCCOqWPJ/b2st68rg0QMhHvyZC1nvQrZ3IO+MIrmDCWJL phOx+xLurT4ND73gjOf84WfavNxBZGePlm9DlTbvFW+CCd/EgKqqq+YGHCj2c/Pm zZgAkTm4NauJPzID/ZPQF4aaGigthd/u+HuKiDdXCDPzmLYlihxZIcymC3MWb0gy /0f+QkSVGB75+DuIKub8isrTx6ZI+5TUcrGjC8npQV6oiN8zMeC7H8MDP3XGTcoL athQhXz/aHzuK97EuUkGeL1e6urqqK+vp6GhAbfbjdvtxuPx0N7ezvnzFgbsP9bG 1NQU0agmPopwe0+WtvMvtjH1+yy6x6F9GHxB2P7GEVMhwzbBiCmbZsa0TZixWZen ZH5RhZymPLxDN/jJ2bUxI0z5FRVRQQqiqfl14ey+uHAmBohjDnnuNLK2XBN+2xda uUmOlUe0uYYSZjSgpaWF+vp6GhsbcbvdXLhwAY/HQ1NTEx0dHVRX+80NeOdwK+Fw mMgcRPpvgCKgCMMX27jz7MOgCCH1IL4gtA7C69s/shTzS5swMY+wTZi0CV8tIH4y v3e4jbpgGyMz0DEWZlmJLWaAKb8u4Acz1k13vU
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
Moderator: NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen
|
0 registered
and 452 anonymous users online.
|
|
|