atzoref Posted February 2, 2012 Share Posted February 2, 2012 Hi, This function return theHandle to the currently selected item, but it works only when "left" click of the mouse is press on an item, How can I make it work even with "Right" click? Thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 2, 2012 Moderators Share Posted February 2, 2012 atzoref, I would do it like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> ; Set flag $fFlag = False ; Create handle array Global $aItem_Handles[16] = [15] ; 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") For $i = 1 To 15 $aItem_Handles[$i] = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $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 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 our treeview Switch $hWndFrom Case $hTreeview ; Work out which item is under cursor $aPos = GUIGetCursorInfo($hGUI) $iIndex = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0] - 10, $aPos[1] - 10) ; Look for code Switch $iCode Case $NM_CLICK ; Get item text For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then ConsoleWrite("You clicked: " & _GUICtrlTreeView_GetText($hTreeview, $aItem_Handles[$i]) & @CRLF) ExitLoop EndIf Next Case $NM_RCLICK ; Click on that item For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then _GUICtrlTreeView_ClickItem($hTreeview, $aItem_Handles[$i]) ExitLoop EndIf Next EndSwitch EndSwitch EndFunc Any help? 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...
AdmiralAlkex Posted February 2, 2012 Share Posted February 2, 2012 Good but not perfect (when left/right clicking on the last pixel of items ) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
atzoref Posted February 5, 2012 Author Share Posted February 5, 2012 This is the only way? It seems to be a little complicate for such small thing.... I just want when to use "ContextMenu" with the right click of the mouse on an item, so it change the GetSelection function like it works when left click is pressed on the item. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2012 Moderators Share Posted February 5, 2012 atzoref, It seems to be a little complicate for such small thing....Often the way alas. Here is a script which both selects the item and shows a context menu when you right click on it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <GuiMenu.au3> ; Create array for the context menu Global $aButtons[4] ; Create handle array Global $aItem_Handles[16] = [15] ; 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") For $i = 1 To 15 $aItem_Handles[$i] = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i) Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) $hDummy = GUICtrlCreateDummy() $mContext = GUICtrlCreateContextMenu($hDummy) $hMenu = GUICtrlGetHandle($mContext) $aButtons[1] = GUICtrlCreateMenuItem("Test 1", $mContext) $aButtons[2] = GUICtrlCreateMenuItem("Test 2", $mContext) $aButtons[3] = GUICtrlCreateMenuItem("Test 3", $mContext) ; Register message GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $aButtons[1] ConsoleWrite("Context Menu Item 1" & @LF) Case $aButtons[2] ConsoleWrite("Context Menu Item 2" & @LF) Case $aButtons[3] ConsoleWrite("Context Menu Item 3" & @LF) EndSwitch WEnd ; Intercept the NOTIFY leassages Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Clear the rightclick flag Static $fRtClick = False ; Read the data Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ; See if it was our treeview Switch $hWndFrom Case $hTreeview ; Work out which item is under cursor $aPos = GUIGetCursorInfo($hGUI) $iIndex = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0] - 10, $aPos[1] - 10) ; Look for code Switch $iCode Case $NM_CLICK ; Get item text For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then ConsoleWrite("You clicked: " & _GUICtrlTreeView_GetText($hTreeview, $aItem_Handles[$i]) & @CRLF) ExitLoop EndIf Next If $fRtClick Then $fRtClick = False _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) EndIf Case $NM_RCLICK ; Click on that item For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then _GUICtrlTreeView_ClickItem($hTreeview, $aItem_Handles[$i]) $fRtClick = True ExitLoop EndIf Next EndSwitch EndSwitch EndFunc I hope that solves your problem. 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...
atzoref Posted February 8, 2012 Author Share Posted February 8, 2012 I took the last example but it still not change the state of the (GetSelection) with the right click on a item in the tree (It still worked only with left click on the item) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2012 Moderators Share Posted February 8, 2012 atzoref, it still not change the state of the (GetSelection) with the right click on a item in the treeYes it does, as this code shows: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <GuiMenu.au3> ; Create array for the context menu Global $aButtons[4] ; Create handle array Global $aItem_Handles[16] = [15] ; Create a flag to show when an item has been clicked Global $fClick = 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") For $i = 1 To 15 $aItem_Handles[$i] = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i) Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) $hDummy = GUICtrlCreateDummy() $mContext = GUICtrlCreateContextMenu($hDummy) $hMenu = GUICtrlGetHandle($mContext) $aButtons[1] = GUICtrlCreateMenuItem("Test 1", $mContext) $aButtons[2] = GUICtrlCreateMenuItem("Test 2", $mContext) $aButtons[3] = GUICtrlCreateMenuItem("Test 3", $mContext) ; Register message GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $aButtons[1] ConsoleWrite("Context Menu 1" & @LF) Case $aButtons[2] ConsoleWrite("Context Menu 2" & @LF) Case $aButtons[3] ConsoleWrite("Context Menu 3" & @LF) EndSwitch ; Test which item is selected at this point If $fClick Then $hItem = _GUICtrlTreeView_GetSelection($hTreeView) ConsoleWrite("Item Selected: " & _GUICtrlTreeView_GetText($hTreeview, $hItem) & @CRLF) $fClick = False EndIf WEnd ; Intercept the NOTIFY leassages Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Clear the rightclick flag Static $fRtClick = False ; Read the data Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ; See if it was our treeview Switch $hWndFrom Case $hTreeview ; Work out which item is under cursor $aPos = GUIGetCursorInfo($hGUI) $iIndex = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0] - 10, $aPos[1] - 10) ; Look for code Switch $iCode Case $NM_CLICK ; Get item text For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then ConsoleWrite("You clicked: " & _GUICtrlTreeView_GetText($hTreeview, $aItem_Handles[$i]) & @CRLF) If $fRtClick Then $fRtClick = False _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) EndIf ; Set the flag to show we have clcked an item $fClick = True ExitLoop EndIf Next Case $NM_RCLICK ; Click on that item For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then _GUICtrlTreeView_ClickItem($hTreeview, $aItem_Handles[$i]) $fRtClick = True ExitLoop EndIf Next EndSwitch EndSwitch EndFunc When I runn that script and rightclick on an item, the code tells me that the item is indeed selected. 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...
atzoref Posted February 8, 2012 Author Share Posted February 8, 2012 (edited) In your last example th first time you click with the Right on an item, the selection still jump to the previous selection, only from the second press is stable on the selection. I try to implement your code in my script but I get: Array variable has incorrect number of subscripts or subscript dimension range exceeded. - on the "IF" line. Case $NM_RCLICK ; Click on that item For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then I have an array with 2 coloums, when coloum [0] is with the handles ,it is something with the range. What it is means? ; Create handle array Global $aItem_Handles[16] = [15] Edited February 8, 2012 by atzoref Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2012 Moderators Share Posted February 8, 2012 (edited) atzoref, I just want when to use "ContextMenu" with the right click of the mouse on an item, so it change the GetSelection function like it works when left click is pressed on the itemThat is what you asked for and that is what the code above does. If you remove the context menu code, then you can see that it takes just the one click of either button to select the item. expandcollapse popup#include <GUIConstants.au3> #include <windowsconstants.au3> #include <guitreeview.au3> #include <guimenu.au3> ; Create array for the context menu Global $aButtons[4] ; Create handle array Global $aItem_Handles[16] = [15] ; Create a flag to show when an item has been clicked Global $fClick = 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") For $i = 1 To 15 $aItem_Handles[$i] = _GUICtrlTreeView_AddChild($hTreeView, $iOverview, "Item " & $i) Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) $hDummy = GUICtrlCreateDummy() $mContext = GUICtrlCreateContextMenu($hDummy) $hMenu = GUICtrlGetHandle($mContext) $aButtons[1] = GUICtrlCreateMenuItem("Test 1", $mContext) $aButtons[2] = GUICtrlCreateMenuItem("Test 2", $mContext) $aButtons[3] = GUICtrlCreateMenuItem("Test 3", $mContext) ; Register message GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $aButtons[1] ConsoleWrite("Context Menu 1" & @LF) Case $aButtons[2] ConsoleWrite("Context Menu 2" & @LF) Case $aButtons[3] ConsoleWrite("Context Menu 3" & @LF) EndSwitch ; Test which item is selected at this point If $fClick Then $hItem = _GUICtrlTreeView_GetSelection($hTreeView) ConsoleWrite("Item Selected: " & _GUICtrlTreeView_GetText($hTreeview, $hItem) & @CRLF) $fClick = False EndIf WEnd ; Intercept the NOTIFY leassages Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Clear the rightclick flag Static $fRtClick = False ; Read the data Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ; See if it was our treeview Switch $hWndFrom Case $hTreeview ; Work out which item is under cursor $aPos = GUIGetCursorInfo($hGUI) $iIndex = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0] - 10, $aPos[1] - 10) ; Look for code Switch $iCode Case $NM_CLICK ; Get item text For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then If $fRtClick Then ConsoleWrite("You right clicked: " & _GUICtrlTreeView_GetText($hTreeview, $aItem_Handles[$i]) & @CRLF) $fRtClick = False Else ConsoleWrite("You left clicked: " & _GUICtrlTreeView_GetText($hTreeview, $aItem_Handles[$i]) & @CRLF) EndIf ; Set the flag to show we have clicked an item $fClick = True ExitLoop EndIf Next Case $NM_RCLICK ; Click on that item For $i = 0 To $aItem_Handles[0] If $aItem_Handles[$i] = $iIndex Then _GUICtrlTreeView_ClickItem($hTreeview, $aItem_Handles[$i]) $fRtClick = True ExitLoop EndIf Next EndSwitch EndSwitch EndFunc Happy now? M23 Edited February 8, 2012 by Melba23 Added missing include 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...
atzoref Posted February 8, 2012 Author Share Posted February 8, 2012 (edited) The mini Bug fixed, But I have an errors when I try it on my script as I said, why can be the reasons? Edited February 8, 2012 by atzoref Link to comment Share on other sites More sharing options...
maba Posted February 8, 2012 Share Posted February 8, 2012 (edited) atzoref, add #include <GUIConstants.au3> in your code Edited February 8, 2012 by maba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2012 Moderators Share Posted February 8, 2012 maba, Thanks for spotting that - I have added it in the code above. 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...
maba Posted February 8, 2012 Share Posted February 8, 2012 yoy all help me everyday! 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