Giordano Posted June 19, 2011 Share Posted June 19, 2011 Hello! I speak english just a little, i'm learning AutoIt code! Here the code: expandcollapse popup#include <GUIConstantsEx.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 413, 300, 249, 148) $TreeView = GUICtrlCreateTreeView(56, 40, 209, 209) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $config="set.ini" ;~ POPOLATING INIFILE IniWrite($config,"Accounts","IDs","1,2,3") $IDAccounts = StringSplit(IniRead($config,"Accounts","IDs",""),",") For $i=1 to $IDAccounts[0] IniWrite($config,$i,"ID",$i) IniWrite($config,$i,"Name",$i&" name") IniWrite($config,$i,"Surname",$i&" surname") Next PopolateTreeviewDinamically() While 1 ;~ This run the NotifiIT() function each 3 seconds! NotifyIT() Sleep(3000) ;~ But i need to run the function NotifiIT() only when selection changes.. Please help me! $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd func PopolateTreeviewDinamically() $Overview = _GUICtrlTreeView_Add($TreeView,0,"Overview") _GUICtrlTreeView_SetItemParam($TreeView,$Overview,0) $IDs = IniRead($config,"Accounts","IDs","") If $IDs <> "" Then $IDs = StringSplit($IDs,",") _GUICtrlTreeView_BeginUpdate($TreeView) For $i = 1 to $IDs[0] $ID = int(IniRead($config,$IDs[$i],"ID",0)) $Name = IniRead($config,$IDs[$i],"Name","ERRORE!") $Surname = IniRead($config,$IDs[$i],"Surname","ERRORE!") $Hello = _GUICtrlTreeView_AddChild($TreeView,$Overview,$Name) _GUICtrlTreeView_SetItemParam($TreeView,$Hello,$ID) Next _GUICtrlTreeView_EndUpdate($TreeView) _GUICtrlTreeView_Expand($TreeView) EndIf EndFunc Func NotifyIT() $ID = _GUICtrlTreeView_GetItemParam($TreeView) Msgbox(0,"Name",$ID) EndFunc Is there a method to: onselect item of the treeview msgbox for item param? Thank you so much for tring help me! [font=courier new, courier, monospace]Una piccola riflessione: [/font] [font=courier new, courier, monospace]Se guardassi la Terra da un pianeta distante 1 anno luce, vedresti la terra 1 anno prima di quell'istante! Quindi se tu potessi arrivare a quella distanza impiegando solo 6 mesi (quindi viaggiando a 2 volte la velocita della luce) vedresti il mondo com'era 6 mesi prima della partenza.. il passato![/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2011 Moderators Share Posted June 19, 2011 Giordano,You need to look for a mouse click on the treeview and then read the Param data like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> ; Set flag $fFlag = False ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) GUISetState() ; Fill Treeview _GUICtrlTreeView_BeginUpdate($hTreeView) $iOverview = _GUICtrlTreeView_Add($hTreeView, 0, "Overview") _GUICtrlTreeView_SetItemParam($hTreeView, $iOverview, 0) For $i = 1 To 15 $iHello = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, $i) _GUICtrlTreeView_SetItemParam($hTreeView, $iHello, $i) Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) ; Register message GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; If flag is set If $fFlag Then ; Clear flag $fFlag = False ; Read and display the parameter ConsoleWrite(_GUICtrlTreeView_GetItemParam ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF) EndIf WEnd ; Intercept the NOTIFY leassages Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Read the data Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ; See if it was out treeview and the required code Switch $hWndFrom Case $hTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control so set the flag $fFlag = True Return 0 EndSwitch EndSwitch EndFuncI hope the comments are clear enough - please ask if not. If you are not used to coding with GUIRegisterMsg, you might find the GUIRegisterMsg tutorial in the Wiki useful. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Giordano Posted June 19, 2011 Author Share Posted June 19, 2011 Thank so much! You solved me 2 problems: The problem posted and the GuiRegisterMsg for what i was looking for! I like so much that function, i want to learn all of it (GuiRegisterMsg) I was almost arrived to the same solution but i was missing this tutorial! Thank you so much from italy! [font=courier new, courier, monospace]Una piccola riflessione: [/font] [font=courier new, courier, monospace]Se guardassi la Terra da un pianeta distante 1 anno luce, vedresti la terra 1 anno prima di quell'istante! Quindi se tu potessi arrivare a quella distanza impiegando solo 6 mesi (quindi viaggiando a 2 volte la velocita della luce) vedresti il mondo com'era 6 mesi prima della partenza.. il passato![/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2011 Moderators Share Posted June 19, 2011 Giordano,Glad I could help. GUIRegisterMsg is a very powerful tool - there are plenty of examples on the forum to help you learn all about it once you have read the tutorial. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Giordano Posted June 19, 2011 Author Share Posted June 19, 2011 This could be useful for who is looking for the same thing: -ADDED control of the last clicked item! So it write the ID only when the selection change! expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> ; Set flag $fFlag = False ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 200, 300, BitOR($TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) GUISetState() ; Fill Treeview _GUICtrlTreeView_BeginUpdate($hTreeView) $iOverview = _GUICtrlTreeView_Add($hTreeView, 0, "Overview") _GUICtrlTreeView_SetItemParam($hTreeView, $iOverview, 0) For $i = 1 To 15 $iHello = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, $i) _GUICtrlTreeView_SetItemParam($hTreeView, $iHello, $i) Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) ; Register message GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $LastClicked = _GUICtrlTreeView_GetItemParam ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; If flag is set If $fFlag Then ; Clear flag $fFlag = False If $LastClicked <> _GUICtrlTreeView_GetItemParam ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) Then ; Read and display the parameter ConsoleWrite(_GUICtrlTreeView_GetItemParam ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF) EndIf EndIf WEnd ; Intercept the NOTIFY leassages Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Read the data Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ; See if it was out treeview and the required code Switch $hWndFrom Case $hTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control so set the flag $fFlag = True $LastClicked = _GUICtrlTreeView_GetItemParam ($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) ;ADDED Return 0 EndSwitch EndSwitch EndFunc [font=courier new, courier, monospace]Una piccola riflessione: [/font] [font=courier new, courier, monospace]Se guardassi la Terra da un pianeta distante 1 anno luce, vedresti la terra 1 anno prima di quell'istante! Quindi se tu potessi arrivare a quella distanza impiegando solo 6 mesi (quindi viaggiando a 2 volte la velocita della luce) vedresti il mondo com'era 6 mesi prima della partenza.. il passato![/font] 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