Announcement

Collapse
No announcement yet.

Problem getting right click on listbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem getting right click on listbox

    No problem with other controls in the dialog. The mouse position isn't being reported to let the right click be seen. Here is the proc:
    Code:
            CASE %WM_INITDIALOG
                ' Initialization handler
                     ' Initialization handler
    
                'get position of loaded files... that is only time we can edit.....
                CONTROL GET LOC CBHNDL, %lbl_LoadedCT1 TO b(1).x,b(1).y
                CONTROL GET SIZE CBHNDL, %lbl_LoadedCT1 TO b(1).xx,b(1).yy
                CONTROL GET LOC CBHNDL, %lbl_LoadedCT2 TO b(2).x,b(2).y
                CONTROL GET SIZE CBHNDL, %lbl_LoadedCT2 TO b(2).xx,b(2).yy
                CONTROL GET LOC CBHNDL, %lbl_LoadedCT3 TO b(3).x,b(3).y
                CONTROL GET SIZE CBHNDL, %lbl_LoadedCT3 TO b(3).xx,b(3).yy
                CONTROL GET LOC CBHNDL, %lbl_LoadedCT4 TO b(4).x,b(4).y
                CONTROL GET SIZE CBHNDL, %lbl_LoadedCT4 TO b(4).xx,b(4).yy
                CONTROL GET LOC CBHNDL, %lb_Files TO b(5).x, b(5).y
                CONTROL GET SIZE CBHNDL, %lb_Files TO b(5).xx,b(5).yy
                MouseOverFiles = 0
    
                CONTROL SEND CBHNDL, %lb_Files,%LB_GETITEMHEIGHT,0,0 TO ListBoxHeight 'get height
                CONTROL SEND CBHNDL, %lb_Files,%LB_SETITEMHEIGHT,0,ListBoxHeight * 5  'make it 5 lines
                'find acctual locations
                  FOR i = LBOUND(b) TO UBOUND(b)
                    b(i).xx = b(i).x + b(i).xx + 1     'set to location on screen, not width
                    b(i).yy = b(i).y + b(i).yy + 1     'ditto
                    DECR b(i).x                        'and make for offset of 0
                    DECR b(i).y
                NEXT
    
    'database loads here....
                FOR i = 0 TO 50
                    LISTBOX ADD CBHNDL, %lb_Files,"File #" + FORMAT$(i) + $CRLF + _
                                                 "Chuck Berry" + $TAB + "Maybelene" + $CRLF + _
                                                 "Early Rock from the king of early rock" + $CRLF + _
                                                 "Now from the jukebox."
                NEXT
    
            CASE %WM_LBUTTONDOWN
                 IF mouseOnCart = 0 THEN
                     EXIT FUNCTION
                 ELSE
                     LISTBOX GET TEXT CBHNDL,%lb_Files TO sText
                     SELECT CASE MouseOnCart
                         CASE 1
                              CONTROL SET TEXT CBHNDL,%lbl_LoadedCT1,sText  'have to parse just for filename later
                         CASE 2
                             CONTROL SET TEXT CBHNDL,%lbl_LOadedCT2,sText
                         CASE 3
                             CONTROL SET TEXT CBHNDL,%lbl_LoadedCT3,sText
                         CASE 4
                             CONTROL SET TEXT CBHNDL,%lbl_LoadedCT4,sText
                     END SELECT
                  END IF
            CASE %WM_RBUTTONDOWN
                '? "Mouse right on " & Format$(MouseOnCart)
    
                  IF MouseOverFiles = 1 THEN
                      ? "In there"
                            Showdlg_FilesRClick CBHNDL
                            MouseOverFiles = 0
                            EXIT FUNCTION
                  END IF
                IF MouseOnCart = 0 THEN
                    EXIT FUNCTION
                ELSE
                    SELECT CASE MouseOnCart
                        CASE 1
                            'cal dialog with filename
                        CASE 2
                        CASE 3
                        CASE 4
                    END SELECT
                END IF
    
                ? "Detected right click on cart" & FORMAT$(MouseOnCart)
                'have to find where the mouse is.
           CASE %WM_MouseMove
                my = HIWRD(CBLPARAM)
                mx = LOWRD(CBLPARAM)
                DIALOG PIXELS CBHNDL, mx, my TO UNITS mx, my
                'Hover is a macro that checkes the mouse location
                'control set text cbhndl,%lbl_loadedCT1,format$(mx) & " " & Format$(my)
                IF Hover(1) THEN
                   MouseonCart = 1
                   MouseOverFiles = 0
                   ELSEIF Hover(2) THEN
                       MouseOnCart = 2
                     '  MouseOverFiles = 0
                   ELSEIF Hover(3) THEN
                       MouseOnCart = 3
                     '  MouseOverFiles = 0
                   ELSEIF Hover(4) THEN
                       mouseOnCart = 4
                     '  MouseOverFiles = 0
                   ELSEIF Hover(5) THEN
                       mouseoverFiles = 1
                      ' mouseOnCart = 0
                   ELSE
                       MouseOnCart = 0
                       'MouseOverFiles = 0
                END IF
    And hover is a macro I use in many programs that sees the reported position is within the controls area:

    Code:
     MACRO FUNCTION Hover(lCNum)=mx=>b(lCNum).x AND mx<=b(lCNum).xx AND my=>b(lCNum).y AND my<=b(lcNum).yy
    and the dim's to be sure:

    Code:
       LOCAL i AS LONG,sText AS STRING, lpdis AS DRAWITEMSTRUCT PTR,   zTxt AS ASCIIZ *1999
        LOCAL hpen AS DWORD
        STATIC MouseOnCart,mx,my,MouseOverFiles, ListBoxHeight AS  LONG
     DIM b(1:5) AS STATIC ClientRect
    There is probably something simple here.
    Barry

  • #2
    Looks like listbox %WM_PBUTTONDOWN msg doesn't get to the parent dialog proc. Maybe you could use something like this instead..?
    Code:
     
            CASE %WM_CONTEXTMENU
                IF CBWPARAM = GetDlgItem(CBHNDL, %lb_Files) Then
                   ? "RightClick on %lb_Files"
                END IF
    Rgds, Dave

    Comment


    • #3
      Thanks, that works.
      Barry

      Comment


      • #4
        LBS_NOTIFY
        Notifies the parent window with an input message whenever the user clicks or double-clicks a string in the list box.
        The default message processing I found was...
        • WM_LBUTTONDBLCLK Tracks the mouse in the list box client area. This enables the user to cancel a selection if the mouse button is released outside the list box client area.
        • WM_LBUTTONDOWN Tracks the mouse in the list box client area. This enables the user to cancel a selection if the mouse button is released outside the list box client area.
        • WM_LBUTTONUP Tracks the mouse in the list box client area. This enables the user to cancel a selection if the mouse button is released outside the list box client area.
        .. but that doesn't really tell me anything.

        I think you may have to subclass the control to get the WM_xBUTTONDOWN notifications.

        In any event I'm pretty sure you have to use the LBS_NOTIFY style to do anything.

        EXCEPT... if the user actually selects an item in the listbox with the mouse or the keyboard (it gets highlited) you will get the LBN_SELCHANGE notification.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X