Results 1 to 4 of 4

Thread: 3rd/Midddle Mouse Button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    Hello, I would like to make a program which will intercept the 3rd/middle button click before windows and then send windows a left button double click,even if my form has not got the focus.

    Many Thanks
    Desire

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    Your going to have to subclass windows messaging. When you get the message you want, change it, and let it continue on. Just check this site to see how subclassing is done.

    ------------------
    HTH,
    Philip
    [email protected]

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    "Even if my form has not got the focus..."
    You're going to have to install a Windows Hook (WH_MOUSE). Here's how:

    Module Code...
    Code:
    Option Explicit
    
    
    Type POINTAPI
            X As Long
            Y As Long
    End Type
    
    
    Type MOUSEHOOKSTRUCT
            PT As POINTAPI
            hWnd As Long
            wHitTestCode As Long
            dwExtraInfo As Long
    End Type
    
    
    Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfnHookProc As Long, ByVal hModuleInstance As Long, ByVal dwThreadId As Long) As Long
    Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    
    
    Public Const WM_MBUTTONDOWN = &H207
    Public Const WM_MBUTTONUP = &H208
    
    
    Public Const MOUSEEVENTF_LEFTDOWN = &H2
    Public Const MOUSEEVENTF_LEFTUP = &H4
    
    
    Public Const WH_MOUSE = 7
    
    
    Dim hHook As Long
    
    
    Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, lParam As MOUSEHOOKSTRUCT) As Long
        If (nCode >= 0) And ((wParam = WM_MBUTTONDOWN) Or (wParam = WM_MBUTTONUP)) Then
            MouseProc = True
            Call mouse_event(Choose(wParam - WM_MBUTTONDOWN + 1, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP), 0, 0, 0, 0)
            Exit Function
        End If
        MouseProc = CallNextHookEx(hHook, nCode, wParam, lParam)
    End Function
    
    
    Sub HookMouse()
        hHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, App.hInstance, App.ThreadID)
    End Sub
    
    
    Sub UnhookMouse()
        Call UnhookWindowsHookEx(hHook)
    End Sub
    Form Code...
    Code:
    Private Sub Form_Load()
        Call HookMouse
    End Sub
    
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Call UnhookMouse
    End Sub
    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    PhilipG and Yonatan thanks for replying.

    I have a few more problems, when I quit the program VBs caption goes crazy like it's swapping between run and design mode, and as I know nothing about hooking and subclassing I think it might be a bug of some sort, also if I then try to run the program again I get about 1000 out of stack messages which then crash VB.

    Once that is sorted how does the code tell if the middle mouse button is pressed and then send a left button double click to windows instead??

    Thanks for the help
    Desire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width