找回密码
 加入
搜索
查看: 8930|回复: 11

[系统综合] 读注册表,用TreeView,无法获取子项ID,怎么办?

  [复制链接]
发表于 2011-12-14 22:55:45 | 显示全部楼层 |阅读模式
本帖最后由 hlzxcjx 于 2011-12-15 21:03 编辑
#include <GUIConstants.au3>
#Include <GuiTreeView.au3>
$AForm1 = GUICreate("AForm1", 801, 601, 174, 66)
$TreeView1 = GUICtrlCreateTreeView(16, 16, 289, 569)
$mycomputer = GUICtrlCreateTreeViewItem("我的电脑", $TreeView1)
$root = GUICtrlCreateTreeViewItem("HKEY_CLASSES_ROOT", $mycomputer)
$user = GUICtrlCreateTreeViewItem("HKEY_CURRENT_USER", $mycomputer)
$MACHINE = GUICtrlCreateTreeViewItem("HKEY_LOCAL_MACHINE", $mycomputer)
$USERS = GUICtrlCreateTreeViewItem("HKEY_USERS", $mycomputer)
$CONFIG = GUICtrlCreateTreeViewItem("HKEY_CURRENT_CONFIG", $mycomputer)
$ListView1 = GUICtrlCreateListView("", 320, 16, 466, 570)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $MACHINE
                        $regpath = StringTrimLeft(_GUICtrlTreeViewGetTree($TreeView1, ""), 9)
                        $i=1
                        While 1
                                $var = RegEnumKey($regpath, $i)
                                If @error <> 0 Then ExitLoop
                                GUICtrlCreateTreeViewItem($var, $MACHINE)
                                $i=$i+1
                        WEnd
        EndSwitch
WEnd


如图,如何使子项建立在象HARDWARE这样的分支中?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-12-14 23:35:35 | 显示全部楼层
本帖最后由 lixiaolong 于 2011-12-14 23:37 编辑

回复 1# hlzxcjx


Case $MACHINE 下写这些每次点击“HKEY_LOCAL_MACHINE”都会添加的.
                        While 1
                                $var = RegEnumKey($regpath, $i)
                                If @error <> 0 Then ExitLoop
                                GUICtrlCreateTreeViewItem($var, $MACHINE)
                                $i=$i+1
                        WEnd



#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>

$HKCR = "HKEY_CLASSES_ROOT"
$HKCU = "HKEY_CURRENT_USER"
$HKLM = "HKEY_LOCAL_MACHINE"
$HKU = "HKEY_USERS"
$HKCC = "HKEY_CURRENT_CONFIG"

$AForm1 = GUICreate("AForm1", 801, 601, 174, 66)
$TreeView1 = GUICtrlCreateTreeView(16, 16, 289, 569)
$mycomputer = GUICtrlCreateTreeViewItem("我的电脑", $TreeView1)
$root = GUICtrlCreateTreeViewItem($HKCR, $mycomputer)
$user = GUICtrlCreateTreeViewItem($HKCU, $mycomputer)
$MACHINE = GUICtrlCreateTreeViewItem($HKLM, $mycomputer)
$USERS = GUICtrlCreateTreeViewItem($HKU, $mycomputer)
$CONFIG = GUICtrlCreateTreeViewItem($HKCC, $mycomputer)
$ListView1 = GUICtrlCreateListView("", 320, 16, 466, 570)

For $i = 1 To 100
        $var = RegEnumKey($HKLM, $i)
        If @error <> 0 Then ExitLoop
        GUICtrlCreateTreeViewItem($var, $MACHINE)
Next

GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
 楼主| 发表于 2011-12-15 07:20:14 | 显示全部楼层
本帖最后由 hlzxcjx 于 2011-12-15 07:23 编辑

回复 2# lixiaolong

谢谢,我的只是初稿。我的问题是想解决点击每个子项时注册表分支建立在子项下,但无法获取子项的ID,帮助中只有获取父项ID的。
 楼主| 发表于 2011-12-15 16:44:29 | 显示全部楼层
难道要用ini记录每个子项的ID?
发表于 2011-12-15 17:50:08 | 显示全部楼层
回复 4# hlzxcjx

不用ini也可以吧,等我吃完饭,别太期待哦~
 楼主| 发表于 2011-12-15 19:07:17 | 显示全部楼层
回复 5# lixiaolong


    期待中。。。
发表于 2011-12-15 20:09:16 | 显示全部楼层
回复 6# hlzxcjx

这样就不用INI了,我能力有限,我就给你这个代码,自己研究吧
#include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>

