|
Получить полное название окна, зная кусок |
|
|
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 Command1_Click()
'использование функции
Call MsgBox(DLHFindWin&(Me, "доку", False))
'или
Call MsgBox(GetCaption$(DLHFindWin&(Me, "доку", False)))
End Sub
|
|
|
|
|
|
|