AndyS01 Posted March 31, 2014 Share Posted March 31, 2014 I'm trying to trap a right click event when focus is on a List (GUICtrlCreateList) control, but no such event is posted via $WM_COMMAND or $WM_NOTIFY. I set up handlers for both $WM_COMMAND and $WM_NOTIFY, and I see notification for a left click, but not for a right click. I see notification when moving focus, but not when I right click on the List control. Here is my stripped down code: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt("GuiOnEventMode", 1) Opt('MustDeclareVars', 1) Global $hGUI = GUICreate("Test", 300, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") Global $lv = GUICtrlCreateList("listview", 10, 10, 200, 200) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While 1 Sleep(10) WEnd Func _Quit() Exit EndFunc ;==>_Quit Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ConsoleWrite("+++: WM_COMMAND(" & Hex($hWnd) & "," & Hex($iMsg) & "," & Hex($iwParam) & "," & Hex($ilParam) & ") entered" & @CRLF) #forceref $hWnd, $iMsg, $iwParam local $str Local $hFrom = HWnd($ilParam) Local $idFrom = BitAND($iwParam, 0x0000FFFF) Local $iCode = BitShift(BitAND($iwParam, 0xFFFF0000), 16) $str = "$hFrom: " & HEX($hFrom) $str &= ", $idFrom: " & HEX($idFrom) $str &= ", $iCode: " & HEX($iCode) consolewrite("+++: " & $str & @CRLF) Switch $hFrom Case $lv If $iCode = $BN_CLICKED Then ConsoleWrite("+++: $BN_CLICKED") ElseIf $iCode = $NM_CLICK Then ConsoleWrite("+++: $NM_CLICK") ElseIf $iCode = $NM_RCLICK Then ConsoleWrite("+++: $NM_RCLICK") EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ConsoleWrite("+++: WM_NOTIFY(" & Hex($hWnd) & "," & Hex($iMsg) & "," & Hex($iwParam) & "," & Hex($ilParam) & ") entered" & @CRLF) #forceref $hWnd, $iMsg, $iwParam local $str Local $hFrom = HWnd($ilParam) Local $idFrom = BitAND($iwParam, 0x0000FFFF) Local $iCode = BitShift(BitAND($iwParam, 0xFFFF0000), 16) $str = "$hFrom: " & HEX($hFrom) $str &= ", $idFrom: " & HEX($idFrom) $str &= ", $iCode: " & HEX($iCode) consolewrite("+++: " & $str & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 31, 2014 Moderators Share Posted March 31, 2014 AndyS01,You can thank the much missed rasim for this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> #include <WinAPI.au3> $gui = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 161, 240) GUICtrlSetData( $cList, "Line 1|Line 2|Line 3") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $tPoint = _WinAPI_GetMousePos(True, GUICtrlGetHandle($cList)) Local $iY = DllStructGetData($tPoint, "Y") ; Look to see if the right click was on an item For $i = 0 To 2 Local $aRect = _GUICtrlListBox_GetItemRect($cList, $i) If $iY >= $aRect[1] And $iY <= $aRect[3] Then ConsoleWrite("RightClick" & @CRLF) ExitLoop EndIf Next Return $GUI_RUNDEFMSG EndFuncM23 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...
AndyS01 Posted March 31, 2014 Author Share Posted March 31, 2014 Good example. It almost does the job. However, I want to detect right clicks anywhere in the List control. If I could get the bounding rectangle of the List control, I could determine if the mouse position is within it or not, just like you did for eacc data line in the control. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 31, 2014 Moderators Share Posted March 31, 2014 AndyS01,Sounds like it should work. 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...
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