Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
''Usage
hwndctl = FindWindowEx(Me.hWnd, 0, "ClassName", vbNullString)
The problem is that its a third party control and it doesnt have any hWnd property and the ThunderTextbox is not working for me, and the classname is ThunderRT6Textbox at design time.
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
h = FindWindowEx(FindWindowEx(hWnd, 0, "ThunderRT6UserControlDC", vbNullString), 0, "ThunderRT6TextBox", vbNullString)
Print h
End Sub
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_LBUTTONDBLCLK = &H203
Public hwndctl As Long
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_LBUTTONDBLCLK Then Exit Function
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
Add to a Form
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Form_Load()
hwndctl = FindWindowEx(FindWindowEx(hwnd, 0, "ThunderRT6UserControlDC", vbNullString), 0, "ThunderRT6TextBox", vbNullString)
SubClassWnd hwndctl
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwndctl
End Sub
Thanks a lot, but can you please tell me why you called the findwindowex function twice? and what should I do if I want to subclass all of these textboxes on my form?
The reason we call it twice is because ThunderRT6TextBox is a child of ThunderRT6UserControlDC, and this is a child of our main form. In other words, ThunderRT6TextBox is a grand-child of our form.