I am running into an issue with my code. Here is the issue and strange part of it. It is accepting sendmessage when I use the WM_KEYDOWN/UP commands. However, when I use WM_SETTEXT to send my string it is not imputing the string to the session window. Does anyone know why an app would work with one SendMessage command and not another, and possibly a work around on this? I have a thought to a solution, but dread the implications of trying to make it. I would have to use a select case scenario for each of the letters, numbers 0-9 and for some of the characters like the *. Then I would have to send the text one key at a time. As you could imagine that would be a lot of coding and overkill. Below is my code as it stands so far. This is my testing phase and each piece as it is resolved will be ported into my final project to create the app. I need a way of running batches of text strings in a session w/o EXTRA! having focus. I know this is possible due to another application within our company sending data in the background already. However that code is written in delphi and I code in VB.net
Public Class Form1
Private Declare Function SendMessage 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 FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName 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 MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
(ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Const WM_SETTEXT = &HC
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD
Dim whwnd As Integer
Dim hwnd_box As Integer
Dim comment As String
comment = TextBox1.Text
whwnd = FindWindow(vbNullString, "SESSION1 - EXTRA! for NetWare")
hwnd_box = FindWindowEx(whwnd, 0, vbNullString, vbNullString)
If hwnd_box <> 0 Then
SendMessage(hwnd_box, WM_SETTEXT, 0, comment)
Threading.Thread.Sleep(500)
SendMessage(hwnd_box, WM_KEYDOWN, VK_RETURN, 0)
SendMessage(hwnd_box, WM_KEYUP, VK_RETURN, 0)
'this is just to verify that I am catching the child handle
TextBox2.Text = hwnd_box
Else
SendMessage(whwnd, WM_SETTEXT, 0&, comment)
End If
End Sub
End Class
Public Class Form1
Private Declare Function SendMessage 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 FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName 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 MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
(ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Const WM_SETTEXT = &HC
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD
Dim whwnd As Integer
Dim hwnd_box As Integer
Dim comment As String
comment = TextBox1.Text
whwnd = FindWindow(vbNullString, "SESSION1 - EXTRA! for NetWare")
hwnd_box = FindWindowEx(whwnd, 0, vbNullString, vbNullString)
If hwnd_box <> 0 Then
SendMessage(hwnd_box, WM_SETTEXT, 0, comment)
Threading.Thread.Sleep(500)
SendMessage(hwnd_box, WM_KEYDOWN, VK_RETURN, 0)
SendMessage(hwnd_box, WM_KEYUP, VK_RETURN, 0)
'this is just to verify that I am catching the child handle
TextBox2.Text = hwnd_box
Else
SendMessage(whwnd, WM_SETTEXT, 0&, comment)
End If
End Sub
End Class