Jump to content
Sign in to follow this  
dantay9

List View Context Menu

Recommended Posts

dantay9

I have a list view with items in it. I have found this script and a few others that can set a context menu to show if an item in that list view is clicked. How can I find out what button on the context menu is clicked, if any?

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView1
    $hWndListView1 = $List1
    $hWndListView2 = $List2
    If Not IsHWnd($List1) Then $hWndListView1 = GUICtrlGetHandle($List1)
    If Not IsHWnd($List2) Then $hWndListView2 = GUICtrlGetHandle($List2)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView1
            Switch $iCode
                Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)

                   ;set context menu text
                    TrackPopupMenu($hGUI, GUICtrlGetHandle($lvcm), MouseGetPos(0), MouseGetPos(1))
;~                  ;Return 1; not to allow the default processing

;~               Case $LVN_HOTTRACK; Sent by a list-view control when the user moves the mouse over an item
;~                   Sleep(1200)
;~                   Switch $iCode
;~                       Case $LVN_HOTTRACK
;~                           Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
;~                           Local $iItem = DllStructGetData($tInfo, "Item")
;~                           Local $aItem_Rect = _GUICtrlListView_GetItemRect($List1, $iItem)

;~                           Local $aLV_Pos = WinGetPos($hWndListView1)

;~                           If $iItem = -1 Then ToolTip("")
;~                           If $iLastItem = $iItem Then Return 0

;~                           $iLastItem = $iItem

;~                           Local $sToolTipData = _GUICtrlListView_GetItemText($List1, $iItem)
;~                           ToolTip($sToolTipData, $aLV_Pos[0] + $aItem_Rect[0] + 5, $aLV_Pos[1] + $aItem_Rect[1])
;~                   EndSwitch
            EndSwitch
;~       Case $hWndListView2
;~           Switch $iCode
;~               Case $LVN_HOTTRACK
;~                   Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
;~                   Local $iItem = DllStructGetData($tInfo, "Item")
;~                   Local $aItem_Rect = _GUICtrlListView_GetItemRect($List2, $iItem)

;~                   Local $aLV_Pos = WinGetPos($hWndListView2)

;~                   If $iItem = -1 Then ToolTip("")
;~                   If $iLastItem = $iItem Then Return 0

;~                   $iLastItem = $iItem

;~                   Local $sToolTipData = _GUICtrlListView_GetItemText($List2, $iItem)
;~                   ToolTip($sToolTipData, $aLV_Pos[0] + $aItem_Rect[0] + 5, $aLV_Pos[1] + $aItem_Rect[1])
;~           EndSwitch
;~       Case $iLastItem <> -1;And _GUICtrlListView_GetHeader($hWndListView1)
;~           ToolTip("")
;~           $iLastItem = -1
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
;~   ConsoleWrite("x,y = " & $hMenu & ',' & $hWnd & @CRLF)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc  ;==>TrackPopupMenu

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
Spiff59

I've had zero luck with performing any sort of complex function called from within a MW_NOTIFY or WM_COMMAND message trap.

Setting a simple flag inside the function, then using the flag to execute the goodies (like TrackPopupMenu) outside of WM_NOTIFY may behave better for you.

My two cents...

Share this post


Link to post
Share on other sites
dantay9

I am open to any ways, not to just the ones inside the WM_NOTIFY function. I don't exactly know what you mean, though. Do you have an example?

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
dantay9

*Bumpity Bump*


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
dantay9

Nobody knows? Is it not possible?


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
SmOke_N

You have buttons on your context menu?

You don't get replies to your question(s) if your question(s) don't make much sense and you fail to supply a reproducer script.

You can't expect others that may know how to do it, or may have enough knowledge to do it, to write the initial coding themselves on a free support forum.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
dantay9

Okay. I have a script which uses a listbox control. That listbox has lines of text in it that can be selected. I have solved the problem of finding out when a user is clicking on the list box and when they are clicking on the blank space. When the user clicks on one of the lines of text, and only on the text, I would like a context menu to appear so the user is able to delete the item. I can make the context menu appear, but I am not sure how to record if the delete menu was pressed or not. Here is what I have at the moment.

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView1
    $hWndListView1 = $List1
    $hWndListView2 = $List2
    If Not IsHWnd($List1) Then $hWndListView1 = GUICtrlGetHandle($List1)
    If Not IsHWnd($List2) Then $hWndListView2 = GUICtrlGetHandle($List2)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView1
            Switch $iCode
                Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $Index = DllStructGetData($tInfo, "Index")
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.