GetText Client Access AS400 window API Help

C

clu

I am trying to get text from an AS400 session. I have tried many
different approaches from SendMessage to GetDlgItemText. I have
succeeded in using Edit Copy by customizing the keyboard in AS400 and
using API Keyboard events to copy the window to the clipboard and then
get the text using API clipboard calls. While this approach works I am
determined to avoid the windows clipboard and to get the text by some
other means that will avoid having to map the keyboard and use the
windows clipboard.

After searching and testing solutions found in the groups I decided to
ask for help. I have successfully used the code below to get text from
notepad but when trying it with Client Access AS400 window I get a
value of 1 for text length and null for text. I am able to get the
handle for the parent and the child window. I am more interested in
this as an exercise to understand how to use API calls to get the text
that is displayed in this window as my original code works well. This
understanding of how to retrieve text from this window will assist me
in getting text from other child windows that are inaccessible from the
edit copy command.

Thank you in advance.

Option Explicit
Private Declare Function GetDlgItemText Lib "user32" Alias
"GetDlgItemTextA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As
String, _
ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
_
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
lParam As Any) As Long
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD

Sub GetTextTest()
Dim mlngHandle As Long
Dim mlngRetVal As Long
Dim mstrBuf As String
mlngHandle = FindWindow("PCSWS:Main:00400000", vbNullString)
If mlngHandle <> 0 Then
mstrBuf = String(1024, 0)
MsgBox mstrBuf
mlngRetVal = GetDlgItemText(mlngHandle, 2, mstrBuf, 1023)
If mlngRetVal > 0 Then
mstrBuf = Left$(mstrBuf, mlngRetVal)
Debug.Print mstrBuf
End If
End If
End Sub

Sub GetTextTest2()
Dim mlngHandle As Long
Dim mlngRetVal As Long
Dim mstrText As String
'
mlngHandle = FindWindowEx(FindWindow("PCSWS:Main:00400000",
vbNullString), 0, "PCSWS:pres:00400000", vbNullString) 'handle for
text window
mlngRetVal = SendMessage(mlngHandle, WM_GETTEXTLENGTH, 0&, ByVal
0&) + 1
Debug.Print mlngRetVal
'
If mlngRetVal > 0 Then 'there is text
mstrText = Space$(mlngRetVal)
Debug.Print mstrText
mlngRetVal = SendMessage(mlngHandle, WM_GETTEXT, mlngRetVal,
ByVal mstrText)
mstrText = Left(mstrText, mlngRetVal)
Debug.Print "-" & mstrText & "-"
MsgBox "-" & mstrText & "-"
End If
End Sub
 
G

Guest

if you can access text from mote[pad then presumably there's a text file
somewhere? Why don't you just import the text file or read the data from
it... see the "OPEN" method in help
 
C

clu

Patrick said:
if you can access text from mote[pad then presumably there's a text file
somewhere? Why don't you just import the text file or read the data from
it... see the "OPEN" method in help

Patrick,

Thank you for your response. It appears I was unclear or am unclear as
to your reply. The code, which I found in this group, works with the
Edit window of Notepad to get text in that window by using its Handle.

The AS400 window displays text that I can copy both manually and with
code. I tried using the same approach (using posted code) to get the
text from the AS400 window (which I have the handle) as I did with
Notepad without success. The Client Access has two processes running
pcscm.exe and pcsws.exe. I don't know which way to go from here and
was hoping to get some direction if not a solution. I am relatively
new to API but I believe it is my lack of understanding of how text is
displayed in this window that has me at a stand still. If anyone has
information on how data is transferred and displayed in a terminal
emulator or can point me to such information I would appreciate it.

I am hoping that the text can be retrieved easy enough and I am just
using the wrong API Function. When I use this code on the Main window I
do successfully get the Text in that window which is the Title. Since
the window that contains the text I wish to get has no title and that
is what I get "nothing" I feel I am using the wrong API call.

Thanks again for any assistance.
 
P

Patrick Molloy

hi
it sounds like you're doing it the hard way. Your AS400 can as easily dump
the text to a text file, and if you use a timestamp in the name, you'll
build up a log of files for record keeping or audit. whatever. once you have
a text file, its real easy to import it into excel without resorting to
horrendous API calls.


clu said:
Patrick said:
if you can access text from mote[pad then presumably there's a text file
somewhere? Why don't you just import the text file or read the data from
it... see the "OPEN" method in help

Patrick,

Thank you for your response. It appears I was unclear or am unclear as
to your reply. The code, which I found in this group, works with the
Edit window of Notepad to get text in that window by using its Handle.

The AS400 window displays text that I can copy both manually and with
code. I tried using the same approach (using posted code) to get the
text from the AS400 window (which I have the handle) as I did with
Notepad without success. The Client Access has two processes running
pcscm.exe and pcsws.exe. I don't know which way to go from here and
was hoping to get some direction if not a solution. I am relatively
new to API but I believe it is my lack of understanding of how text is
displayed in this window that has me at a stand still. If anyone has
information on how data is transferred and displayed in a terminal
emulator or can point me to such information I would appreciate it.

I am hoping that the text can be retrieved easy enough and I am just
using the wrong API Function. When I use this code on the Main window I
do successfully get the Text in that window which is the Title. Since
the window that contains the text I wish to get has no title and that
is what I get "nothing" I feel I am using the wrong API call.

Thanks again for any assistance.
 
C

clu

Actually the API calls have not been so horrendous. I have been able
to replace all internal Excel VBA commands for this project without too
much trouble. The last bit is this get text part. I don't need to get
the text in a text file I want to put the text in a variable at runtime
in my excel vba code directly. I already use the clipboard with
success. I have tested SendMessage, GetDlgItemText, GetWindowText,
SetWindowText and have been able to set the text and retrieve it with
these functions but I am not able to get the text from the screen.
When I use wm_SetText or SetWindowText it changes the Title of the
child window. I am then able to get that text. From what I have read
elsewhere in the Groups this indicates that the window is accepting
these commands. The text window may have hidden windows which I
understand slightly after searching the Groups/Web but I am not sure
how to proceed to learn more about this. I used EnumWindows to
retrieve the following results of my open session. Note the Title
"Hello, world!" which was placed there by one of my SetText tests. I
also included info that I retreived from a GUIi Spy Tool. I feel like
I am close but frustrated because I am unclear as to how to proceed.

LEV. CLASSNAME HANDLE PARENT TITLE
0 PCSWS:Main:00400000 590504 0 AS400
1 msctls_statusbar32 656032 590504
1 PCSWS:Oia:00400000 656034 590504
1 PCSWS:Hsb:00400000 656036 590504
1 PCSWS:pres:00400000 525212 590504 Hello, world!
1 UCMBrkr 524982 590504
2 UCMenu 525008 524982
3 ScrollBar 2360176 525008
4 Hide 787228 2360176
5 MenuToolBar 524984 787228
6 ToolbarWindow32 590526 524984

This is the window information that contains text I wish to get!

{displayed: 1,width: 960,x: 36,y: 119,abs_x: 32,class:
object,MSW_class: "PCSWS:pres:00400000",abs_y: 115,maximizable:
0,focused: 0,height: 577,active: 0,MSW_id: 2,handle:
525212,minimizable: 0,nchildren: 0,label: "Hello, world!",enabled:
1,TOOLKIT_class: "PCSWS:pres:00400000"}

I have also come across information regarding HLLAPI

Declare Function hllapi& Lib "PCSHLL32.DLL" (Func&, ByVal DataString$,
Length&, RetC&)

This API is provided by IBM and requires an install I believe.

Any suggestions would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top