Global $hKey, $Count, $hklm_sub[100]
$AForm1 = GUICreate("AForm1", 801, 601, 174, 66)
$TreeView1 = GUICtrlCreateTreeView(16, 16, 289, 569)
$mycomputer = GUICtrlCreateTreeViewItem("我的电脑", $TreeView1)
$root = GUICtrlCreateTreeViewItem("HKEY_CLASSES_ROOT", $mycomputer)
$user = GUICtrlCreateTreeViewItem("HKEY_CURRENT_USER", $mycomputer)
$MACHINE = GUICtrlCreateTreeViewItem("HKEY_LOCAL_MACHINE", $mycomputer)
$USERS = GUICtrlCreateTreeViewItem("HKEY_USERS", $mycomputer)
$CONFIG = GUICtrlCreateTreeViewItem("HKEY_CURRENT_CONFIG", $mycomputer)
$ListView1 = GUICtrlCreateListView("", 320, 16, 466, 570)

$hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE)
$Count = _WinAPI_RegQueryInfoKey($hKey)
Local $aKey[$Count[0]]
For $i = 0 To UBound($aKey) - 1
        $aKey[$i] = _WinAPI_RegEnumKey($hKey, $i)
        $hklm_sub[$i] = GUICtrlCreateTreeViewItem($aKey[$i], $MACHINE)
Next
_WinAPI_RegCloseKey($hKey)

GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $hklm_sub[0] To UBound($hklm_sub) - 1
                        $selection = _GUICtrlTreeView_GetSelection($TreeView1)
                        $__text = _GUICtrlTreeView_GetText($TreeView1, $selection)
                        MsgBox(0, 0, $__text)
        EndSwitch
WEnd
 楼主| 发表于 2011-12-15 21:02:00 | 显示全部楼层
本帖最后由 hlzxcjx 于 2011-12-15 21:04 编辑

回复 7# lixiaolong


    谢谢!是用数组吧?这样好像对读取部分是可以,但若读取整个注册似乎有点麻烦。
发表于 2011-12-15 21:39:20 | 显示全部楼层
本帖最后由 lixiaolong 于 2011-12-15 21:41 编辑

回复 8# hlzxcjx

是有点麻烦,看看这个这么样.
参考了这里,http://www.autoitscript.com/foru ... ui-registry-editor/

#NoTrayIcon
#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
$header = "AutoIT Registry Editor"
Global $treeview1, $sresult, $reg_new, $typedisp, $regkey, $regui, $regsearch, $reg_search, $chb_key, $chb_name, $chb_value, $reg_new_name, $reg_new_type, $reg_new_value, $btn_reg_search, $btn_reg_cancel, $reg_new_pre_name, $reg_new_pre_type, $reg_new_pre_value, $reg_new_pre_key, $regfresh, $Msg
Global $regstop = 0
Global $searchgui = 0
Global $onemsg = 0
Global $twomsg = 0
Global $which = 1
Global $_xHashCollection = ObjCreate("Scripting.Dictionary"), $_xHashCache

Opt("GUICoordMode", 1)
Opt("ExpandVarStrings", 1)

$guiwidth = 640
$guiheight = 480
$mygui = GUICreate($header, $guiwidth, $guiheight, -1, -1, $WS_CAPTION + $WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $mygui)
$btn_quit = GUICtrlCreateButton("Quit", $guiwidth - 110, $guiheight - 35, 100, 30)
GUICtrlSetOnEvent($btn_quit, "quit")

GUICtrlCreateGroup("", 10, 10, $guiwidth / 3, $guiheight - 134)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $treeview1 = GUICtrlCreateTreeView(11, 18, $guiwidth / 3 - 2, $guiheight - 145)
$context_regtree = GUICtrlCreateContextMenu($treeview1)
$regnewkey = GUICtrlCreateMenuItem("New key", $context_regtree)
$regnewvalue = GUICtrlCreateMenuItem("New name", $context_regtree)
$regdelete = GUICtrlCreateMenuItem("Delete", $context_regtree)
$regsearch = GUICtrlCreateMenuItem("Search...", $context_regtree)
Global $ListView1 = GUICtrlCreateListView("Name|Type|Value", $guiwidth / 3 + 20, 16, ($guiwidth / 3) * 2 - 30, $guiheight - 140, $LVS_NOSORTHEADER)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 2, 100)
Global $keypath[5]
$keypath[0] = "HKEY_CLASSES_ROOT"
$keypath[1] = "HKEY_CURRENT_USER"
$keypath[2] = "HKEY_LOCAL_MACHINE"
$keypath[3] = "HKEY_USERS"
$keypath[4] = "HKEY_CURRENT_CONFIG"

