Anyone have any idea how to use AddressOf in a VBA Module?
I'm trying to use some API calls to block the mouse right-click, but I keep getting an error that doesn't occur with the same code in VB6.
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_RBUTTONUP = &H205
Public lpPrevWndProc As Long
Private lngHWnd As Long
Public Sub Hook(hWnd As Long)
lngHWnd = hWnd
lpPrevWndProc = SetWindowLong (lngHWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
MsgBox "Right Click Intercepted"
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Select
End Function
Runs perfectly in VB6 but not inVBA, although VBA DOES Recognise AddressOf because it activates a drop down menu containing relevant Modules & Proceedures.
To try this in VB 6, throw the code above into a VB6 Module. Place a textbox on a blank form, Text1, and add Call Hook (Text1.hwd) [ color black] to the Form Load event and Call UnHook to the Form Unload event. BEWARE : If you don't add the UnHook you'll cause a General Protection Fault
Help me ObiWan...
Thanks,
Peter
I'm trying to use some API calls to block the mouse right-click, but I keep getting an error that doesn't occur with the same code in VB6.
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_RBUTTONUP = &H205
Public lpPrevWndProc As Long
Private lngHWnd As Long
Public Sub Hook(hWnd As Long)
lngHWnd = hWnd
lpPrevWndProc = SetWindowLong (lngHWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
MsgBox "Right Click Intercepted"
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Select
End Function
Runs perfectly in VB6 but not inVBA, although VBA DOES Recognise AddressOf because it activates a drop down menu containing relevant Modules & Proceedures.
To try this in VB 6, throw the code above into a VB6 Module. Place a textbox on a blank form, Text1, and add Call Hook (Text1.hwd) [ color black] to the Form Load event and Call UnHook to the Form Unload event. BEWARE : If you don't add the UnHook you'll cause a General Protection Fault
Help me ObiWan...
Thanks,
Peter