findwindowEX Send Message in Child of a Child of an Application
findwindowEX Send Message in Child of a Child of an Application
First:
- my english is very bad (german)
- i am a newby of Visual Basic
My Form with SQL-Integration is sending Data per Button to Notepad sucessfull. Unfortunately, the purpose application has interlocking children.
But the application don´t become the data. i need help to found a solution / or a Idear. i think i put in screenshots an my code:
Code:
Public Class Form1
'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim ListBox1 As ListBox.ObjectCollection
' Dim i As Long
' TextBox1.Text = ""
' With ListBox1.ToString()
' For i = 0 To .Count - 1
' TextBox1.Text = TextBox1.Text & .Item(i) & vbCrLf
' Next i
' End With
'End Sub
'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim i As Long
'TextBox1.Text = ""
'For i = 0 To ListBox1.Items.Count - 1
' TextBox1.Text = TextBox1.Text & ListBox1.Items.ToString(i) & vbCrLf
'Next i
'End Sub
'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' TextBox1.Text = ListBox1.Text.ToString
'End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Const WM_SETTEXT = &HC
Private Const WM_GETTEXT = &HC
Private Const WM_KEYDOWN = &H100
Private Const VK_RETURN = &HD
'Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Any) As Integer
Dim CobraMain As Integer
Dim MClient As Integer
Dim adl As Integer
Dim AfxFrameOrView70 As Long
Dim AfxWnd70 As Integer
Dim F00040F22 As Integer
Dim SysTabControl32 As Integer
Dim F00580F76 As Integer
Dim F00040EC0 As Integer
Dim F00040EBC As Integer
Dim F00040EBE As Integer
Dim F00060F00 As Integer
Dim F00060EE8 As Integer
Dim AfxMDIFrame70 As Integer
Dim F00030EAC As Integer
Dim F00070ED0 As Integer
Dim F000B0EF2 As Integer
Dim F00040ECA As Integer
Dim F00060F0C As Integer
Dim Projekte As Integer
Dim RichEdit20A As Integer
'call them
Private Sub ListBox1_onClick()
'Wert der 1ten Spalte der selektierten Zeile in Textbox1 schreiben
TextBox1.Text = ListBox1.Text.ToString
'Wert der 2ten Spalte der selektierten Zeile in Textbox2 schreiben
'WIE???? So übernimmte es bislang auch nur den selben wert wie in TextBox1
'Irgendwie muss man doch an die 2te Spalte ran kommen?
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: Diese Codezeile lädt Daten in die Tabelle "_K_ProjekteDataSet.ADDRESSES". Sie können sie bei Bedarf verschieben oder entfernen.
Me.ADDRESSESTableAdapter.Fill(Me._K_ProjekteDataSet.ADDRESSES)
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.Text.ToString
End Sub
Private Sub BindingSource1_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TEXT29_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TEXT29.CurrentChanged
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = ListBox2.Text.ToString + 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CobraMain = FindWindow("COBRAMain", vbNullString)
'MClient = FindWindowEx(CobraMain, 0&, "msctls_statusbar32", vbNullString)
'CobraMain = FindWindow("COBRAMain", vbNullString)
MClient = FindWindowEx(CobraMain, 0&, "MDIClient", vbNullString)
adl = FindWindowEx(MClient, 0&, "AfxFrameOrView70", vbNullString)
AfxFrameOrView70 = FindWindowEx(adl, 0&, "AfxFrameOrView70", vbNullString)
AfxWnd70 = FindWindowEx(AfxFrameOrView70, 0&, "AfxWnd70", vbNullString)
F00040F22 = FindWindowEx(AfxWnd70, 0&, "AfxFrameOrView70", vbNullString)
SysTabControl32 = FindWindowEx(F00040F22, 0&, "SysTabControl32", vbNullString)
F00580F76 = FindWindowEx(SysTabControl32, 0&, "AfxFrameOrView70", vbNullString)
F00040EC0 = FindWindowEx(F00580F76, 0&, "AfxFrameOrView70", vbNullString)
F00040EBC = FindWindowEx(F00040EC0, 0&, "AfxFrameOrView70", vbNullString)
F00040EBE = FindWindowEx(F00040EBC, 0&, "AfxFrameOrView70", vbNullString)
F00060F00 = FindWindowEx(F00040EBE, 0&, "AfxFrameOrView70", vbNullString)
F00060EE8 = FindWindowEx(F00060F00, 0&, "AfxFrameOrView70", vbNullString)
AfxMDIFrame70 = FindWindowEx(F00060EE8, 0&, "AfxMDIFrame70", vbNullString)
F00030EAC = FindWindowEx(AfxMDIFrame70, 0&, "AfxFrameOrView70", vbNullString)
F00070ED0 = FindWindowEx(F00030EAC, 0&, "AfxFrameOrView70", vbNullString)
F000B0EF2 = FindWindowEx(F00070ED0, 0&, "AfxFrameOrView70", vbNullString)
F00040ECA = FindWindowEx(F000B0EF2, 2&, "AfxFrameOrView70", vbNullString)
F00060F0C = FindWindowEx(F00040ECA, 2&, "AfxFrameOrView70", vbNullString)
Projekte = FindWindowEx(F00060F0C, 0&, "Button", vbNullString)
RichEdit20A = FindWindowEx(MClient, 0&, "RichEdit20A", vbNullString)
SendMessageByString(RichEdit20A, WM_SETTEXT, 0, TextBox2.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub
End Class
Re: findwindowEX Send Message in Child of a Child of an Application
Work it the other way around. Get WinID for a quicker handle reference if you wish. Then manually use the current handle of the last parent to check if the code actually returns the handle of RichEdit20A.
Code:
Private Declare Auto Function FindWindowEx Lib "user32" _
(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _
ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
'2055E was the handle from the screenshot, replace it with the current one
Dim ImportantHandle As IntPtr
ImportantHandle = FindWindowEx(New IntPtr(&H2055E), IntPtr.Zero, "RichEdit20A", "210036")
Dim Result As String
Result = System.Convert.ToString(ImportantHandle.ToInt32, 16)
MessageBox.Show(ImportantHandle.ToString)
Re: findwindowEX Send Message in Child of a Child of an Application
Most of the time it should work but let's try something else. Right click the RichEdit20A window in Spy++, select Properties and tell me what the Control ID is. It is in the General tab.
Re: findwindowEX Send Message in Child of a Child of an Application
This is going to be hard. See if you can get all the handles and if they change position between starts of the software. It would be better if you create a new project for testing.
Code:
Imports System.Runtime.InteropServices
Private Declare Auto Function FindWindowEx Lib "user32" _
(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _
ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
Private Declare Auto Function EnumChildWindows Lib "user32" _
(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, _
ByVal lParam As IntPtr) As Boolean
Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, _
ByVal Parameter As IntPtr) As Boolean
Public Shared 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
Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
Dim ChildrenList As List(Of IntPtr) = CType(GCHandle.FromIntPtr(Parameter).Target, Global.System.Collections.Generic.List(Of Global.System.IntPtr))
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim MainHandle As IntPtr
MainHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "COBRAmain", Nothing)
Dim ChildHandles() As IntPtr = GetChildWindows(MainHandle)
For i As Integer = 0 To ChildHandles.Length - 1
ListBox1.Items.Add(i & ": " & System.Convert.ToString(ChildHandles(i).ToInt32, 16))
Next
End Sub