Dim $hkcount = 1, $tvcount = 1
For $i = 0 To 4
        Assign("main" & $tvcount, GUICtrlCreateTreeViewItem($keypath[$i], $treeview1))
        x("reg." & Eval("main" & $tvcount) & ".name", $keypath[$i])
        x("reg." & Eval("main" & $tvcount) & ".path", $keypath[$i])
        x("reg." & Eval("main" & $tvcount) & ".variable", "main" & $tvcount)
        $tvcount = $tvcount + 1
Next

Global $Keylabel = GUICtrlCreateLabel("Key:", 10, $guiheight - 88)
Global $reg_new_key = GUICtrlCreateInput("", 45, $guiheight - 90, $guiwidth / 3 - 35, 17)
Global $vallabel = GUICtrlCreateLabel("Name:", 10, $guiheight - 56, 50, 17)
Global $reg_new_name = GUICtrlCreateInput("", 65, $guiheight - 58, $guiwidth / 3 - 55, 17)
Global $datlabel = GUICtrlCreateLabel("Value:", $guiwidth / 3 + 20, $guiheight - 88, 50, 17)
Global $reg_new_value = GUICtrlCreateInput("", ($guiwidth / 3) + 54, $guiheight - 90, 235, 17)
GUICtrlCreateLabel("Type:", $guiwidth / 3 + 20, $guiheight - 56, 50, 17)
$reg_new_type = GUICtrlCreateCombo("REG_NONE", $guiwidth / 3 + 55, $guiheight - 62, 235, 17, $CBS_DROPDOWN + $CBS_AUTOHSCROLL + $WS_VSCROLL + $CBS_UPPERCASE + $CBS_SIMPLE)
GUICtrlSetData($reg_new_type, "REG_SZ|REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST", "REG_NONE")
$btn_reg_delete = GUICtrlCreateButton("Delete", $guiwidth - 110, $guiheight - 105, 100, 30)
$btn_reg_write = GUICtrlCreateButton("Modify/Create", $guiwidth - 110, $guiheight - 70, 100, 30)

GUISetState(@SW_SHOW)
$handle = WinGetHandle($header)

While 1
        $Msg = GUIGetMsg()
        Select
                Case $Msg = $GUI_EVENT_CLOSE
                        Exit
                Case 0
                        ; nothing is happening, so do nothing
                        ;Case $Msg < 1
                        ; Don't want to do anything with System Messages.
                Case $Msg = $btn_quit
                        quit()
                Case $Msg = $regnewkey
                        reg_pre_newkey()
                Case $Msg = $regnewvalue
                        reg_pre_newvalue()
                Case $Msg = $regsearch
                        reg_pre_search()
                Case $Msg = $regdelete
                        reg_delete()
                Case $Msg = $btn_reg_delete
                        reg_name_delete()
                Case $Msg = $btn_reg_write
                        reg_newvalue()
                Case $Msg > 12 ; this case must be the last in the select/switch structure! This number must be changed depending on how many controls did you create
                        $regfresh = $Msg
                        Treeview1($Msg)
                        msgstore($Msg)
        EndSelect
WEnd

Func reg_pre_search()
        Opt("GUIOnEventMode", 1)
        $regui = GUICreate($header & " - Search", 480, 320, -1, -1, "", "", $handle)
        GUICtrlCreateLabel("Search for:", 10, 12)
        $reg_search = GUICtrlCreateInput("", 70, 12, 150, 17)
        GUICtrlCreateGroup("Search type", 10, 40, 170, 90)
        $chb_key = GUICtrlCreateCheckbox("Key", 20, 60)
        GUICtrlSetState($chb_key, $GUI_CHECKED)
        $chb_name = GUICtrlCreateCheckbox("Name", 20, 80)
        GUICtrlSetState($chb_name, $GUI_CHECKED)
        $chb_value = GUICtrlCreateCheckbox("Value", 20, 100)
        GUICtrlSetState($chb_value, $GUI_CHECKED)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $btn_reg_search = GUICtrlCreateButton("Search", 365, 10, 100, 30, $BS_DEFPUSHBUTTON)
        $btn_reg_cancel = GUICtrlCreateButton("Cancel", 365, 45, 100, 30)
        GUICtrlSetOnEvent($btn_reg_search, "reg_search")
        GUICtrlSetOnEvent($btn_reg_cancel, "regcancel")
        GUICtrlCreateLabel("Searching under:", 10, 140, 100, 17)
        $reg_new_key = GUICtrlCreateEdit($regkey, 10, 160, 455, 20, $ES_READONLY + $ES_AUTOHSCROLL)
        $sresult = GUICtrlCreateEdit("", 10, 185, 455, 100, $WS_HSCROLL + $WS_VSCROLL)
        GUISetState(@SW_SHOW, $regui)
