Tuesday, June 12, 2012

ComboBox SubClassing - Private Collections

Option Explicit 


Public
glPrevWndProc As Long
Public
glPrevWndProcC As Long

Private Const
GWL_WNDPROC = (-4)
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_PARENTNOTIFY = &H210
Private Const WM_MOUSEMOVE = &H200
Private Const WM_MOUSEWHEEL As Long = &H20A

Private Declare Function
SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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

'ComboBox
Public Sub pUnSubClassCombo(cbo As ComboBox)
Call SetWindowLong(cbo.hwnd, GWL_WNDPROC, glPrevWndProcC)
End Sub

Public Function
pMyWindowProcC(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If
uMsg = WM_PARENTNOTIFY And wParam = WM_RBUTTONDOWN Then
' Call frmMain.Text2_MouseUp(vbRightButton, 0, 0, 0)
Exit Function
ElseIf
uMsg = WM_MOUSEWHEEL Then
Exit Function
End If
pMyWindowProcC = CallWindowProc(glPrevWndProcC, hw, uMsg, wParam, lParam)
End Function

Public Function
fSubClassCombo(cbo As ComboBox) As Long
fSubClassCombo = SetWindowLong(cbo.hwnd, GWL_WNDPROC, AddressOf pMyWindowProcC)
End Function

'TextBox
Public Function pMyWindowProc(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If
uMsg = WM_RBUTTONUP Then
' Call frmMain.Text2_MouseUp(vbRightButton, 0, 0, 0)
Exit Function
End If
pMyWindowProc = CallWindowProc(glPrevWndProc, hw, uMsg, wParam, lParam)
End Function

Public Function
fSubClass(txt As TextBox) As Long
fSubClass = SetWindowLong(txt.hwnd, GWL_WNDPROC, AddressOf pMyWindowProc)
End Function

Public Sub
pUnSubClass(txt As TextBox)
Call SetWindowLong(txt.hwnd, GWL_WNDPROC, glPrevWndProc)
End Sub