Need help interacting with non-VB apps

greenspun.com : LUSENET : MW Software's Visual BASIC Descusion System : One Thread

I'm creating a VB app that interacts with another (non-VB/Microsoft) app called ACSA. But right now I'm just testing everything with Notepad. I haven't had any experience with API functions which is why I'm having a hard time figuring this thing out. Anyway, I was able to figure out how to interact with the other applications using their menu commands but my problem is that I want to be able to send text strings to their windows and I can't seem to figure out how to do it.

I tried: Dim winWnd As Long

winWnd = FindWindow(vbNullString, "Untitled - Notepad") Call SendMessageByString(winWnd, WM_SETTEXT, 0, "test")

This code only seems to change the title of the document. Do I have to include the handle for the text box/Rich textbox for Notepad in order to get the string "test" in the text field? If this is the case how would I go about getting the handle for that field?

I also tried:

Private Type COPYDATASTRUCT dwData As Long cbData As Long lpData As Long End Type

Private Const WM_COPYDATA = &H4A Private Declare Function FindWindow Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName _ As String) 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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Sub Command1_Click() Dim cds As COPYDATASTRUCT Dim ThWnd As Long Dim buf(1 To 255) As Byte

' Get the hWnd of the target application ThWnd = FindWindow(vbNullString, "Target") a$ = "It Works!" ' Copy the string into a byte array, converting it to ASCII Call CopyMemory(buf(1), ByVal a$, Len(a$)) cds.dwData = 3 cds.cbData = Len(a$) + 1 cds.lpData = VarPtr(buf(1)) i = SendMessage(ThWnd, WM_COPYDATA, Me.hwnd, cds) End Sub

Private Sub Form_Load() ' This gives you visibility that the target app is running ' and you are pointing to the correct hWnd Me.Caption = Hex$(FindWindow(vbNullString, "Target")) End Sub

But this only seems to work if you have another VB app with coding behind it to recieve the string.

So now I don't know what I'm doing wrong, or if I'm on the right track. Right now I'm just stumped can't can't think of anything else to do.

Thanks

-- Jenn (jagas@hertz.com), August 18, 1999


Moderation questions? read the FAQ