|
-
Dec 1st, 2005, 03:40 PM
#1
Thread Starter
Frenzied Member
API Newbie
Ok, I've read all over in the FAQ's etc about API's but i dont understand what they do.
Is there a basic turtorial to get one of these running?
This is what i wanted to do:
Make a program in VB, that interacts with a terminal emulated program.
I wanted to be able to just type in a "Order number" hit "go or search" and it does all the functions like i was in the terminal program it self.
I wont be updating records etc, i just want the information out of the info.
Here is a screen shot.
-
Dec 5th, 2005, 11:08 AM
#2
Thread Starter
Frenzied Member
-
Dec 5th, 2005, 11:10 AM
#3
Re: API Newbie
You can execute a hidden shell and stream the output.
I used to do that with ping, it worked ok. I'll see if I can scrape together an example.
-
Dec 6th, 2005, 05:50 PM
#4
Frenzied Member
Re: API Newbie
I think this is what sevehalo meant...maybe:
VB Code:
Dim path As String = "C:\Program Files\Java\jdk1.5.0_05\bin"
Dim p As Process
p = New Process
p.StartInfo.CreateNoWindow = True
p.StartInfo.WorkingDirectory = path
p.StartInfo.Arguments = "HelloWorld"
p.StartInfo.FileName = "java.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.Start()
p.WaitForExit()
Dim io As String = p.StandardOutput.ReadToEnd()
Note: HelloWorld is a java program - filename HelloWorld.class
Whatever the output that shows up in the console is the string you end up with from the line: Dim io As String = p.StandardOutput.ReadToEnd()
If this isn't what you meant, then just ignore it.
-
Dec 7th, 2005, 03:14 PM
#5
Thread Starter
Frenzied Member
Re: API Newbie
Does anyone have an basic exmample of API used to get text from Note pad and display that text into a text box in the VB application?
Ive been trying to figure this out for days now. I tried the examples above but cant figure it out.
-
Dec 7th, 2005, 03:56 PM
#6
Frenzied Member
Re: API Newbie
this gets the text from an open notepad(make sure there are some text on the notepad so you can see a result)
VB Code:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public 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
Public 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
Public Const WM_GETTEXT = &HD
Private Sub proc()
Dim hwnd As Integer
Dim hwndEx As Integer
'gets handle of notepad
hwnd = FindWindow("Notepad", vbNullString)
'gets handle of 'edit' area of notepad
hwndEx = FindWindowEx(hwnd, vbNullString, "edit", vbNullString)
Dim len As Integer = 255
Dim buffer As String 'buffer will contain the text from notepad
buffer = Space(len)
'sends WM_GETTEXT message to 'edit' area of notepad
Dim x As Integer = SendMessage(hwndEx, WM_GETTEXT, len, buffer)
buffer = buffer.Substring(0, x)
End Sub
Last edited by benmartin101; Dec 7th, 2005 at 04:00 PM.
-
Dec 7th, 2005, 04:46 PM
#7
Thread Starter
Frenzied Member
Re: API Newbie
when i try that code i get these erros:
-
Dec 7th, 2005, 06:19 PM
#8
Frenzied Member
Re: API Newbie
that code is meant for vb.net. You are obviously using vb 6.0. To fix:
change all integers to 'long' type
On situation with Dim x as integer = 1; change to:
Dim x as integer
x = 1
And instead of using WM_GETTEXT, just substitute the value 13.
vb6 doesn't have .substring, you have to figure out how to do some string manipulation
-
Dec 7th, 2005, 06:31 PM
#9
Thread Starter
Frenzied Member
Re: API Newbie
 Originally Posted by benmartin101
