Wie kann ich mit VB.Net Eigenschaften von Steuerelementen abrufen, die in einem Popup-Meldungsfeld enthalten sind?

Ich arbeite an einemVB.Net Projekt, in dem in einem Teil davon ein Popup-Meldungsfeld angezeigt und auf irgendeine Weise behandelt wird. Mein Problem ist, dass ich wissen muss, welche Schaltflächen in diesem Popup-Fenster enthalten sind (hauptsächlich deren Beschriftungen). Ist das möglich? Kann mir bitte jemand sagen, wie das geht? Eine Probe wäre sehr dankbar.

Vielen Dank.

Update: Da ich eine Ablehnung bekommen habe und Ed Cottrell mir sagte, dass dies daran liegt, dass ich keinen Code zu meiner Frage hinzufüge. Jetzt habe ich die Antwort auf meine Frage und füge folgenden Code hinzu:

Meine App fängt ein Popup-Fenster ab, das von einer anderen Windows-Anwendung angezeigt wird, die ich verwendet habeEnumWindows API, um zu erfahren, wann ein neues Popup-Fenster angezeigt wird.

Public Declare Function EnumWindows Lib "User32.dll" (ByVal WNDENUMPROC As EnumWindowDelegate, ByVal lparam As IntPtr) As Boolean
Delegate Function EnumWindowDelegate(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean

Wenn ich dieses Fenster abfange, verwende ich dessen Handle, das ich aus dem EnumWindows-Ergebnis erhalten habe, und verwende dessen untergeordnete FensterEnumChildWindows (Was sind die Steuerelemente, die ich suche, da Steuerelemente auch eine Art Fenster sind):

APIs, die ich verwendet habe

    <DllImport("User32.dll")> _
    Public Function EnumChildWindows _
        (ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, _
        ByVal lParam As IntPtr) As Boolean
    End Function

    Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

' Get window text length signature.
Public Declare Function SendMessage _
 Lib "user32" Alias "SendMessageA" _
 (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

' Get window text signature.
Public Declare Function SendMessage _
 Lib "user32" Alias "SendMessageA" _
 (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As StringBuilder) As Int32

Struktur ApiWindow

Public Structure ApiWindow
    Public MainWindowTitle As String
    Public ClassName As String
    Public hWnd As Int32
End Structure

Funktionen

Public Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
    Dim ChildrenList As New List(Of IntPtr)
    Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
    Try
        EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
    Finally
        If ListHandle.IsAllocated Then ListHandle.Free()
    End Try
    Return ChildrenList.ToArray
End Function

Public Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
    Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target
    If ChildrenList Is Nothing Then Throw New Exception("GCHandle Target could not be cast as List(Of IntPtr)")
    ChildrenList.Add(Handle)
    Return True
End Function

Wenn ich nun das Handle des Popup-Fensters (parentHandle) habe, kann ich dessen untergeordnete Fenster erhalten:

Dim hndls() As IntPtr = GetChildWindows(parentHandle)
Dim window As ApiWindow

For Each hnd In hndls
    window = GetWindowIdentification(hnd)
    'Add Code Here 
Next

Wo GetWindowIdentification ist:

''' <summary>
''' Build the ApiWindow object to hold information about the Window object.
''' </summary>
Public Function GetWindowIdentification(ByVal hwnd As Integer) As ApiWindow

    Const WM_GETTEXT As Int32 = &HD
    Const WM_GETTEXTLENGTH As Int32 = &HE

    Dim window As New ApiWindow()

    Dim title As New StringBuilder()

    ' Get the size of the string required to hold the window title.
    Dim size As Int32 = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)

    ' If the return is 0, there is no title.
    If size > 0 Then
        title = New StringBuilder(size + 1)

        SendMessage(hwnd, WM_GETTEXT, title.Capacity, title)
    End If

    ' Set the properties for the ApiWindow object.
    window.MainWindowTitle = title.ToString()
    window.hWnd = hwnd

    Return window

End Function

Antworten auf die Frage(1)

Ihre Antwort auf die Frage