Desire
Nov 5th, 1999, 02:55 AM
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
PhilipG
Nov 5th, 1999, 08:08 AM
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
phgarman@home.com
Yonatan
Nov 5th, 1999, 05:44 PM
"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...
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...
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: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
Desire
Nov 5th, 1999, 08:36 PM
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