that code is meant for vb.net. You are obviously using vb 6.0. To fix:
change all integers to 'long' type
On situation with Dim x as integer = 1; change to:
Dim x as integer
x = 1
And instead of using WM_GETTEXT, just substitute the value 13.
vb6 doesn't have .substring, you have to figure out how to do some string manipulation
I changed all that but i get errors:
Public const 13 = &HD
buffer = Space(len)
x = SendMessage(hwndEx, WM_GETTEXT, len, buffer)
**
Does anyone have a VB 6.0 basic api call to notepad to get the text and put it in a text box in the VB app?
Last edited by joefox; Dec 7th, 2005 at 06:37 PM.
-
Dec 7th, 2005, 07:28 PM
#10
Frenzied Member
Re: API Newbie
You misunderstood me on the 13 part. I meant, instead of using variablle WM_GETTEXT in one of the parameters, just put value 13.
make buffer = space(len) to buffer = " " make it 255 blank spaces.
-
Dec 8th, 2005, 09:47 AM
#11
Thread Starter
Frenzied Member
Re: API Newbie
Ok i hope i did this right, here is what i have, atleast it builds, but when i hit the button it dosent do anything":
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Long
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 Long
Public Sub proc()
Dim hwnd As Long
Dim hwndEx As Long
'gets handle of notepad
hwnd = FindWindow("Notepad", vbNullString)
'gets handle of 'edit' area of notepad
hwndEx = FindWindowEx(hwnd, vbNullString, "edit", vbNullString)
Dim x As Integer
x = 1
Dim buffer As String 'buffer will contain the text from notepad
buffer = " "
'sends WM_GETTEXT message to 'edit' area of notepad
Dim x As Integer
x = SendMessage(hwndEx, 13, buffer)
buffer = buffer.Substring(0, x)
Text1.Text = buffer
End Sub
-
Dec 8th, 2005, 06:37 PM
#12
Thread Starter
Frenzied Member
-
Dec 9th, 2005, 01:33 AM
#13
Frenzied Member
Re: API Newbie
I'm not sure if you're even looking at the sample code. Your sendmessage() only has 3 parameters, when the sample code shows 4.
-
Dec 9th, 2005, 09:58 AM
#14
Thread Starter
Frenzied Member
Re: API Newbie
I am looking at it, i dont know what values to pass into there.
That is why i posted in these forums.
I guess a simple API to notepad is turning into a nightmare.
-
Dec 9th, 2005, 07:51 PM
#15
Re: API Newbie
'You cant have public declares or public constants in form code
'You cant dim a var and assign it a value all at once
'len is a reserved word cant dim it as a var (all .NET stuff)
'buffer.Substring(0, x) more .NET
'In hwndEx = FindWindowEx(hwnd, vbNullString, "edit", vbNullString) you are passing the second param as a string, its looking for an Integer
'also placing the 'buffer' in the wrong param of sendmessage
So,
VB Code:
Option Explicit
Private Const WM_GETTEXT As Long = &HD
Private Const WM_GETTEXTLENGTH As Long = &HE
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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As String) As Integer
Private Sub Form_Load()
Dim hwnd As Integer
Dim hwndEx As Integer
Dim intlen As Integer
Dim buffer As String
hwnd = FindWindow("Notepad", vbNullString)
'gets handle of 'edit' area of notepad
hwndEx = FindWindowEx(hwnd, 0, "edit", vbNullString)
intlen = SendMessage(hwndEx, WM_GETTEXTLENGTH, 0, vbNullString)
buffer = Space$(intlen)
SendMessage hwndEx, WM_GETTEXT, intlen, ByVal buffer
MsgBox buffer
End Sub
Last edited by Jmacp; Dec 9th, 2005 at 11:58 PM.
-
Dec 12th, 2005, 12:07 PM
#16
Thread Starter
Frenzied Member
Re: API Newbie
Thanks for your help.
Ok i tried running the code, but it only puts blank values into the msgbox, and when i changed the code to put it into the text1 field, it just puts blank spots, and i have text in notepad.
VB Code:
Option Explicit
Private Const WM_GETTEXT As Long = &HD
Private Const WM_GETTEXTLENGTH As Long = &HE
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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As String) As Integer
Private Sub Command1_Click()
Dim hwnd As Integer
Dim hwndEx As Integer
Dim intlen As Integer
Dim buffer As String
hwnd = FindWindow("Notepad", vbNullString)
'gets handle of 'edit' area of notepad
hwndEx = FindWindowEx(hwnd, 0, "edit", vbNullString)
intlen = SendMessage(hwndEx, WM_GETTEXTLENGTH, 0, vbNullString)
buffer = Space$(intlen)
SendMessage hwndEx, WM_GETTEXT, intlen, ByVal buffer
Text1.Text = buffer
End Sub
-
Dec 12th, 2005, 02:21 PM
#17
-
Dec 12th, 2005, 03:55 PM
#18
Thread Starter
Frenzied Member
Re: API Newbie
 Originally Posted by Jmacp
