FindWindowEx Problem

Phil
09-01-2000, 11:26 AM
Hi,
I have written two applications which I wish to have interact with one another. The method I have used is to send a string to a text box in the second application (app2) from the other (app1) using the WM_SETTEXT constant with the SendMessage function. When the textbox receives the text, I use the change event to utilise the string. The code in app1 to send the string is as below:

Dim MessStr As String
Dim retVal As Long
Dim hTxt1 As Long
Dim hApp2 As Long

MessStr = "Test Message"

'Check for App2 by searching for window with text "App2 Hidden"
hApp2 = FindWindow(CLng(0), "App2 Hidden")
If hApp2 = 0 Then
MsgBox "App2 Not Found!"
Exit Sub
End If

'If App2 Open Get handle for textbox on window
hTxt1 = FindWindowEx(hApp2, 0, "ThunderTextBox", CLng(0))
If hTxt1 <> 0 Then
retVal = SendMessage(hTxt1, WM_SETTEXT, ByVal CLng(0), ByVal MessStr)
If retVal = 0 Then
MsgBox "Message not Sent"
End If
Else
MsgBox "Textbox not found"
End If

The window "App2 Hidden" is a form in the second application which is loaded but not shown, the form contains only one control ie the textbox. My logic in the code above therefore is to look for this window if it is found then app2 is running, then I retrieve the handle to the textbox and happily send the text to it.

It appeared to work when I tested on the uncompiled app2 as soon as I made an exe of app2 the function failed returning 0 at the line

hTxt1 = FindWindowEx(hApp2, 0, "ThunderTextBox", CLng(0))

and therefore giving my error message "Textbox not found".

If anyone can suggest why this is happening and any hints how to overcome it, these will be very much appreciated.

Thanks, Phil

tezcanalinca
09-01-2002, 02:36 PM
Hi Phil,

Just replce CLng(0) with vbNullString as the last parameter and it should work:

hTxt1 = FindWindowEx(hApp2, 0, "ThunderTextBox", vbNullString)


Windows API is very pedantic !


Good Luck
Tez

Mathimagics
09-02-2002, 01:00 PM
A couple of observations.

1 You don't have to use "Clng(0)" to pass a zero to an API - if the parameter is declared "ByVal xxx As Long", you can just use "0"

2 It's not the FindWindowEx call arguments that is the problem - you can pass zero as either string, which is the equivalent of a NULL pointer in the API

3 But VB controls in an exe are different - for EXE's built with VB5, the correct name is ThunderRT5TextBox, and for VB6 it's ThunderRT6TextBox (Same applies to all VB Thunder classnames)

Dr Memory :cool:


hTxt1 = FindWindowEx(hApp2, 0, "ThunderRT6TextBox", ByVal 0)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum