Он говорит handle родных/дочерних окошек формы "Me".
А как бы мне заставить его говорить handl'ы дочерних окошек других программ?
- Код: Выделить всё
Option Explicit
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetNextWindow Lib "user32" _
Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) _
As Long
Public Function GetCaption(lhWnd As Long) As String
Dim sA As String, lLen As Long
lLen& = GetWindowTextLength(lhWnd&)
sA$ = String(lLen&, 0&)
Call GetWindowText(lhWnd&, sA$, lLen& + 1)
GetCaption$ = sA$
End Function
Public Function DLHFindWin(frm As Form, WinTitle As String, _
CaseSensitive As Boolean) As Long
Dim lhWnd As Long, sA As String
lhWnd& = frm.hwnd
Do
DoEvents
If lhWnd& = 0 Then Exit Do
If CaseSensitive = False Then
sA$ = LCase$(GetCaption(lhWnd&))
WinTitle$ = LCase$(WinTitle$)
Else
sA$ = GetCaption(lhWnd&)
End If
If InStr(sA$, WinTitle$) Then
DLHFindWin& = lhWnd&
Exit Do
Else
DLHFindWin& = 0
End If
lhWnd& = GetNextWindow(lhWnd&, 2)
Loop
End Function
Private Sub Form_Load()
MsgBox DLHFindWin(Me, "Project1", False)
End Sub