danielkza Posted April 5, 2008 Share Posted April 5, 2008 I want to make a treeview with editable labels,but i have no idea how to get wich control was being edited or how to get the new text in TVN_BEGINLABELEDIT or TVN_ENDLABELEDIT.I took a look at the example from Siao at http://www.autoitscript.com/forum/index.php?showtopic=56411 but i didn't understand any of it.Can anybody help me? Link to comment Share on other sites More sharing options...
rasim Posted April 7, 2008 Share Posted April 7, 2008 (edited) Hi! Try this: expandcollapse popup#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 April 7, 2008 by rasim Link to comment Share on other sites More sharing options...
danielkza Posted April 8, 2008 Author Share Posted April 8, 2008 Hi! Try this: expandcollapse popup#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 More sharing options...
Siao Posted April 8, 2008 Share Posted April 8, 2008 (edited) 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 April 8, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
rasim Posted April 9, 2008 Share Posted April 9, 2008 To work for both unicode and ansi, the switch statement in the above example should look like this:I did not know this. Thank you! Link to comment Share on other sites More sharing options...
danielkza Posted April 9, 2008 Author Share Posted April 9, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now