EndFunc   ;==>reg_pre_search

Func reg_search()
        HotKeySet("{ESC}", "regstop")
        $regstop = 0
        GUICtrlSetState($btn_reg_search, $GUI_DISABLE)
        GUICtrlSetState($btn_reg_cancel, $GUI_DISABLE)
        GUICtrlSetState($reg_search, $GUI_DISABLE)
        GUICtrlSetState($chb_key, $GUI_DISABLE)
        GUICtrlSetState($chb_name, $GUI_DISABLE)
        GUICtrlSetState($chb_value, $GUI_DISABLE)
        GUICtrlSetData($btn_reg_search, "Stop: ESC")
        $regsearching = GUICtrlRead($reg_search)
        If $regsearching = "" Then
                GUISetCursor()
                MsgBox(16, $header, "ERROR - no data entered", "", $handle)
        Else
                $result = ""
                GUISetCursor(1, 1)
                $whattosearch = 0
                If BitAND(GUICtrlRead($chb_key), $GUI_CHECKED) = $GUI_CHECKED Then
                        $whattosearch += 1
                EndIf
                If BitAND(GUICtrlRead($chb_name), $GUI_CHECKED) = $GUI_CHECKED Then
                        $whattosearch += 2
                EndIf
                If BitAND(GUICtrlRead($chb_value), $GUI_CHECKED) = $GUI_CHECKED Then
                        $whattosearch += 4
                EndIf
                $result = _RegSearch($regkey, $regsearching, $whattosearch)
                If $result = "" Then
                        GUICtrlSetData($sresult, "No match")
                        GUISetCursor()
                Else
                        GUICtrlSetData($sresult, "Searching finished, here are the results:" & @CRLF & @CRLF & $result)
                        GUISetCursor()
                EndIf
        EndIf
        HotKeySet("{ESC}")
        GUICtrlSetData($btn_reg_search, "Search")
        GUICtrlSetState($btn_reg_search, $GUI_ENABLE)
        GUICtrlSetState($btn_reg_cancel, $GUI_ENABLE)
        GUICtrlSetState($reg_search, $GUI_ENABLE)
        GUICtrlSetState($chb_key, $GUI_ENABLE)
        GUICtrlSetState($chb_name, $GUI_ENABLE)
        GUICtrlSetState($chb_value, $GUI_ENABLE)
EndFunc   ;==>reg_search

Func reg_pre_newkey()
        Select
                Case $regkey = ""
                        MsgBox(16, "ERROR", "You cannot create a new rootkey!")
                Case $regkey = "HKEY_LOCAL_MACHINE" Or $regkey = "HKEY_USERS"
                        MsgBox(16, "ERROR", "You cannot create a new key directly under " & $regkey)
                Case Else
                        Opt("GUIOnEventMode", 1)
                        $regui = GUICreate("New key", 360, 160, -1, -1, "", "", $handle)
                        GUICtrlCreateLabel("Creating key under this key:", 10, 10, 220, 18)
                        GUICtrlCreateEdit($regkey, 10, 30, 335, 20, $ES_READONLY + $ES_AUTOHSCROLL)
                        $reg_new = GUICtrlCreateInput("", 10, 62, 220, 17)
                        $btn_reg_new = GUICtrlCreateButton("OK", 245, 60, 100, 30, $BS_DEFPUSHBUTTON)
                        GUICtrlSetOnEvent($btn_reg_new, "reg_newkey")
                        $btn_reg_cancel = GUICtrlCreateButton("Cancel", 245, 95, 100, 30)
                        GUICtrlSetOnEvent($btn_reg_cancel, "regcancel")
                        GUISetState(@SW_SHOW, $regui)
        EndSelect
EndFunc   ;==>reg_pre_newkey

