1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Option Compare Database
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 GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
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 Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
' Recherche l'identifiant de la query nommée pQueryName
' Si la query n'est pas ouverte, la fonction renvoie 0
Public Function GetQueryWindow(pQueryName As String) As Long
Dim lHwnd As Long
Dim lRet As Long
Dim lClassName As String
Dim lWindowText As String
lHwnd = GetWindow(FindWindowEx(Application.hWndAccessApp, 0&, "MdiClient", vbNullString), GW_CHILD)
Do While lHwnd
lClassName = Space(255)
lRet = GetClassName(lHwnd, lClassName, 255)
lClassName = Left(lClassName, lRet)
If lClassName = "oQry" Then
lWindowText = Space(255)
lRet = GetWindowText(lHwnd, lWindowText, 255)
lWindowText = Left(lWindowText, lRet)
If Left(lWindowText, Len(pQueryName)) = pQueryName Then
GetQueryWindow = lHwnd
Exit Do
End If
End If
lHwnd = GetWindow(lHwnd, GW_HWNDNEXT)
Loop
End Function |
Partager