seadoggie01 Posted August 27, 2020 Share Posted August 27, 2020 I have code to read when the selected item in a tree view changes. I use the selected item's text to perform a search later, but this is a stripped down version. About 1/3 of the time it won't read the selected item's text when I run the script. The rest of the time everything goes great. expandcollapse popup#include <GUIConstants.au3> #include <GuiTreeView.au3> Global $idFileTreeView Main() Func Main() GUICreate("Function Docs", 300, 375) $idFileTreeView = GUICtrlCreateTreeView(10, 10, 250, 350) GUISetState() LoadTreeView() Local $iTemp, $iSelected, $sTreePath, $sText While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case Else $iTemp = _GUICtrlTreeView_GetSelection($idFileTreeView) If ($iTemp <> $iSelected) and ($iTemp <> 0) Then $sText = _GUICtrlTreeView_GetText($idFileTreeView, $iTemp) If Not ($sText = "") Then $iSelected = $iTemp $sTreePath = _GUICtrlTreeView_GetTree($idFileTreeView, _GUICtrlTreeView_GetParentHandle($idFileTreeView, $iSelected)) Debug("Selected: " & $sText) Debug("Path: " & $sTreePath) EndIf EndIf EndSwitch WEnd EndFunc Func LoadTreeView() If Not _GUICtrlTreeView_BeginUpdate($idFileTreeView) Then ErrMsg("_GUICtrlTreeView_BeginUpdate", -1) If Not _GUICtrlTreeView_DeleteAll($idFileTreeView) Then ErrMsg("_GUICtrlTreeView_DeleteAll", -1) Local $iParent For $i=0 To 20 $iParent = _GUICtrlTreeView_Add($idFileTreeView, 0, $i) For $iSub=0 To 20 _GUICtrlTreeView_AddChild($idFileTreeView, $iParent, "Sub " & $iSub) Next Next If Not _GUICtrlTreeView_EndUpdate($idFileTreeView) Then ErrMsg("_GUICtrlTreeView_EndUpdate", -1) EndFunc Func ErrMsg($sMsg, $iError = @error) If $iError Then Debug($sMsg & " Error: " & $iError, "!") Return SetError($iError) EndFunc Func Debug($sMsg, $sPrefix = Default) If $sPrefix = Default Then $sPrefix = "+" ConsoleWrite($sPrefix & " " & $sMsg & @CRLF) EndFunc I'm not sure if this is just a problem with my system or if I'm doing something wrong when reading/editing the tree view. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 27, 2020 Author Share Posted August 27, 2020 Okay, so it always works when I use _GUICtrlTreeView_Create instead. However, now the Tree View doesn't resize All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted August 27, 2020 Share Posted August 27, 2020 Unable to replicate your issue. It is working all the time (Win7). I will test later on Win10. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Zedna Posted August 27, 2020 Share Posted August 27, 2020 (edited) Look here - catch TVN_SELCHANGE in WM_NOTIFY: Edited August 27, 2020 by Zedna seadoggie01 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 28, 2020 Author Share Posted August 28, 2020 (edited) Thanks Zedna! That's perfect, took me a minute to understand all of that, but it's working great now It won't resize, however... I've tried using Opt("GUIResizeMode") and getting the ControlID to use with GUICtrlSetResizing, but neither work. (The button is able to be resized) expandcollapse popup#include <GUIConstants.au3> #include <GuiTreeView.au3> Global $hFileTreeView Main() Func Main() Local $hGUI = GUICreate("Function Docs", 300, 375, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU)) GUICtrlCreateButton("", 0, 0, 10, 10) If Not GUICtrlSetResizing(-1, $GUI_DOCKRIGHT) Then Exit Debug("Failed to make button resizeable") Opt("GUIResizeMode", $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) $hFileTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 250, 350) ; Get the ControlID from the control's handle Local $idFileTreeView = _WinAPI_GetDlgCtrlID($hFileTreeView) If $idFileTreeView = 0 Then Exit Debug(_WinAPI_GetLastError() & ": " & _WinAPI_GetLastErrorMessage()) Debug("TreeView ID: " & $idFileTreeView) ; <-- Prints 10000 and matches Au3Info If Not GUICtrlSetResizing($idFileTreeView, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) Then Debug("Failed to make TreeView resizeable") Opt("GUIResizeMode", 0) ;~ ; Register Tree View item changes -- Woot! ;~ GUIRegisterMsg($WM_NOTIFY, 'OnNotify') GUISetState() ;~ LoadTreeView() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ; N.B. The old variable was $TVN_SELCHANGED, a W/A was added to use Unicode/Ansi Func OnNotify($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $tNMTV = DllStructCreate($tagNMTREEVIEW, $ilParam) Local $hwndFrom = DllStructGetData($tNMTV, 'hWndFrom') Local $iCode = DllStructGetData($tNMTV, 'Code') Local $hSelected, $sText, $sTreePath, $hParent If $hwndFrom = $hFileTreeView And $iCode = $TVN_SELCHANGEDW Then $hSelected = DllStructGetData($tNMTV, 'NewhItem') $sText = _GUICtrlTreeView_GetText($hFileTreeView, $hSelected) $hParent = _GUICtrlTreeView_GetParentHandle($hFileTreeView, $hSelected) if $hParent = 0 Then Return ; No parent $sTreePath = _GUICtrlTreeView_GetTree($hFileTreeView, $hParent) Debug("Text: " & $sText) Debug("Path: " & $sTreePath) EndIf EndFunc Func Debug($sMsg, $sPrefix = Default) If $sPrefix = Default Then $sPrefix = "+" ConsoleWrite($sPrefix & " " & $sMsg & @CRLF) EndFunc Edited August 28, 2020 by seadoggie01 Added OnNotify code for future reference All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Zedna Posted August 28, 2020 Share Posted August 28, 2020 Use $idFileTreeView = GUICtrlCreateTreeView(10, 10, 250, 350) $hFileTreeView = GUICtrlGetHandle($idFileTreeView) seadoggie01 1 Resources UDF ResourcesEx UDF AutoIt Forum Search 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