Jump to content

Tree View with Editable Labels


Recommended Posts

Hi! Try this:

#include <GuiConstants.au3>
#include <GuiTreeView.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 180, _
BitOR($TVS_EDITLABELS, $TVS_INFOTIP, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)

For $i = 1 To 5
    $hItem = _GUICtrlTreeView_Add($hTreeView, $i, "Item" & $i)
    For $j = 1 To 5
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "SubItem" & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $HwndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $HwndFrom = DllStructGetData($tNMHDR, "HwndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT
                    Return False
                Case $TVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                                                     DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return 1
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
:) Edited by rasim
Link to comment
Share on other sites

Hi! Try this:

#include <GuiConstants.au3>
#include <GuiTreeView.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 180, _
BitOR($TVS_EDITLABELS, $TVS_INFOTIP, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)

For $i = 1 To 5
    $hItem = _GUICtrlTreeView_Add($hTreeView, $i, "Item" & $i)
    For $j = 1 To 5
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "SubItem" & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $HwndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $HwndFrom = DllStructGetData($tNMHDR, "HwndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT
                    Return False
                Case $TVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                                                     DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return 1
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFuncoÝ÷ Ûú®¢×è®Ø^r^nëb¦ÞjènW¦Z§Úò¶®¶­sdFÆÅ7G'V7DvWDFFb33c·D'VffW"ÂgV÷CµFWBgV÷C²
i only get the first letter of the new string.

Does anyone know what's the problem?

Link to comment
Share on other sites

Does anyone know what's the problem?

The above example is made for ansi only, and you're most likely trying to make it work with unicode treeview (which is what it is if you're running unicode version of AutoIt and use native GuiCtrl... functions to create treeview and its items).

To work for both unicode and ansi, the switch statement in the above example should look like this:

Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT, $TVN_BEGINLABELEDITW
                    Return False
                Case $TVN_ENDLABELEDIT, $TVN_ENDLABELEDITW
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam), $sBuffer = "wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", $tBuffer, $sText
                    If Not _GUICtrlTreeView_GetUnicodeFormat($HwndFrom) Then $sBuffer = StringTrimLeft($sBuffer, 1)
                    $tBuffer = DllStructCreate($sBuffer, DllStructGetData($tInfo, "Text"))
                    $sText = DllStructGetData($tBuffer, "Text")
;~                  ConsoleWrite($sText & @CRLF)
                    If StringLen($sText) Then Return 1
            EndSwitch
    EndSwitch
Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

The above example is made for ansi only, and you're most likely trying to make it work with unicode treeview (which is what it is if you're running unicode version of AutoIt and use native GuiCtrl... functions to create treeview and its items).

To work for both unicode and ansi, the switch statement in the above example should look like this:

Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT, $TVN_BEGINLABELEDITW
                    Return False
                Case $TVN_ENDLABELEDIT, $TVN_ENDLABELEDITW
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam), $sBuffer = "wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", $tBuffer, $sText
                    If Not _GUICtrlTreeView_GetUnicodeFormat($HwndFrom) Then $sBuffer = StringTrimLeft($sBuffer, 1)
                    $tBuffer = DllStructCreate($sBuffer, DllStructGetData($tInfo, "Text"))
                    $sText = DllStructGetData($tBuffer, "Text")
;~                  ConsoleWrite($sText & @CRLF)
                    If StringLen($sText) Then Return 1
            EndSwitch
    EndSwitch
Thanks,that solved the problem,i'd never think of something like that!
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...