想实现这样的功能,用户输入一个注册表项,如“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 编辑 ] |