Jump to content

[Solved] Access TreeView Control of existing GUI


Recommended Posts

Hey,

i'm building a "Jump To" registry key function and trying to get access to the regedit treeview control like this:

#include <GUIConstants.au3>
#include <GuiTreeView.au3>
#include <TreeViewConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>


Global $h_item

ShellExecute("regedit.exe")
;~ Local $pid = ProcessExists("regedit.exe")

;~ If $pid Then
;~  $h_tree = WinHandFromPID($pid, "[CLASS:RegEdit_RegEdit]")
;~  WinActivate("[CLASS:RegEdit_RegEdit]", "")
;~ EndIf

WinWaitActive("[CLASS:RegEdit_RegEdit]", "")
;~ WinActivate("[CLASS:RegEdit_RegEdit]", "")
;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_SHOW) ; activate
;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_RESTORE) ; activate
;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_RESTORE) ; activate

$h_tree = WinGetHandle("[CLASS:RegEdit_RegEdit]", "")
;~ $ret = _WinAPI_ShowWindow($h_tree, @SW_RESTORE)

$ctrl = ControlGetHandle($h_tree, "", "[CLASS:SysTreeView32]")

ConsoleWrite("$h_tree: " & $h_tree & @CRLF)
ConsoleWrite("$ctrl: " & $ctrl & @CRLF)

$show = GUICtrlCreateButton("Show", 70, 180, 70, 20)

Show()


;~ While 1
;~  Sleep(200)
;~ WEnd


Func Show()
    $result = ""

    _SendMessage($ctrl, $WM_SETFOCUS, 0, 0)
    If @error Then ConsoleWrite("error" & @CRLF)


    $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_ROOT, 0)

    $split = StringSplit("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "\")
    For $i=1 To $split[0]

        ConsoleWrite("item bevor findkey: " & $h_item & @CRLF)

        $h_item = FindKey($h_item, $split[$i])
        If $h_item = 0 Then Return
        _SendMessage($ctrl, $TVM_SELECTITEM, 0x0009, $h_item)

        ; expand tree
        _GUICtrlTreeView_Expand($ctrl, $h_item)

    Next

    MsgBox(0, "dsfsdf", "sdfsf")
    Exit
EndFunc


Func FindKey($hItemParent, $sKey)

    $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItemParent)
    ConsoleWrite("child : " & $h_item & " key: " & $sKey & " parent: " & $hItemParent & " parent text: " & _GUICtrlTreeView_GetText($ctrl, $hItemParent) & @CRLF)

    While $h_item <> 0
        Local $sItemText = _GUICtrlTreeView_GetText($ctrl, $h_item)
        ConsoleWrite("text : " & $sItemText & @CRLF)
        If $sItemText = $sKey Then Return $h_item

        $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item)
        ConsoleWrite("next : " & $h_item & @CRLF)
    WEnd
    ConsoleWrite("not found" & @CRLF)
    Return 0

EndFunc

it's working, when i start regedit.exe within my app. But can't get it work when regedit.exe already open. Some ideas?

Edited by Trolleule
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...