CrewXp Posted March 2, 2009 Share Posted March 2, 2009 GUICtrlSetOnEvent - Runs Function when the GuiCtrl is single-clicked. Any way to do this with double-clicking instead of its default single-click? Sample Code for you guys to play with: ;Dummy Data for AutoIt Helpers to Run Opt("GUIOnEventMode", 1) HotKeySet("{F9}","Quit") Dim $gui_stack[25] $data0="asdasdsadsadsadsadsadsadsadsadsadsadsadasdasdasdsadasdas" $data=StringSplit($data0,"") ;END Dummy Data for AutoIt Helpers GLOBAL $maingui=GUICreate("Search Results", 1920/2,(1200/2)) $gui_stack[0]=$maingui $treeview = GUICtrlCreateTreeView(6, 6, 1920/3, 1200/3) $generalitem = GUICtrlCreateTreeViewItem("MEDIA", $treeview) GUICtrlSetColor(-1, 0x0000C0) Dim $search_item_stack[UBound($data)] For $i=0 To UBound($data)-1 $temp=$data[$i] $search_item_stack[$i] = GUICtrlCreateTreeViewItem($temp, $generalitem) ;SetOnEventA($search_item_stack[$i],"show_media_info",$paramByVal,$maingui,$ParamByVal, $i,$ParamByVal, $data[$i]) <- MY ACTUAL LINE IN MY PROGRAM GuiCtrlSetOnevent(-1,"blah");<- For people who dont have the OnEventA include ;SetOnEventA($search_item_stack[$i],"blah") <-This would be the equivalent to the above line in the include I use Next GuiSetState(1) Func blah() Msgbox(0,"","TEST") EndFunc Func Quit() Exit EndFunc While 1 Sleep(100) WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2009 Moderators Share Posted March 2, 2009 CrewXP,I can do it in GUI MessageLoop mode:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> Dim $gui_stack[25] $data0 = "asdasdsadsadsadsadsadsadsadsadsadsadsadasdasdasdsadasdas" $data = StringSplit($data0, "") Global $search_item_stack[UBound($data)], $aItem_Handles[UBound($data)] Global $hMain_GUI = GUICreate("Search Results", 1920 / 2, (1200 / 2)) $hTree = GUICtrlCreateTreeView(6, 6, 1920 / 3, 1200 / 3) $generalitem = GUICtrlCreateTreeViewItem("MEDIA", $hTree) GUICtrlSetColor(-1, 0x0000C0) For $i = 0 To UBound($data) - 1 $temp = $data[$i] $search_item_stack[$i] = GUICtrlCreateTreeViewItem($temp, $generalitem) $aItem_Handles[$i] = GUICtrlGetHandle($search_item_stack[$i]) Next GUISetState(1) ; Initialise "Click on TreeView function" GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") Global $iDoubleClick = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Check if tree view double clicked If $iDoubleClick Then $hCtrl = _GUICtrlTreeView_GetSelection($hTree) $iIndex = _ArraySearch($aItem_Handles, $hCtrl) MsgBox(0, $hCtrl, "You double clicked on Item " & $iIndex + 1) $iDoubleClick = 0 EndIf WEnd Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tagNMHDR, $vEvent Switch $wParam Case $hTree $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $vEvent = DllStructGetData($tagNMHDR, 3) If $vEvent = $NM_DBLCLK Then $iDoubleClick = 1 EndIf EndSwitch $tagNMHDR = 0 EndFunc ;==>MY_WM_NOTIFYThis is how it works.The GUIRegisterMessage lets you peek into the Windows message stream. When we see that the control that was actioned was the TreeView, we look for the "doubleclick" message - if we see it we set a flag. It is important to spend as little time as possible within this function - there is certainly not time to run anything important or you will hold up the Windows message stream and a crash is certain.In the While...WEnd loop, we look for the flag. When we see it we get the Windows handle of the item in the TreeView that has focus. We then need to work out which item that is in ControlID terms. Here I ran into a problem: there is a function _WinAPI_GetDlgCtrlID which should give you the ControlID directly, but it does not work on TreeViewItems - perhaps one of the gurus can tell us why later. So I had to produce a work around - I collected the Windows handles of the TreeViewItems as they were created and then searched that array to find a match.I hope this helps. Sorry I had to change your code so much - but at least now you can pass parameters to your functions without martin's UDF! :-)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...
ken82m Posted March 6, 2009 Share Posted March 6, 2009 I got this working on my listview it works great One thing, What other objects can it work with? I've tried it with an input and label and neither one registered a double click. I used this in my loop to test it If $iDoubleClick Then MsgBox(0, "", "double clicked") $iDoubleClick = 0 EndIf Thanks, Kenny CrewXP, I can do it in GUI MessageLoop mode:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> Dim $gui_stack[25] $data0 = "asdasdsadsadsadsadsadsadsadsadsadsadsadasdasdasdsadasdas" $data = StringSplit($data0, "") Global $search_item_stack[UBound($data)], $aItem_Handles[UBound($data)] Global $hMain_GUI = GUICreate("Search Results", 1920 / 2, (1200 / 2)) $hTree = GUICtrlCreateTreeView(6, 6, 1920 / 3, 1200 / 3) $generalitem = GUICtrlCreateTreeViewItem("MEDIA", $hTree) GUICtrlSetColor(-1, 0x0000C0) For $i = 0 To UBound($data) - 1 $temp = $data[$i] $search_item_stack[$i] = GUICtrlCreateTreeViewItem($temp, $generalitem) $aItem_Handles[$i] = GUICtrlGetHandle($search_item_stack[$i]) Next GUISetState(1) ; Initialise "Click on TreeView function" GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") Global $iDoubleClick = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Check if tree view double clicked If $iDoubleClick Then $hCtrl = _GUICtrlTreeView_GetSelection($hTree) $iIndex = _ArraySearch($aItem_Handles, $hCtrl) MsgBox(0, $hCtrl, "You double clicked on Item " & $iIndex + 1) $iDoubleClick = 0 EndIf WEnd Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tagNMHDR, $vEvent Switch $wParam Case $hTree $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $vEvent = DllStructGetData($tagNMHDR, 3) If $vEvent = $NM_DBLCLK Then $iDoubleClick = 1 EndIf EndSwitch $tagNMHDR = 0 EndFunc ;==>MY_WM_NOTIFY This is how it works. The GUIRegisterMessage lets you peek into the Windows message stream. When we see that the control that was actioned was the TreeView, we look for the "doubleclick" message - if we see it we set a flag. It is important to spend as little time as possible within this function - there is certainly not time to run anything important or you will hold up the Windows message stream and a crash is certain. In the While...WEnd loop, we look for the flag. When we see it we get the Windows handle of the item in the TreeView that has focus. We then need to work out which item that is in ControlID terms. Here I ran into a problem: there is a function _WinAPI_GetDlgCtrlID which should give you the ControlID directly, but it does not work on TreeViewItems - perhaps one of the gurus can tell us why later. So I had to produce a work around - I collected the Windows handles of the TreeViewItems as they were created and then searched that array to find a match. I hope this helps. Sorry I had to change your code so much - but at least now you can pass parameters to your functions without martin's UDF! :-) M23 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 8, 2009 Moderators Share Posted March 8, 2009 ken82m,You are on the ragged edge of my AutoIt (or more accurately Windows) knowledge here. If the control you are actioning sends a Windows message then you can normally use GUIRegisterMsg to intercept it (there are some exceptions already noted in the Help file). However, controls do not all send the same message - and not in the same format. Look in the Help file under "GUIRegisterMsg" and "Appendix - Windows Message Codes" to get some idea and then try searching for GUIRegisterMsg in the forum. There are plenty of examples out there if you look.If you get stuck, try starting a topic with the message name in the title - that should get the gurus' attention! :-) 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...
Manko Posted March 9, 2009 Share Posted March 9, 2009 At OP: Did you alter Func MY_WM_NOTIFY to accept other controles, not just $htree? /Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... 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