Func reg_newkey()
        $reguj = GUICtrlRead($reg_new)
        RegWrite($regkey & "\" & $reguj)
        GUIDelete($regui)
        Opt("GUIOnEventMode", 0)
        Treeview1($regfresh)
EndFunc   ;==>reg_newkey

Func reg_pre_newvalue()
        Opt("GUIOnEventMode", 1)
        $regui = GUICreate("New name", 370, 230, -1, -1, "", "", $handle)
        GUICtrlCreateLabel("Creating name under this key:", 10, 10, 220, 17)
        $reg_new_pre_key = GUICtrlCreateEdit($regkey, 10, 30, 345, 20, $ES_READONLY + $ES_AUTOHSCROLL)
        GUICtrlCreateLabel("Name:", 10, 60, 50, 18)
        $reg_new_pre_name = GUICtrlCreateInput("", 10, 80, 235, 17)
        GUICtrlCreateLabel("Type:", 10, 105, 50, 17)
        $reg_new_pre_type = GUICtrlCreateCombo("REG_NONE", 10, 122, 235, 17, $CBS_DROPDOWN + $CBS_AUTOHSCROLL + $WS_VSCROLL + $CBS_UPPERCASE + $CBS_SIMPLE)
        GUICtrlSetData($reg_new_pre_type, "REG_SZ|REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST", "REG_NONE")
        GUICtrlCreateLabel("Value:", 10, 152, 50, 18)
        $reg_new_pre_value = GUICtrlCreateInput("", 10, 172, 235, 17)
        $btn_reg_new = GUICtrlCreateButton("OK", 255, 130, 100, 30, $BS_DEFPUSHBUTTON)
        GUICtrlSetOnEvent($btn_reg_new, "reg_new_prevalue")
        $btn_reg_cancel = GUICtrlCreateButton("Cancel", 255, 165, 100, 30)
        GUICtrlSetOnEvent($btn_reg_cancel, "regcancel")
        GUISetState(@SW_SHOW, $regui)
        $searchgui = 1
EndFunc   ;==>reg_pre_newvalue

Func reg_new_prevalue()
        $regnewname = GUICtrlRead($reg_new_pre_name)
        $regnewtype = GUICtrlRead($reg_new_pre_type)
        $regnewvalue = GUICtrlRead($reg_new_pre_value)
        $regkey = GUICtrlRead($reg_new_pre_key)
        RegWrite($regkey, $regnewname, $regnewtype, $regnewvalue)
        If $searchgui = 1 Then
                GUIDelete($regui)
                WinActivate($mygui)
        EndIf
        Treeview1($regfresh)
        Opt("GUIOnEventMode", 0)
EndFunc   ;==>reg_new_prevalue

Func reg_newvalue()
        $regnewname = GUICtrlRead($reg_new_name)
        $regnewtype = GUICtrlRead($reg_new_type)
        $regnewvalue = GUICtrlRead($reg_new_value)
        $regkey = GUICtrlRead($reg_new_key)
        RegWrite($regkey, $regnewname, $regnewtype, $regnewvalue)
        If $searchgui = 1 Then
                GUIDelete($regui)
                WinActivate($mygui)
        EndIf
        Treeview1($regfresh)
        Opt("GUIOnEventMode", 0)
EndFunc   ;==>reg_newvalue

Func reg_delete()
        Select
                Case $regkey = "HKEY_CLASSES_ROOT"
                        MsgBox(16, "Delete key", "ERROR - The whole " & $regkey & " key cannot be deleted!")
                Case $regkey = "HKEY_CURRENT_USER"
                        MsgBox(16, "Delete key", "ERROR - The whole " & $regkey & " key cannot be deleted!")
                Case $regkey = "HKEY_LOCAL_MACHINE"
                        MsgBox(16, "Delete key", "ERROR - The whole " & $regkey & " key cannot be deleted!")
                Case $regkey = "HKEY_USERS"
                        MsgBox(16, "Delete key", "ERROR - The whole " & $regkey & " key cannot be deleted!")
                Case $regkey = "HKEY_CURRENT_CONFIG"
                        MsgBox(16, "Delete key", "ERROR - The whole " & $regkey & " key cannot be deleted!")
                Case Else
                        $answer = MsgBox(52, "Delete key", "Are you sure you want to delete this key?" & @CRLF & @CRLF & $regkey, "", $handle)
                        Select
                                Case $answer = 6
                                        RegDelete($regkey)
                                        Switch $which
                                                Case 1
                                                        Treeview1($onemsg)
                                                Case 2
                                                        Treeview1($twomsg)
                                        EndSwitch
                                Case $answer = 7
                        EndSelect
        EndSelect
EndFunc   ;==>reg_delete

Func reg_name_delete()
        $regnewname = GUICtrlRead($reg_new_name)
        $regnewtype = GUICtrlRead($reg_new_type)
        $regnewvalue = GUICtrlRead($reg_new_value)
        RegDelete($regkey, $regnewname)
        $regkey = GUICtrlRead($reg_new_key)
        Switch $which
                Case 1
                        Treeview1($onemsg)
                Case 2
                        Treeview1($twomsg)
        EndSwitch
EndFunc   ;==>reg_name_delete

Func regcancel()
        GUIDelete($regui)
        Opt("GUIOnEventMode", 0)
        WinActivate($header)
EndFunc   ;==>regcancel

Func Treeview1($Msg)
        GUISetCursor(15, 1)
        Dim $tvcount = 0, $i, $c
        $type = ""

        _GUICtrlTreeView_BeginUpdate($treeview1)

        $regkey = x("reg." & $Msg & ".path")
        $title = x("reg." & $Msg & ".title")
        $variable = x("reg." & $Msg & ".variable")
        $type = x("reg." & $Msg & ".type")

        ;MsgBox(0,"Message",$regkey)

        If StringInStr($variable, "_val") Then
                _EditVal($Msg, $regkey, $title, $variable, $type)
        Else
                ; messy delete old data :(
                ; works, but has screen flash without the _GUICtrlTreeView_BeginUpdate($TreeView1) line
                GUICtrlSetState($Msg, $TVE_COLLAPSE)

                $c = 1
                While 1
                        $subkey = Eval("$variable$" & "_" & "$c$")
                        $isdeclared = IsDeclared("$variable$" & "_" & "$c$")
                        ;MsgBox(0,"$variable$_$c$", $subkey & @CRLF & $variable & @CRLF & "Declared? " & $isdeclared & @CRLF & "$variable$" & "_" & "$c$")
                        If IsInt($subkey) Then
                                GUICtrlDelete($subkey)
                        Else
                                ExitLoop
                        EndIf
                        $c = $c + 1
                WEnd

                ; Start creating the sub-keys of the Item clicked on.
                _GUICtrlListView_DeleteAllItems($ListView1) ; this line seems to be good here too...
                $c = 1
                While 1
                        $key = RegEnumKey($regkey, $c)
                        If $key = "" Then ExitLoop
                        $path = $regkey & "\" & $key
                        $title = $key
                        Assign("$variable$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, $Msg), 2)
                        x("reg." & Eval("$variable$" & "_" & "$c$") & ".path", $path)
                        x("reg." & Eval("$variable$" & "_" & "$c$") & ".title", $title)
                        x("reg." & Eval("$variable$" & "_" & "$c$") & ".variable", $variable & "_" & $c)
                        $c = $c + 1
                WEnd

                ; Display the Values and data of the hilighted key name
                $c = 1
                ;_GUICtrlListView_DeleteAllItems($ListView1)    ; seems to be good here too, but anywhere I put this line, I still have gui issues...
                SetError(0)
                While 1
                        $val = RegEnumVal($regkey, $c)
                        If @error <> 0 Then ExitLoop
                        $type = @extended
                        If $val = "" Then
                                $val = "(Default)"
                        EndIf

                        Switch $type
                                Case 1
                                        $typedisp = "REG_SZ"
                                Case 2
                                        $typedisp = "REG_EXPAND_SZ"
                                Case 3
                                        $typedisp = "REG_BINARY"
                                Case 4
                                        $typedisp = "REG_DWORD"
                                Case 5
                                        $typedisp = "REG_DWORD_BIG_ENDIAN"
                                Case 6
                                        $typedisp = "REG_LINK"
                                Case 7
                                        $typedisp = "REG_MULTI_SZ"
                                Case 8
                                        $typedisp = "REG_RESOURCE_LIST"
                                Case 9
                                        $typedisp = "REG_FULL_RESOURCE_DESCRIPTOR"
                                Case 10
                                        $typedisp = "REG_RESOURCE_REQUIREMENTS_LIST"
                                Case Else
                                        $typedisp = "REG_NONE"
                        EndSwitch

                        $data = RegRead($regkey, $val)
                        If $data = "" Then
                                $data = "(nem beallitott ertek)"
                        EndIf
                        Assign("$variable$" & "_val" & "$c$", GUICtrlCreateListViewItem($val & "|" & $typedisp & "|" & $data, $ListView1))
                        x("reg." & Eval("$variable$" & "_val" & "$c$") & ".path", $regkey)
                        x("reg." & Eval("$variable$" & "_val" & "$c$") & ".title", $val)
                        x("reg." & Eval("$variable$" & "_val" & "$c$") & ".type", $type)
                        x("reg." & Eval("$variable$" & "_val" & "$c$") & ".typedisp", $typedisp)
                        x("reg." & Eval("$variable$" & "_val" & "$c$") & ".variable", $variable & "_val" & $c)
                        $c = $c + 1
                        $type = ""
                WEnd

        EndIf

        ; Show the results
        _GUICtrlTreeView_EndUpdate($treeview1)
        GUICtrlSetState($Msg, $GUI_EXPAND)
        GUISetState(@SW_SHOW)
        ;x_display()
        GUISetCursor()
EndFunc   ;==>Treeview1

Func _EditVal($Msg, $regkey, $title, $variable, $type)
        $howmuch = StringInStr($variable, "val") ; looking for where the "val" string begins in the $variable
        $whichone = StringTrimLeft($variable, $howmuch + 2) ; cutting the characters from $variable until the end of "val" to determine which line was clicked
        $regfresh = $regfresh - $whichone ; substracting the line number from $regfresh (=$Msg) we get the control id number where we are and which we have to refresh
        GUICtrlSetData($reg_new_key, $regkey)
        GUICtrlSetData($reg_new_name, $title)
        GUICtrlSetData($reg_new_type, $typedisp)
        $value = RegRead($regkey, $title)
        GUICtrlSetData($reg_new_value, $value)
EndFunc   ;==>_EditVal

Func regstop()
        If WinActive($header & " - Search") Then ; check to see if the ESC was pressed in this program
                $regstop = 1
                GUICtrlSetData($btn_reg_search, "Stopping...")
        EndIf
EndFunc   ;==>regstop

Func _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
        Local $v, $sVal, $k, $sKey, $sFound = "", $sFoundSub = "", $avFound[1] = [0]

        ; Trim trailing backslash, if present
        If StringRight($sStartKey, 1) = "\" Then $sStartKey = StringTrimRight($sStartKey, 1)

        ; Generate type flags
        If Not BitAND($iType, 0x07) Then Return SetError(1, 0, 0); No returns selected
        Local $fKeys = BitAND($iType, 0x1), $fValue = BitAND($iType, 0x2), $fData = BitAND($iType, 0x4), $fRegExp = BitAND($iType, 0x8)

        ; Check for wildcard
        If (Not $fRegExp) And ($sSearchVal == "*") Then
                ; Use RegExp pattern "." to match anything
                $iType += 0x8
                $fRegExp = 0x8
                $sSearchVal = "."
        EndIf

        ; This checks values and data in the current key
        If ($fValue Or $fData) Then
                $v = 1
                While $regstop = 0
                        $sVal = RegEnumVal($sStartKey, $v)
                        If @error = 0 Then
                                ; Valid value - test its name
                                If $fValue Then
                                        If $fRegExp Then
                                                If StringRegExp($sVal, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & @CRLF
                                        Else
                                                If StringInStr($sVal, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & @CRLF
                                        EndIf
                                EndIf

                                ; test its data
                                If $fData Then
                                        $readval = RegRead($sStartKey, $sVal)
                                        If $fRegExp Then
                                                If StringRegExp($readval, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @CRLF
                                        Else
                                                If StringInStr($readval, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @CRLF
                                        EndIf
                                EndIf
                                $v += 1
                        Else
                                ; No more values here
                                ExitLoop
                        EndIf
                WEnd
        EndIf

        ; This loop checks subkeys
        $k = 1
        While $regstop = 0
                $sKey = RegEnumKey($sStartKey, $k)
                If @error = 0 Then
                        ; Valid key - test it's name
                        If $fKeys Then
                                If $fRegExp Then
                                        If StringRegExp($sKey, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @CRLF
                                Else
                                        If StringInStr($sKey, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @CRLF
                                EndIf
                        EndIf
                        GUICtrlSetData($sresult, $sStartKey & "\" & $sKey)
                        ; Now search it
                        $sFoundSub = _RegSearch($sStartKey & "\" & $sKey, $sSearchVal, $iType, False) ; use string mode to test sub keys
                        If $sFoundSub <> "" Then $sFound &= $sFoundSub & @CRLF
                Else
                        ; No more keys here
                        ExitLoop
                EndIf
                $k += 1
        WEnd

        ; Return results
        If StringRight($sFound, 1) = @LF Then $sFound = StringTrimRight($sFound, 1)
        If $fArray Then
                If StringStripWS($sFound, 8) <> "" Then $avFound = StringSplit($sFound, @LF)
                Return $avFound
        Else
                Return $sFound
        EndIf
EndFunc   ;==>_RegSearch

Func msgstore($Msg) ; used by reg_delete() function to refresh the tree after deleting a key
        Switch $which
                Case 1
                        If $twomsg <> $Msg Then
                                $onemsg = $Msg
                                $which = 2
                        EndIf
                Case 2
                        If $onemsg <> $Msg Then
                                $twomsg = $Msg
                                $which = 1
                        EndIf
        EndSwitch
EndFunc   ;==>msgstore

Func quit()
        Exit
EndFunc   ;==>quit

Func x($sKey = '', $vValue = '')
        $func = "get"
        If @NumParams <> 1 Then $func = "set"
        If $sKey == '' Then
                If $func == "get" Then
                        Return $_xHashCollection
                Else
                        $_xHashCollection.removeAll
                        Return ''
                EndIf
        EndIf
        $parts = StringSplit($sKey, ".")
        $last_key = $parts[$parts[0]]
        $cur = $_xHashCollection
        For $x = 1 To $parts[0] - 1
                If Not $cur.exists($parts[$x]) Then
                        If $func == "get" Then Return
                        $cur.add($parts[$x], ObjCreate("Scripting.Dictionary"))
                EndIf
                $cur = $cur.item($parts[$x])
        Next
        If IsPtr($vValue) Then $vValue = String($vValue)
        If $func == "get" Then
                If Not $cur.exists($last_key) Then Return
                $item = $cur.item($last_key)
                Return $item
        ElseIf Not $cur.exists($last_key) Then
                $cur.add($last_key, $vValue)
        Else
                $cur.item($last_key) = $vValue
        EndIf
        Return $vValue
EndFunc   ;==>x

; #FUNCTION# ====================================================================================================================
; Name...........: x_unset
; Description ...: Removes a key from an associative Array
; Syntax.........: x_unset( $sKey )
; Parameters ....: $sKey - the key to remove.
; Return values .: Success - True
;                  Failure - False
; Author ........: OHB <me at orangehairedboy dot com>
; ===============================================================================================================================
Func x_unset($sKey)
        If $sKey == '' Then Return x('', '')
        $parts = StringSplit($sKey, ".")
        $cur = $_xHashCollection
        For $x = 1 To $parts[0] - 1
                If Not $cur.exists($parts[$x]) Then Return False
                $cur = $cur.item($parts[$x])
        Next
        $cur.remove($parts[$parts[0]])
        Return True
EndFunc   ;==>x_unset

; #FUNCTION# ====================================================================================================================
; Name...........: x_display
; Description ...: Displays the contents of an associative Array
; Syntax.........: x_display( $sKey )
; Parameters ....: $sKey - the key to display. Examples:
;                  x_display()          displays everything
;                  x_display( 'foo' )   displays the contents of foo
; Author ........: OHB <me at orangehairedboy dot com>
; ===============================================================================================================================
Func x_display($key = '')
        $text = $key
        If $key <> '' Then $text &= " "
        $text &= StringTrimRight( _x_display( x($key), ''), 2)
        $wHnd = GUICreate("Array " & $key, 700, 500)
        GUISetState(@SW_SHOW, $wHnd)
        $block = GUICtrlCreateEdit($text, 5, 5, 690, 490)
        GUICtrlSetFont($block, 10, 400, -1, 'Courier')
        While 1
                If GUIGetMsg() == -3 Then ExitLoop
        WEnd
        GUISetState(@SW_HIDE, $wHnd)
        GUIDelete($wHnd)
EndFunc   ;==>x_display

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _x_display
; Description ...: Itterates through an array and builds output for x_display
; Author ........: OHB <me at orangehairedboy dot com>
; ===============================================================================================================================
Func _x_display($item, $tab)
        If IsObj($item) Then
                $text = 'Array (' & @CRLF
                $itemAdded = False
                For $i In $item
                        $text &= $tab & "  [" & $i & "] => " & _x_display($item.item($i), $tab & "  ")
                        $itemAdded = True
                Next
                If Not $itemAdded Then $text &= @CRLF
                $text &= $tab & ')'
        ElseIf IsArray($item) Then
                $text = "Array"
                $totalItems = 1
                $dimensions = UBound($item, 0)
                For $dimension = 1 To $dimensions
                        $size = UBound($item, $dimension)
                        $totalItems *= $size
                        $text &= "[" & $size & "]"
                Next
                $text &= " (" & @CRLF
                For $itemID = 0 To $totalItems - 1
                        $idName = ''
                        $idNum = $itemID
                        For $dimension = 1 To $dimensions - 1
                                $mul = ($totalItems / UBound($item, $dimension))
                                $a = Floor($idNum / $mul)
                                $idName &= '[' & $a & ']'
                                $idNum -= ($a * $mul)
                        Next
                        $idName &= '[' & $idNum & ']'
                        $text &= $tab & "  " & $idName & " => " & _x_display(Execute("$item" & $idName), $tab & "  ")
                Next
                $text &= $tab & ")"
        Else
                $text = $item
        EndIf
        $text &= @CRLF
        Return $text
EndFunc   ;==>_x_display
 楼主| 发表于 2011-12-15 22:06:38 | 显示全部楼层
回复 9# lixiaolong


    这个强!可惜看不懂,不会用到自己的代码上!
发表于 2011-12-18 11:15:30 | 显示全部楼层
这么长的代码,头疼啊
发表于 2011-12-22 00:18:29 | 显示全部楼层
果断头晕了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 16:22 , Processed in 0.086091 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表