Hallo GPM
das Demo2 gefällt mir super. Bin gerade ein bisschen am spielen.
Hab den Button enfernt. Der war ja nur zum testen.
Jetzt schaude der Code so aus
Imports System.Runtime.InteropServices, System.Text
Public Class Form1
Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal _
Msg As Int32, ByVal wParam As Int32, ByVal lParam As StringBuilder) As _
Int32
Declare Function EnumChildWindows Lib "user32" (ByVal hWnd As IntPtr, ByVal _
Callback As EnumWinProc, ByVal lParam As IntPtr) As Boolean
Declare Function GetForegroundWindow Lib "user32" () As IntPtr
'Private WithEvents Btn As New Button With {.Dock = DockStyle.Bottom, .Text
' = "MsgBox-Show", .Parent = Me}
Private WithEvents T As New Timer With {.Interval = 1000}
Delegate Function EnumWinProc(ByVal hWnd As IntPtr, ByVal Param As IntPtr) _
As Boolean
Const WM_GETTEXT As Int32 = &HD
'Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As _
' System.EventArgs) Handles Btn.Click
' T.Start()
' MessageBox.Show("Die Nummer (001315) ist gemeldet", "Info", _
' MessageBoxButtons.OK, MessageBoxIcon.Stop)
' End Sub
Private Sub T_Tick(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles T.Tick
Dim hfw = GetForegroundWindow
If hfw <> Me.Handle Then
Dim sb As New StringBuilder(256)
SendMessage(hfw, WM_GETTEXT, sb.Capacity, sb)
If sb.ToString = "Info" Then
Dim hnd() = GetChildWindows(hfw) 'Demo= 4, 2x Btn + Icon + Text
SendMessage(hnd(3), WM_GETTEXT, sb.Capacity, sb)
Dim txt As String = sb.ToString.Split("("c, ")"c)(1)
SendKeys.Send("{Enter}")
'Me.Text = txt 'bzw My.Computer.Clipboard.SetText(txt)
My.Computer.Clipboard.SetText(txt)
End If
End If
End Sub
Private Function GetChildWindows(ByVal hnd As IntPtr) As IntPtr()
Dim childlist As New List(Of IntPtr), gh = GCHandle.Alloc(childlist)
EnumChildWindows(hnd, AddressOf EnumWindows, GCHandle.ToIntPtr(gh))
gh.Free()
Return childlist.ToArray
End Function
Private Function EnumWindows(ByVal Handle As IntPtr, ByVal param As IntPtr) _
As Boolean
Dim ptrlist = CType(GCHandle.FromIntPtr(param).Target, List(Of IntPtr))
ptrlist.Add(Handle)
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
T.Start()
End Sub
End Class Leider bleibt er in dieser Zeile hängen
SendMessage(hnd(3), WM_GETTEXT, sb.Capacity, sb) IndexOutOfRangeException wurde nicht behandelt.
Wie bekomme ich diesen fehler noch weg ?
Mfg |