Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with SendMessage and EXTRA! 6.4 in VB.net 1

Status
Not open for further replies.

Necromis

Technical User
Jun 15, 2007
14
US
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
 
Maybe I don't understand completely, but it appears that you're going about this the hard way. Check out this FAQ on how to pilot Extra using VB(A).

faq99-4069

Basically, you create an object that controls Extra. Then you can just send your string to anywhere in Extra that you need.

calculus
 
well that is fine to a degree. However the standard inputs for text, that I am aware of, in EXTRA are SendKeys and SendInput. SendKeys has to have focus and SendInput requires you not to be typing. These won't work in my case. How else would you send a batch of text to an extra session?
 
I don't know of any reason you wouldn't be able to use the Extra object in VB.Net. From there you can obtain the session and screen objects. With the screen object the PutString method is my preferred method to populate the screen. You can use the SendKeys method as well.

objScreen.PutString string, row, col
objScreen.SendKeys string
 
Skie, as I indicated in my previous post, sendkeyes won't work for my purposes. Also I have looked into putstring, but it does not seem to be within VB.net coding. Or I am not finding it at the least. I am looking for solutions within the vb.net framework to automate this process. If I hvae to I will just have to key them one key at a time thru keydown and keyup.
 
ok, I correct myself on this last post. I have found the options to make putstring work. However, now I am running into another issue. How do you define an option to select the session you wish to interact with when you have multiple sessions running? My code has been modified as below. Realize that some of this will go away but is all in the testing phaze. I just need to know how within vb.net to get it to reference the specific session rather than activesession. I have tried using session(1) and session("session1") to select a particular session but it errors out on me when I do it with anything other than active session.

Dim System As EXTRA.ExtraSystem
Dim Sessions As EXTRA.ExtraSessions
Dim Sess0 As EXTRA.ExtraSession
Dim MyScn As EXTRA.ExtraScreen

System = New EXTRA.ExtraSystem
Sessions = System.Sessions
Sess0 = System.ActiveSession
MyScn = Sess0.Screen


'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
MyScn.PutString(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
TextBox3.Text = System.ActiveSession.ToString
Else
'SendMessage(whwnd, WM_SETTEXT, 0&, comment)
End If
End Sub
 
Code:
Dim System As EXTRA.ExtraSystem
Dim Sessions As EXTRA.ExtraSessions
For i = 1 to Sessions.Count
  MsgBox Sessions.Item(i).Name
Next

I don't remember if sessions start at 0 or 1, so you may need to use an i-1 for the Item.
 
Sess0 = Sessions.ActiveSession is the easiest way to get the session the user is using.

calculus
 
I was able to find this option and it seems to work. I do appreciate all the help. Now I am able to send the input I need while having the session either minimized or hidden by changing its visible state to 0. Thanks everyone.

Code:
System = New EXTRA.ExtraSystem
        Sessions = System.Sessions
        Sess1 = Sessions.Open("C:\Program Files\EXTRA!\Sessions\session1.edp")
        MyScn1 = Sess1.Screen
        Sess2 = Sessions.Open("C:\Program Files\EXTRA!\Sessions\session2.edp")
        MyScn2 = Sess2.Screen
 
ok, one last question, hopefully. Using the code in the last post is fine for opening, but I am running into an issue when I try to close the sessions. I just need the command that would close all open sessions of Extra!. Thanks
 
This will close all.
Sessions.CloseAll

I'd think this would work if you wanted to close Extra too:
System.Quit
 
Great. That did it. I appreciate it. Now I have all the pieces of my code working properly and can actually put them all together to build my application. This will help me out tremendously. Thanks everyone for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top