PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: wfxPopupMenu  (Read 91 times)


  • Senior Member
  • ***
  • Posts: 364
  • Windows 10
« on: June 24, 2020, 03:26:17 PM »

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
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9287
  • Windows 10
    • PlanetSquires Software
Re: wfxPopupMenu
« Reply #1 on: June 26, 2020, 09:34:33 AM »

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

Code: [Select]
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()
               "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
         ' 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
WinFBE Editor and Visual Designer