Sending messages/keystrokes to a control in a different app
Posted: Wed Oct 20, 2004 12:25 pm
I am facing two problems:
1.
The handle of the control changes everytime the app is launched. For example, using Winspector I can find out that the Internet Explorer instance I am using to write this posting has a
ComboBox, handle $60344
Edit control, handle $5031C
Is there a way to figure out the handle dynamically?
2.
When using PB's sendkeys procedure
using the handles retrieved manually with Winspector, it seems to be ok (changing the handles gives me an error) and I can see the messages passed to the control, but nothing else happens - no visual feedback of what I typed.
Any clue?
Edit: Seems the control doesn't receive the messages despite what I said. It were messages from other actions on the control.
Edit2:
Has worked... leaves me mainly with question 1. And sorry for monolog! 
1.
The handle of the control changes everytime the app is launched. For example, using Winspector I can find out that the Internet Explorer instance I am using to write this posting has a
ComboBox, handle $60344
Edit control, handle $5031C
Is there a way to figure out the handle dynamically?
2.
When using PB's sendkeys procedure
Code: Select all
Procedure SendKeys(handle,window$,keys$)
If window$<>"" : handle=FindWindow_(0,window$) : EndIf ; Use window$ instead of handle.
If IsWindow_(handle)=0 ; Does the target window actually exist?
MessageRequester("Error","Window not open:"+Chr(10)+window$)
ProcedureReturn 0 ; Nope, so report 0 for failure to type.
Else
; This block gives the target window the focus before typing.
thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
thread2=GetWindowThreadProcessId_(handle,0)
If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#TRUE) : EndIf
; just a bit of the entire procedure posted
Any clue?
Edit: Seems the control doesn't receive the messages despite what I said. It were messages from other actions on the control.
Edit2:
Code: Select all
SendMessage_($5031C,#WM_SETTEXT ,0,"ABC")