Доброго дня уважаемые господа !
Необходимо найти окно, которое принадлежит конкретному обьекту ?
Делаю так !
Public Const GW_HWNDNEXT = 2
Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwprocessid As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetCurrentProcessId Lib "Kernel32" () As Long
Function GetWinHandle(hInst As Long) As Long
Dim hWnd As Long, IdProc As Long
hWnd = FindWindow(vbNullString, vbNullString)
Do While hWnd <> 0
If GetParent(hWnd) = 0 Then
Call GetWindowThreadProcessId(hWnd, IdProc)
If IdProc = hInst Then Exit Do
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
GetWinHandle = hWnd
End Function
Private Sub Command1_Click()
Dim hInst As Long, hWApp As Long, sNaim As String
Set Outlooks = CreateObject("Outlook.Application")
hInst = Shell("calc.exe")
[SIZE=3]
'hInst = GetCurrentProcessId - не подходит указывает текущий-запускаемый процесс
'hInst = Outlooks - здесь надо получить ID процесса, от обьекта...
[/SIZE]
hWApp = GetWinHandle(hInst)
If hWApp <> 0 Then
sNaim = String(255, vbNullChar)
Call GetWindowText(hWApp, sNaim, Len(sNaim))
List.AddItem " Title Window: " & Left(sNaim, InStr(sNaim, vbNullChar) - 1)
End If
End Sub
Спасибо ...