找回密码
 加入
搜索
查看: 1645|回复: 3

如何展开指定的注册表项?

[复制链接]
发表于 2008-6-24 09:28:17 | 显示全部楼层 |阅读模式
想实现这样的功能,用户输入一个注册表项,如“HKEY_CLASSES_ROOT\._sln”,程序自动打开注册表编辑器,并展开相应的项。写了一下代码,可是到了 _GUICtrlTreeView_FindItemEx 出得不到值了,请问是什么原因?如何解决?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

$formExpandReg = GUICreate("注册表项展开工具", 469, 76, 243, 256)
$txtRegKey = GUICtrlCreateInput("我的电脑\HKEY_CLASSES_ROOT\.aca", 8, 8, 449, 21)
$btnPaste = GUICtrlCreateButton("粘贴(&P)", 296, 40, 75, 25, 0)
$btnExpand = GUICtrlCreateButton("展开(E)", 384, 40, 75, 25, 0)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $formExpandReg, "int", 200, "long", 0x00080000);fade-in
GUISetState()
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $btnPaste
                        GUICtrlSetData($txtRegKey, ClipGet(), "")
                Case $btnExpand
                        ExpandReg()
        EndSwitch
WEnd

Func ExpandReg()
        ;读取用户输入的注册表项
        $RegKey = GetRegKey()
        ;打开注册表编辑器
        Run("regedit")
        WinWaitActive("注册表编辑器")
        ;得到左侧树状列表
        $TreeViewHandle = ControlGetHandle("注册表编辑器", "", 1)        
        If Not $TreeViewHandle Then
                MsgBox ("","错误","此程序只能运行于简体中文 Windows 之上!")
                Exit
        EndIf

        $ItemFoundHandle = _GUICtrlTreeView_FindItemEx($TreeViewHandle, $RegKey)
        If $ItemFoundHandle Then
        _GUICtrlTreeView_SelectItem($TreeViewHandle, $ItemFoundHandle)
        MsgBox(4160, "提示", "发现项目:" & @LF & "句柄: " & $ItemFoundHandle & @LF & "文本: " & _GUICtrlTreeView_GetText($TreeViewHandle, $ItemFoundHandle))
    Else
        MsgBox(4160, "提示", "未找到项目!")
    EndIf
EndFunc

Func GetRegKey()
        Return GUICtrlRead($txtRegKey)
EndFunc


[ 本帖最后由 runningwater 于 2008-6-25 08:35 编辑 ]
发表于 2008-6-24 18:54:28 | 显示全部楼层
这样做可以简单点
[au3]#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

$formExpandReg = GUICreate("注册表项展开工具", 469, 76, 243, 256)
$txtRegKey = GUICtrlCreateInput("我的电脑\HKEY_CLASSES_ROOT\.aca", 8, 8, 449, 21)
$btnPaste = GUICtrlCreateButton("粘贴(&P)", 296, 40, 75, 25, 0)
$btnExpand = GUICtrlCreateButton("展开(E)", 384, 40, 75, 25, 0)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $formExpandReg, "int", 200, "long", 0x00080000);fade-in
GUISetState()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $btnPaste
            GUICtrlSetData($txtRegKey, ClipGet(), "")
        Case $btnExpand
            ExpandReg()
    EndSwitch
WEnd

Func ExpandReg()
    ;读取用户输入的注册表项
    $RegKey = GetRegKey()   
        RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit","LastKey","REG_SZ",$RegKey)
        ;打开注册表编辑器
    Run("regedit")   
EndFunc

Func GetRegKey()
    Return GUICtrlRead($txtRegKey)
EndFunc[/au3]
 楼主| 发表于 2008-6-25 08:35:37 | 显示全部楼层
果然非常方便,谢谢!我的方法走弯路了。
发表于 2009-10-9 16:13:23 | 显示全部楼层
不错啊,,收下了。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 08:19 , Processed in 0.070370 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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