EDN Admin
Well-known member
I Have a an C# application which needs to send Ruby commands to The Ruby Console window in Skecthup + read back what Sketchup anwers to that command. But i cant get this rigth... Found some code and tried that.
I get a handle to that window, but the call<span style="font-size:small
<span style="font-size:small <span style="font-size:small GetClassName(hWndParent, Buffer, Len(Buffer))
<span style="font-size:small <span style="font-size:small
rises the error "A call to PInvoke function library_2! has unbalanced the stack"
I presume this was not the way of doing it then....
Any who can tell me how to manage to send + retrive text from the Ruby console window?
Bet regards
Hans
------------------------------
Friend Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal funcCallBack As funcCallBackChild, ByVal lParam As IntPtr) As Boolean
Public Delegate Function funcCallBackChild(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Public TextBoxStrings As ArrayList = New ArrayList
Public Sub ParseWindowControls(ByVal WindowTitle As String)<br/>
Dim hWnd As IntPtr = FindWindow(vbNullString, WindowTitle)<br/>
TextBoxStrings.Clear()<br/>
If hWnd Then<br/>
Form4.TextBox2.Text = Form4.TextBox2.Text & vbCrLf
Dim MyCallBack As New funcCallBackChild(AddressOf EnumChildWindowsProc)<br/>
EnumChildWindows(hWnd, MyCallBack, IntPtr.Zero)<br/>
Else<br/>
MsgBox("Could not find window!", vbOKOnly + vbExclamation, "Error")<br/>
End If<br/>
End Sub
Private Function EnumChildWindowsProc(ByVal hWndParent As IntPtr, ByVal lParam As IntPtr) As Boolean<br/>
Dim Buffer As String = Space(256 * 1024)<br/>
Dim Retval As Long = GetClassName(hWndParent, Buffer, Len(Buffer))<br/>
If Left(Buffer, Retval) = "WindowsForms10.EDIT.app.0.218f99c" Then<br/>
TextBoxStrings.Add(GetText(hWndParent))<br/>
End If<br/>
<br/>
EnumChildWindowsProc = True<br/>
End Function
Private Function GetText(ByVal hwnd As IntPtr) As String<br/>
Dim sText As String = Space(1024)<br/>
If SendMessageTimeoutString(hwnd, &HD, 1024, sText, &H2, 1000, 0) <> 0 Then<br/>
GetText = Left(sText, InStr(sText, vbNullChar) - 1)<br/>
Exit Function<br/>
End If<br/>
GetText = ""<br/>
End Function
End Module
View the full article
I get a handle to that window, but the call<span style="font-size:small
<span style="font-size:small <span style="font-size:small GetClassName(hWndParent, Buffer, Len(Buffer))
<span style="font-size:small <span style="font-size:small
rises the error "A call to PInvoke function library_2! has unbalanced the stack"
I presume this was not the way of doing it then....
Any who can tell me how to manage to send + retrive text from the Ruby console window?
Bet regards
Hans
------------------------------
Friend Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal funcCallBack As funcCallBackChild, ByVal lParam As IntPtr) As Boolean
Public Delegate Function funcCallBackChild(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Public TextBoxStrings As ArrayList = New ArrayList
Public Sub ParseWindowControls(ByVal WindowTitle As String)<br/>
Dim hWnd As IntPtr = FindWindow(vbNullString, WindowTitle)<br/>
TextBoxStrings.Clear()<br/>
If hWnd Then<br/>
Form4.TextBox2.Text = Form4.TextBox2.Text & vbCrLf
Dim MyCallBack As New funcCallBackChild(AddressOf EnumChildWindowsProc)<br/>
EnumChildWindows(hWnd, MyCallBack, IntPtr.Zero)<br/>
Else<br/>
MsgBox("Could not find window!", vbOKOnly + vbExclamation, "Error")<br/>
End If<br/>
End Sub
Private Function EnumChildWindowsProc(ByVal hWndParent As IntPtr, ByVal lParam As IntPtr) As Boolean<br/>
Dim Buffer As String = Space(256 * 1024)<br/>
Dim Retval As Long = GetClassName(hWndParent, Buffer, Len(Buffer))<br/>
If Left(Buffer, Retval) = "WindowsForms10.EDIT.app.0.218f99c" Then<br/>
TextBoxStrings.Add(GetText(hWndParent))<br/>
End If<br/>
<br/>
EnumChildWindowsProc = True<br/>
End Function
Private Function GetText(ByVal hwnd As IntPtr) As String<br/>
Dim sText As String = Space(1024)<br/>
If SendMessageTimeoutString(hwnd, &HD, 1024, sText, &H2, 1000, 0) <> 0 Then<br/>
GetText = Left(sText, InStr(sText, vbNullChar) - 1)<br/>
Exit Function<br/>
End If<br/>
GetText = ""<br/>
End Function
End Module
View the full article