works for me.
Weird, i can see it copies the text from Notepad, but they are just spaces when they are displayed in my VB app.
Do i need to include an references to anything?
Right now, i typed Hellocheckme on Notepad, I hit the button, and it puts however many spaces HelloCheckme is into the text field.
-
Dec 12th, 2005, 04:11 PM
#19
Re: API Newbie
Beats me then, just tried it again no probs, did you cut and copy the code ?
-
Dec 12th, 2005, 05:00 PM
#20
Thread Starter
Frenzied Member
Re: API Newbie
Yeah, i copy and cut the whole code, and added a textbox and button.
Its weird, it seems to work, but just puts blank spots in there. It does the correct amount of spots, just no text lol.
I tried to copy the blank spots out of the textbox and past them into work, and they are all blank spots.
-
Dec 12th, 2005, 07:58 PM
#21
Lively Member
Re: API Newbie
here, i think this might help
VB Code:
'declerations:
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
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Sub Command1_Click()
Dim notepad&, notepadedit&, num&, buff$, edittxt&
'--find the right windows--
notepad& = FindWindow("Notepad", vbNullString)
notepadedit& = FindWindowEx(notepad&, 0&, "Edit", vbNullString)
'--
'--create a buffer the length of the string that needs to be loaded
num& = SendMessageByNum(notepadedit&, 14, 0, 0&)
buff$ = Space$(num&)
'--
'--actually retrieve the text-
edittxt& = SendMessageByString(notepadedit&, 13, num& + 1, buff$)
Text1.text = buff$
End Sub
Last edited by si_the_geek; Dec 13th, 2005 at 12:08 PM.
Reason: added VBCode tags
-
Dec 13th, 2005, 10:10 AM
#22
Thread Starter
Frenzied Member
Re: API Newbie
OMG yes that worked, so what did we do different?
-
Dec 13th, 2005, 05:51 PM
#23
Lively Member
Re: API Newbie
i just declared the variables corretly really, but it was easier to write the code over than edit the other one. i added sendmessagebynum and sendmessagebystring, just because i use them to remember my different uses of the SendMessageA function in user32.dll. sendmessage, sendmessagebynum,and sendmessagebystring are all the same call.
Last edited by ghettohacker; Dec 13th, 2005 at 06:08 PM.
-
Dec 13th, 2005, 06:01 PM
#24
Thread Starter
Frenzied Member
Re: API Newbie
Thanks for the help, is there a way now i can get the text from this:
-
Dec 13th, 2005, 06:10 PM
#25
Lively Member
Re: API Newbie
if there is a will. there are several ways to do it though, is the window title caption always the same? does the classname change? i don't have that program so i don't know exactly what the best way to go about it would be. one must study its habbits
-
Dec 13th, 2005, 06:23 PM
#26
Thread Starter
Frenzied Member
Re: API Newbie
Yes, the name of the program stays that same, with those values.
I checked it a few times with Spy++
here is my code, i press the button but it dosent get anything:
Here is whats in my button click
VB Code:
Dim notepad&, notepadedit&, num&, buff$, edittxt&
'--find the right windows--
notepad& = FindWindow("PCSWS:Main:00400000", vbNullString)
notepadedit& = FindWindowEx(notepad&, 0&, "PCSWS:Pres:00400000", vbNullString)
'--
'--create a buffer the length of the string that needs to be loaded
num& = SendMessageByNum(notepadedit&, 14, 0, 0&)
buff$ = Space$(num&)
'--actually retrieve the text-
edittxt& = SendMessageByString(notepadedit&, 13, num& + 1, buff$)
Text1.Text = buff$
-
Dec 13th, 2005, 06:34 PM
#27
Lively Member
Re: API Newbie
sendmessage in this context is for edit controls, and that my friend isn't an edit control...its a pcws whatever it is, i'm not a very good teacher, i'd have to have the program, or else i'll be posting a code i think will work, instead of pressing run to find out.
-
Dec 13th, 2005, 06:37 PM
#28
Thread Starter
Frenzied Member
Re: API Newbie
Oh i thought this code would work in the same way the one with notepad did.
I figure i would just find the program, then copy all the text, and display in the box.
-
Dec 13th, 2005, 06:44 PM
#29
Lively Member
-
Jan 25th, 2006, 04:24 PM
#30
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|