ActiveX Control Stealing Focus
Ok, here is my problem. I got a form with an activeX control on it that I made (and can modify, if needed). I am using the scroll wheel code posted below. It works good if the form has focus or if any other control on the form has focus besides my ActiveX control. When my ActiveX control gets focus the code no longer works. Please help.
I have also noted that my app uses 2 threads. Do all activeX controls use their own thread??
VB Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
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
Const GWL_WNDPROC = (-4)
Const WM_MOUSEWHEEL = &H20A
Global WndProcOld As Long
Private Function HiWord(ByVal LongVal As Long) As Integer
If LongVal = 0 Then
HiWord = 0
Exit Function
End If
HiWord = LongVal \ &H10000 And &HFFFF&
End Function
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
If wMsg = WM_MOUSEWHEEL Then
If HiWord(wParam) < 0 Then
'event 1
Else
'event 2
End If
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub