wfxPopupMenu

Started by SeaVipe, June 24, 2020, 03:56:17 PM

Previous topic - Next topic

SeaVipe

Hi Paul, PopUpMenu over a ListView. When a PopupMenu item is clicked, the ListView HitTest reports the Row and Col directly under the Mouse Pointer not the selected Row and Col. The selected Row and Col however do not change from that which the user selected.
If the PopUpMenu item selected is beyond the limits of the ListView then HitTest returns -1. Only when the PopupMenu item selected is directly over the selected Row will the correct result be returned (in this case a form to edit the selected Row values).
I plagiarised your Help example code for PopupMenu over a TreeView and placed it, with appropriate mods in a ListView Click Event. Only PopupMenu item 1, with the mouse pointer carefully placed so that it is also over the selected ListView Row, will the result be correct.
Clive Richey

Paul Squires

Hi Clive, if I read your description correctly then it seems that maybe you are not handling the popup menu in the 'RightClick' event?


''
''
Function frmMain_ListView1_RightClick( ByRef sender As wfxListView, ByRef e As EventArgs ) As LRESULT
   
   ' Only display the popup menu if a valid row has been selected
   if e.ListViewRow = -1 then exit function
   

   ' Create the menu (only one item for this example)
   Dim hPopUpMenu As HMENU = CreatePopupMenu()
   AppendMenu( hPopUpMenu, MF_ENABLED or MF_STRING, IDM_COPYLISTVIEWTEXT, _
               "Copy cell data to clipboard" )


   ? "Popup menu on Row: "; e.ListViewRow; "  Col: "; e.ListViewColumn
   
   ' Display the popup menu and receive the selected item. We use the TPM_RETURNCMD flag
   ' to retrieve the result here rather than have to get it from here.
   dim as long nSelected = _
               TrackPopupMenu( hPopUpMenu, TPM_RETURNCMD or TPM_NONOTIFY, _
                               e.x, e.y, 0, frmMain.hWindow, ByVal Null )

   select case nSelected
      case IDM_COPYLISTVIEWTEXT
         ' Get the text from the row/col and copy it to the clipboard
         dim as CWSTR wszText = frmMain.ListView1.Item(e.ListViewRow).SubItem(e.ListViewColumn).Text
         AfxSetClipboardText( wszText )
   end select                   
   

   ' Finally, destroy the popup menu
   DestroyMenu hPopUpMenu

   Function = 0
End Function


Paul Squires
PlanetSquires Software