Как получить дескриптор окна в VBA?
...
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
...
WordHWnd = FindWindow("OpusApp", vbNullString)
...
Кстати, у меня получилось незамысловато следующим образом:
ActiveWindowHandle = FindWindow(vbNullString, _
ActiveWindow.Caption + " - " + Application.Caption)
HOWTO: Obtain the Window Handle for an Office Automation Server
----
Find the Window Handle for an Application That Is Single Instance
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click
Dim PptApp As Object
Set PptApp = CreateObject("PowerPoint.Application")
PptApp.Visible = True
Dim hWndPpt As Long
hWndPpt = FindWindow("PP9FrameClass", 0) 'PP97FrameClass w/ PowerPoint 97
MsgBox "hWndPpt ( " & Hex(hWndPpt) & " ) contains the Window Handle " & _
"of the PowerPoint application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, such " & _
"as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr & _
vbCr & "All Done. Click OK to close PowerPoint.", vbMsgBoxSetForeground
PptApp.Quit
Set PptApp = Nothing
End Sub
Find the Window Handle for an Application That Can Have Multiple Instances
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Caption = "New Caption Supplied by Program"
Dim hWndXl As Long
hWndXl = FindWindow("XLMAIN", xlApp.Caption)
xlApp.Caption = Empty 'Set the original caption back
xlApp.Visible = True
MsgBox "hWndXl ( " & Hex(hWndXl) & " ) contains the Window Handle " & _
"of the Excel application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, " & _
"such as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr _
& vbCr & "All Done. Click OK to close Excel.", vbMsgBoxSetForeground
xlApp.Quit
Set xlApp = Nothing
End Sub
PS. Если приложение Access, тогда можно проще Application.hWndAccessApp - родительское окно и Form[Report].hWnd
Оставить комментарий
Djet
субж? дескриптор нужен для вызова функции GetWindowThreadProcessId hwnd, RunningAppProcessID