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 Sub Form_Activate() MsgBox extraitcontenucontrole(Text1.hwnd) End Sub Private Function extraitcontenucontrole(mhwnd As Long) As String extraitcontenucontrole = String(GetWindowTextLength(mhwnd) + 1, Chr$(0)) GetWindowText mhwnd, extraitcontenucontrole, Len(extraitcontenucontrole) End Function
Private Sub Form_Activate() Text1.Text = "bonjour" Text2.Text = "Hello" EnumChildWindows Me.hwnd, AddressOf EnumChildProc, ByVal 0& End Sub
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim sSave As String sSave = Space$(GetWindowTextLength(hwnd) + 1) GetWindowText hwnd, sSave, Len(sSave) sSave = Left$(sSave, Len(sSave) - 1) If sSave <> "" Then Form1.List1.AddItem sSave EnumChildProc = 1 End Function
Option Explicit Private Sub Form_Activate() Set ou_montrer = List1 Dim retourne As Long, lParam As Long Dim le_handle_fenetre As Long le_handle_fenetre Me.hwnd '>> le handle de la fenêtre (ici, pour demo, celui de ton Form) retourne = EnumChildWindows(le_handle_fenetre, AddressOf EnumChildProc, lParam) End Sub
Option Explicit Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent _ As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _ (ByVal hwnd As Long, ByVal lpClassName As String, _ ByVal nMaxCount As Long) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, _ ByVal cch As Long) As Long Public ou_montrer As ListBox Function EnumChildProc(ByVal le_handle_fenetre As Long, ByVal lParam As Long) As Long Dim RetVal As Long Dim WinClassBuf As String * 255, WinTitleBuf As String * 255 Dim WinClass As String, WinTitle As String Dim WinWidth As Long, WinHeight As Long RetVal = GetClassName(le_handle_fenetre, WinClassBuf, 255) WinClass = nettoyage(WinClassBuf) RetVal = GetWindowText(le_handle_fenetre, WinTitleBuf, 255) WinTitle = nettoyage(WinTitleBuf) ou_montrer.AddItem WinClass & "===>> Title = " & WinTitle EnumChildProc = True End Function Public Function nettoyage(chaine As String) As String nettoyage = chaine If (InStr(chaine, Chr(0)) > 0) Then nettoyage = Left(chaine, InStr(chaine, Chr(0)) - 1) End If If Left(nettoyage, 7) = "Thunder" Then nettoyage = Mid(nettoyage, 8) End If End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionle_handle_fenetre Me.hwnd '>> le handle de la fenêtre (ici, pour demo, celui de ton Form)
Function EnumChildProc(ByVal le_handle_fenetre As Long, ByVal lParam As Long) As Long Dim RetVal As Long Dim WinClassBuf As String * 255, WinTitleBuf As String * 255 Dim WinClass As String, WinTitle As String Dim WinWidth As Long, WinHeight As Long RetVal = GetClassName(le_handle_fenetre, WinClassBuf, 255) WinClass = nettoyage(WinClassBuf) RetVal = GetWindowText(le_handle_fenetre, WinTitleBuf, 255) WinTitle = nettoyage(WinTitleBuf) ou_montrer.AddItem WinClass & "===>> Title = " & WinTitle EnumChildProc = True End Function
.... WinClass = nettoyage(WinClassBuf) RetVal = GetWindowText(le_handle_fenetre, WinTitleBuf, 255) WinTitle = nettoyage(WinTitleBuf) If WinClass = ....... (ta classe ..... then ou_montrer.AddItem WinClass & "===>> Title = " & WinTitle end if ....
et même le nom du type du contrôle "AfxFrameOrView80".
Le WinTitle vaut AfxFrameOrView80.
Et voici ce que j'ai fait (n'ayant pas vb, j'ai fait ca en access). Tes fonctions sont incluses dans Module1.
Sorry, mais je n'ai pas vb 6.
Accueil > Forum > Visual Basic 6 > Windows > API > Lire le contenu d'une application tierce
Le constructeur de l'application me propose de lui payer une somme rondelette pour ajouter un "beep" quand une des valeurs dépasse un intervalle délimité. Moi je veux être prévenu par mail ou par sms quand une des valeurs dépasse un intervalle délimité, d'où ma tentative via programmation de lire le contenu de ce contrôle
Je ne pense pas que cette application soit prévue pour utiliser l'OLE.
Par contre si je trouvais un moyen de savoir quel est le contrôle "grille" et les méthodes pour en interroger le contenu, ca m'arrangerait.