Announcement

Collapse
No announcement yet.

Easy listbox question

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

  • Easy listbox question

    So I have this listbox on hDlg called %IDLISTBOX1

    Life is good (isn't it?)

    Now, a user selects a string on the listbox, and this message occurs:


    %LBN_SELCHANGE


    Two questions.
    If the string is highlighted how can i get the position of the string.
    Since the string actually represents itself in an array in the same position this would be nice.


    Question 2
    Is there a message for a RIGHT CLICK on this control, if so I'd like to throw a menu up like "Remove this item"


    Thanks!

    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    LOCAL sl AS LONG
    sl = SendMessage(lbhWnd, %LB_GETCURSEL, 0, 0)

    As for trapping right button clicks, I think you have to subclass
    it and trap %WM_RBUTTONDOWN in listbox's subclassed message handler.
    Could be some easier way to do it, but I don't know other that this..


    ------------------

    Comment


    • #3
      Scott,

      Just at this moment I'm working on the same problem - to trap a right mouse click on a listbox.

      Looking at the dialog callback procedure, I noticed the following. A right mouse click inside the listbox generates a WM_MOUSEACTIVATE message. Testing the HIWRD( lParam ), you get "the identifier of the mouse message generated when the user pressed a mouse button", which is WM_RBUTTONDOWN! It seems to be possible to trap such a right clicks.

      I don't know if I can be confident on this behavior. On the other hand, I don't know how to convert the click coordinates (getcursorpos) in something tells me the related item. Can someone help me?

      ------------------
      Rgds, Aldo

      Comment


      • #4
        Code:
          
        #Compile Exe
        #Register None
        #Dim All         
        #Include "win32api.inc" 
          
          
        %LBText             = 100
        %LISTBOX            = 101
        '--------------------------------------------------
        Declare CallBack Function Form_DlgProc
          
        Function PbMain
        Local hDlg&,Style&,ExStyle&,Lst$(),i&
          
          Style& = %WS_POPUP OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR _
                   %DS_SYSMODAL OR %DS_CENTER
          ExStyle& = 0
          
          Dialog New %HWND_DESKTOP,"Context-Menu in Listbox", 0, 0,267,177, _
                     Style&, ExStyle& TO hDlg&
          
          Control Add Label,hDlg&,%LBText,"", 3, 5,259, 12, _
                     %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %WS_DLGFRAME
          
          ReDim LST$(0:99)
          For i& = 0 to 99
           lst$(i&)="**This is listindex " & Str$(i&) & "    ---------"
          Next i&
             
          Control Add ListBox,hDlg&,%LISTBOX,lst(), 3, 20,259,153, _
            %WS_CHILD OR %WS_VISIBLE OR %LBS_NOTIFY OR %WS_VSCROLL OR %WS_BORDER OR %WS_TABSTOP 
            
         Dialog Show Modal hDlg&, Call Form_DlgProc
        End Function
        
        CallBack Function Form_DlgProc
        Local CurSel&,CurItem&,x&,y&,hPopUp&,Id&
        Local R As RECT
        Local pt AS POINTAPI
        Local TopItem&,ItemHight&,Tmp$
             
          Select Case CBMsg
           Case %WM_TIMER
           Case %WM_SIZE
           Case %WM_CLOSE 
           Case %WM_CONTEXTMENU                             
            Select Case GetDlgCtrlID(CBwParam )
             Case %Listbox
        '--Execute only if in listbox----------------------------------------
              CurSel& = SendMessage(CBwParam,%LB_GETCURSEL,0,0)
              x& = LoWrd(CBlParam ) : y& = HiWrd(CBlParam )
              If (x&=65535) Or (y&=65535) Then
        '--Keyboard Shift F10 is used to trigger WM_CONTEXTMENU--------------
               If CurSel& < 0 Then Exit Function 
               TopItem&   = SendMessage(CBwParam,%LB_GETTOPINDEX, 0, 0)
               ItemHight& = SendMessage(CBwParam,%LB_GETITEMHEIGHT,0,0)
               GetClientRect CBwParam,ByVal VarPtr(R)
               pt.x = (R.nRight-R.nLeft)/4
               pt.y = ItemHight&*(CurSel&-TopItem&)+ItemHight&
               ClientToScreen CBwParam,pt
               x&=pt.x:y&=pt.y
              Else
        '--Mouse Right button is used to trigger WM_CONTEXTMENU--------------               
               pt.x = x& : pt.y = y&
               ScreenToClient CBwParam,pt
               CurItem& = LoWrd(SendMessage(CBwParam,%LB_ITEMFROMPOINT,0,MakLng(pt.x,pt.y)))
               If CurItem& <> CurSel& Then _
                  SendMessage CBwParam,%LB_SETCURSEL,CurItem&,0:CurSel& = CurItem&
              End If 
        '--Build & Show the PopUp-menu---------------------------------------
              Menu New Popup To hPopup&
              Menu Add String, hPopup&, "Show Listindex",900, %MF_ENABLED
              Menu Add String, hPopup&, "Show List-Text",901, %MF_ENABLED
              Menu Add String, hPopup&, "Delete this Line", 902, %MF_ENABLED
              Menu Add String, hPopup&, "Add a line here", 903, %MF_ENABLED
              Menu Add String, hPopup&, "Add a line at end", 904, %MF_ENABLED
              Id& =TrackPopupMenu(hPopup&, _
                                  %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON Or %TPM_RETURNCMD, _
                                  x&, y&, 0,CBwParam, ByVal 0)
        '--Execute menu-command----------------------------------------------
              Select Case Id&
               Case 900
                Control Set Text CBHndl,%lbText,"Selected Listitem is no " & Format$(CurSel&)
               Case 901
                ListBox Get Text CBHndl,%Listbox To Tmp$
                Control Set Text CBHndl,%lbText,"Selected text is " & UCase$(Tmp$)
               Case 902
                ListBox Delete CBHndl,%ListBox,CurSel& + 1
                Control Set Text CBHndl,%lbText,"Line " & Format$(CurSel&) & " is deleted"
               Case 903
                Control Set Text CBHndl,%lbText,"No code to execute"
               Case 904 
                CurItem& = SendMessage(CBwParam,%LB_GETCOUNT,0,0)
                Tmp$="**This is listindex " & Str$(CurItem&) & "    ---------"
                Control Set Text CBHndl,%lbText,"This line hopefully added at end " & UCase$(Tmp$)
                ListBox Add CBHndl,%ListBox,Tmp$
               Case Else
                Control Set Text CBHndl,%lbText,"No selection"
              End Select      
             End Select
          End Select
        End Function

        ------------------
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Comment

        Working...
        X