Home All Groups Group Topic Archive Search About

Right Click on a file List box

Author
3 Feb 2006 7:23 AM
daniel
Hello All,

On a File List Box is it possible to get a event on the ricght click button.
If yes how does it possible ?
CLick is ok , key pressed ok
Thanks

Author
3 Feb 2006 9:25 AM
Dave
There are both MouseUp and MouseDown events, both of which have a Button
value which tells you which button was pressed.
What more do you need?

Regards
Dave O.

Show quoteHide quote
"daniel" <dan***@danielcollin.com> wrote in message
news:43e304d9$0$29223$ba620e4c@news.skynet.be...
> Hello All,
>
> On a File List Box is it possible to get a event on the ricght click
> button. If yes how does it possible ?
> CLick is ok , key pressed ok
> Thanks
>
Are all your drivers up to date? click for free checkup

Author
3 Feb 2006 11:44 AM
J French
On Fri, 3 Feb 2006 08:23:07 +0100, "daniel" <dan***@danielcollin.com>
wrote:

>Hello All,
>
>On a File List Box is it possible to get a event on the ricght click button.
>If yes how does it possible ?
>CLick is ok , key pressed ok
>Thanks

Not my code :-

Option Explicit

Private Type POINTAPI
     X As Long
     Y As Long
  End Type

  Private Const LB_ITEMFROMPOINT As Long = &H1A9

  Private Declare Function SendMessage Lib "user32" _
     Alias "SendMessageA" _
    (ByVal hWnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     lParam As Long) As Long

  Private Declare Sub CopyMemory Lib "kernel32" _
     Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, _
     ByVal Length As Long)

  Private Declare Function GetCursorPos Lib "user32" _
    (lpPoint As POINTAPI) As Long

  Private Declare Function ScreenToClient Lib "user32" _
    (ByVal hWnd As Long, _
     lpPoint As POINTAPI) As Long


  Private Sub Command1_Click()

     Unload Me

  End Sub


  Private Sub Form_Load()

   'Add a few items
    Dim i As Integer

     For i = 0 To 20
        List1.AddItem "List item no" & Str$(i)
     Next

  End Sub


  Public Function LoWord(dwValue As Long) As Integer

    CopyMemory LoWord, dwValue, 2

  End Function


  Public Function MAKELONG(wLow As Long, wHigh As Long) As Long

    MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh))

  End Function


  Public Function MAKELPARAM(wLow As Long, wHigh As Long) As Long

   'Combines two integers into a long integer
    MAKELPARAM = MAKELONG(wLow, wHigh)

  End Function


  Private Sub List1_MouseDown(Button As Integer, _
                              Shift As Integer, _
                              X As Single, Y As Single)

     If Button = vbRightButton Then

        Dim lParam As Long
        Dim curritem As Long
        Dim r As Long
        Dim pt As POINTAPI

        Call GetCursorPos(pt)
        Call ScreenToClient(List1.hWnd, pt)

        lParam = MAKELPARAM(pt.X, pt.Y)

        r = SendMessage(List1.hWnd, _
                        LB_ITEMFROMPOINT, _
                        0&, ByVal lParam)

        If r > -1 Then
           curritem = LoWord(r)
           Text1.Text = "Right-mouse clicked over item " & _
                         curritem & " - " & vbTab & Chr$(34) & _
                         List1.List(curritem) & Chr$(34)

          'this line selects the item (if desired)
          'with the right-click
           List1.Selected(curritem) = True

          'uncomment to display a context menu which
          'could be customized for the given selection
          'PopupMenu mnuListOptions
        End If

     End If

  End Sub
Author
4 Feb 2006 10:25 AM
daniel
thank you
"J French" <erew***@nowhere.uk> a écrit dans le message de news:
43e3410f.174980***@news.btopenworld.com...
Show quoteHide quote
> On Fri, 3 Feb 2006 08:23:07 +0100, "daniel" <dan***@danielcollin.com>
> wrote:
>
>>Hello All,
>>
>>On a File List Box is it possible to get a event on the ricght click
>>button.
>>If yes how does it possible ?
>>CLick is ok , key pressed ok
>>Thanks
>
> Not my code :-
>
> Option Explicit
>
> Private Type POINTAPI
>     X As Long
>     Y As Long
>  End Type
>
>  Private Const LB_ITEMFROMPOINT As Long = &H1A9
>
>  Private Declare Function SendMessage Lib "user32" _
>     Alias "SendMessageA" _
>    (ByVal hWnd As Long, _
>     ByVal wMsg As Long, _
>     ByVal wParam As Long, _
>     lParam As Long) As Long
>
>  Private Declare Sub CopyMemory Lib "kernel32" _
>     Alias "RtlMoveMemory" _
>    (Destination As Any, Source As Any, _
>     ByVal Length As Long)
>
>  Private Declare Function GetCursorPos Lib "user32" _
>    (lpPoint As POINTAPI) As Long
>
>  Private Declare Function ScreenToClient Lib "user32" _
>    (ByVal hWnd As Long, _
>     lpPoint As POINTAPI) As Long
>
>
>  Private Sub Command1_Click()
>
>     Unload Me
>
>  End Sub
>
>
>  Private Sub Form_Load()
>
>   'Add a few items
>    Dim i As Integer
>
>     For i = 0 To 20
>        List1.AddItem "List item no" & Str$(i)
>     Next
>
>  End Sub
>
>
>  Public Function LoWord(dwValue As Long) As Integer
>
>    CopyMemory LoWord, dwValue, 2
>
>  End Function
>
>
>  Public Function MAKELONG(wLow As Long, wHigh As Long) As Long
>
>    MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh))
>
>  End Function
>
>
>  Public Function MAKELPARAM(wLow As Long, wHigh As Long) As Long
>
>   'Combines two integers into a long integer
>    MAKELPARAM = MAKELONG(wLow, wHigh)
>
>  End Function
>
>
>  Private Sub List1_MouseDown(Button As Integer, _
>                              Shift As Integer, _
>                              X As Single, Y As Single)
>
>     If Button = vbRightButton Then
>
>        Dim lParam As Long
>        Dim curritem As Long
>        Dim r As Long
>        Dim pt As POINTAPI
>
>        Call GetCursorPos(pt)
>        Call ScreenToClient(List1.hWnd, pt)
>
>        lParam = MAKELPARAM(pt.X, pt.Y)
>
>        r = SendMessage(List1.hWnd, _
>                        LB_ITEMFROMPOINT, _
>                        0&, ByVal lParam)
>
>        If r > -1 Then
>           curritem = LoWord(r)
>           Text1.Text = "Right-mouse clicked over item " & _
>                         curritem & " - " & vbTab & Chr$(34) & _
>                         List1.List(curritem) & Chr$(34)
>
>          'this line selects the item (if desired)
>          'with the right-click
>           List1.Selected(curritem) = True
>
>          'uncomment to display a context menu which
>          'could be customized for the given selection
>          'PopupMenu mnuListOptions
>        End If
>
>     End If
>
>  End Sub
>
>
Author
3 Feb 2006 1:47 PM
Rick Rothstein [MVP - Visual Basic]
> On a File List Box is it possible to get a event
> on the ricght click button.

In the example at this link...

http://vbnet.mvps.org/code/listapi/rightmouseclick.htm

Use a FileListBox in place of the suggested plain ListBox and rename your
FileListBox control to List1 (in order to match the sample code's reference
to its own ListBox). Then, after copying all of the sample code, remove the
Form_Load event code and substitute code to point to a directory path of
your choice instead.

Rick

Bookmark and Share