Sign in to follow this  
Followers 0
AndyS01

No events for $WM_COMMAND or $WM_NOTIFY for List control

4 posts in this topic

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:
#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

 

Share this post


Link to post
Share on other sites



AndyS01,

You can thank the much missed rasim for this: ;)

#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

EndFunc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0