dantay9 Posted April 26, 2009 Share Posted April 26, 2009 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? expandcollapse popupFunc 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 Link to comment Share on other sites More sharing options...
Spiff59 Posted April 26, 2009 Share Posted April 26, 2009 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... Link to comment Share on other sites More sharing options...
dantay9 Posted April 26, 2009 Author Share Posted April 26, 2009 (edited) 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 April 26, 2009 by dantay9 Link to comment Share on other sites More sharing options...
dantay9 Posted April 26, 2009 Author Share Posted April 26, 2009 *Bumpity Bump* Link to comment Share on other sites More sharing options...
dantay9 Posted April 28, 2009 Author Share Posted April 28, 2009 Nobody knows? Is it not possible? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 28, 2009 Moderators Share Posted April 28, 2009 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. Link to comment Share on other sites More sharing options...
dantay9 Posted April 29, 2009 Author Share Posted April 29, 2009 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 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