Recup control d'un fenêtre windows

Résolu
AirByte Messages postés 13 Date d'inscription mercredi 5 janvier 2011 Statut Membre Dernière intervention 25 février 2011 - 6 janv. 2011 à 16:38
AirByte Messages postés 13 Date d'inscription mercredi 5 janvier 2011 Statut Membre Dernière intervention 25 février 2011 - 7 janv. 2011 à 16:46
Bonjour

Je suis en VB.net, avec Visual Studio Express 2010

J'aurais besoin d'un coup de main, en fait je voudrais surtout savoir si ce que je veux faire est possible.

Une fenêtre d'information est ouverte en permanence (réduite dans la barre des tâche). un chiffre inscrit sur cette fenêtre change régulièrement.

Je voudrais faire une application qui va lire ce chiffre. Avec un outil AutoIt, j'ai le ClassName de la fenêtre et le ClassName du control contenant le chiffre. Est-ce que avec ces infos je pourrais, sans afficher la fenêtre, déterminer la couleur d'un pixel de cette fenêtre (par exemple) pour déterminer quel est ce chiffre.

Auriez-vous des pistes de solutions?

Merci

2 réponses

Utilisateur anonyme
7 janv. 2011 à 15:15
Salut,
Ne connaissant rien sur cette fameuse fenêtre d'information que tu cite je te propose un petit exemple trouvé sur le net qui permet de récupérer le résultat inscrit dans la calculatrice windows.
En l'adaptant, tu pourra peut être récupérer ce qui te manque.
Ajoute 2 labels et un bouton dans un nouveau projet et colle ceci :
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
   Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
                                        ByVal childAfter As IntPtr, _
                                        ByVal lclassName As String, _
                                        ByVal windowTitle As String) As IntPtr
    End Function

    Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Const WM_GETTEXT As Integer = &HD

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Find the running notepad window
        Dim Hwnd As IntPtr = FindWindow(Nothing, "Calculatrice")

        'Alloc memory for the buffer that recieves the text
        Dim Handle As IntPtr = Marshal.AllocHGlobal(100)

        'send WM_GWTTEXT message to the notepad window
        Dim NumText As Integer = SendMessage(Hwnd, WM_GETTEXT, 50, Handle)

        'copy the characters from the unmanaged memory to a managed string
        Dim Text As String = Marshal.PtrToStringUni(Handle)

        'Display the string using a label
        Label1.Text = Text

        'Find the Edit control of the Running Notepad
        Dim ChildHandle As IntPtr = FindWindowEx(Hwnd, IntPtr.Zero, "Edit", Nothing)

        'Alloc memory for the buffer that recieves the text
        Dim Hndl As IntPtr = Marshal.AllocHGlobal(200)

        'Send The WM_GETTEXT Message
        NumText = SendMessage(ChildHandle, WM_GETTEXT, 200, Hndl)

        'copy the characters from the unmanaged memory to a managed string
        Text = Marshal.PtrToStringUni(Hndl)

        'Display the string using a label
        Label2.Text = Text

    End Sub

End Class
3
AirByte Messages postés 13 Date d'inscription mercredi 5 janvier 2011 Statut Membre Dernière intervention 25 février 2011
7 janv. 2011 à 16:46
hello

Je devrais pouvoir m'avancer en m'inspirant de ce code

merci!
0
Rejoignez-nous