Renderer Posted October 25, 2020 Posted October 25, 2020 Hello Guys! I have a question regarding TreeView selections. How can I get the OLD and CURRENT selected Items in a TreeView? The script bellow does only get the current TreeView selected Item. global $hWin = GUICreate("TreeView --> ListView", 650,550) global $TreeView = GUICtrlCreateTreeView(0,0,250,550) ;TreeView Items global $tv_item_1 = GUICtrlCreateTreeViewItem("Item 1", $TreeView) global $tv_item_2 = GUICtrlCreateTreeViewItem("Item 2", $TreeView) global $tv_item_3 = GUICtrlCreateTreeViewItem("Item 3", $TreeView) GUISetState() global $current_selection global $old_selection While 1 Switch GUIGetMsg() case -3 ExitLoop EndSwitch local $tv_selection = _GUICtrlTreeView_GetSelection($TreeView); Gets the current TreeView Selection Consolewrite("Current Selection: " & $tv_selection & @crlf) WEnd Thanks in advance
caramen Posted October 25, 2020 Posted October 25, 2020 Hello, I already shared multiple time this register msg. I think it can fit to your needs until you understand the GUIRegisterMsg() Of course, you have to rework on variables. expandcollapse popupGUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $WMNotifyTest = 1 Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) If $WMNotifyTest = 1 Then ConsoleWrite ("; WMNotify () Is Working!!"&@CRLF) $WMNotifyTest += 1 EndIf #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $Console If Not IsHWnd($Console) Then $hWndListView = GUICtrlGetHandle($Console) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_CLICK" & @CRLF & _ $TextFav = _GUICtrlListView_GetItemText($Console, DllStructGetData($tInfo, "Index")) & _ "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ClipPut(_GUICtrlListView_GetItemText($Console, DllStructGetData($tInfo, "Index"))) _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _GUICtrlListView_DeleteItem($Console, DllStructGetData($tInfo, "Index")) _FileWriteToLine ( @ScriptDir&"\Log.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log02.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log002.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Log.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log02.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log002.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Log.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log02.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _FileWriteToLine ( @ScriptDir&"\Data\Log002.txt" , DllStructGetData($tInfo, "Index") , "" , True , True ) _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ;~ FileClose ($File2) ;~ FileClose ($File02) ;~ FileClose ($File002) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Nine Posted October 25, 2020 Posted October 25, 2020 (edited) Or just modifying your code a bit : #include <GuiTreeView.au3> Global $hWin = GUICreate("TreeView --> ListView", 650, 550) Global $TreeView = GUICtrlCreateTreeView(0, 0, 250, 550) ;TreeView Items Global $tv_item_1 = GUICtrlCreateTreeViewItem("Item 1", $TreeView) Global $tv_item_2 = GUICtrlCreateTreeViewItem("Item 2", $TreeView) Global $tv_item_3 = GUICtrlCreateTreeViewItem("Item 3", $TreeView) GUISetState() Global $current_selection = 0, $tv_selection, $old_selection SetSelection () While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $tv_item_1 To $tv_item_3 SetSelection() EndSwitch WEnd Func SetSelection () $tv_selection = _GUICtrlTreeView_GetSelection($TreeView) If $current_selection <> $tv_selection Then $old_selection = $current_selection $current_selection = $tv_selection ConsoleWrite("Current Selection: " & $tv_selection & " Old Selection = " & $old_selection & @CRLF) EndIf EndFunc This way you won't overload the CPU by always searching for the new selection... Edited October 25, 2020 by Nine “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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