PDA

View Full Version : ThinBasic - active window or application?



CARLO
15-12-2009, 17:40
Hello,

I just started programming in ThinBasic (this morning).
I need to send some keys to an active window; specifically, select a menu item to simulate a user clicking or choosing "Save" and then "Text File", before specifying a Path+filename in the opening dialog (and confirming with Enter).

This is what I currently do using autoHotkey, with its own problems though and that's why I am recoding in ThinBasic. Coding last ThinBasic version, running from ThinAir 1.7.7.0.

Two questions:
1. {AppActivate WindowName} and Win_SetForeground: how do they differ?
I would expect a window in the foreground 'active' and able to receive sendkeys?


2. Offending portion of the code: Sendkeys(%V, 200)
ERROR: "Missing Close Parens ')'. Expected a ')' but found something else"

Sendkeys(%V) OR SENDKEYS({ALT}V) OR : SENDKEYS({%V})
ERROR: Missing Close Parens ')'. Expected a ')' but found something else.

What is the correct syntax?

3. I am saving into an array the window handles of the several instances of a program I launch. However, even if I do not get errors, the attempt to display the handles fails, even if it seems it is possible to reference them with the array:

FOR k=1 to Ntimes
OS_ShellExecute("open", "DSO2300.exe", "", "C:\Program Files\EMBEST\software\", 4)
Sendkeys(sleep(2000)) ' for now: we give time to press enter when in demo mode
NEXT

if (Win_Get(WArray, %WIN_GET_HWND, TitleExpr , %TRUE))=0 then ' save the number and names of DSO wins opened
{
MsgBox (0, "No elem?)"
}
end if

FOR k=1 to Ntimes
MsgBox (0, "element: ", WArray(k)) ' show them
NEXT

hWind=Win_FindByTitle("Embest",%WIN_FindTitleStart)

'Win_SetForeground(hWind) ' this works
Win_SetForeground(WArray(2)) ' it also works

So several questions!
I assume this is the right place to post, if not, apologies, I registered today.

Many thanks for your replies.

Petr Schreiber
15-12-2009, 18:22
Hi Carlo,

and welcome to the forums!

1) These two should be equivalent

2) As help file says, the first parameter is string, so the correct syntax would be:


SendKeys("%V", 200)


The double quotes are essential.

3) Here I was not able to follow you, but let me note that you don't have to use curly prackets in the IF/ENDIF.
What do you mean by "the attempt to display the handles fails".

It seems that you passed the window handle instead of style parameter of the msgbox (move cursor at msgbox and hit F1 to see the help topic).

It should be:


FOR k=1 to Ntimes
MsgBox (0, "element: "+FORMAT$(WArray(k))) ' show them
NEXT


Petr

ErosOlmi
15-12-2009, 18:33
Hi Carlo and welcome in thinBasic community.

Sorry, not much time to reply at the moment (I'm at work, I will have more time later this evening CET) but Petr already gave some tricks.

Please check attached file for a SendKeys examples that opens and drive an Internet Explorer session.
It may help you.

Ciao
Eros

CARLO
15-12-2009, 18:57
Dear Petr,
thank you for your help, much appreciated.



Hi Carlo,

and welcome to the forums!

1) These two should be equivalent

2) As help file says, the first parameter is string, so the correct syntax would be:


SendKeys("%V", 200)


The double quotes are essential.

Sendkeys: I was misled by the curly brackets, like in {Enter} etc :roll:


3) Here I was not able to follow you, but let me note that you don't have to use curly prackets in the IF/ENDIF.
What do you mean by "the attempt to display the handles fails".

It seems that you passed the window handle instead of style parameter of the msgbox (move cursor at msgbox and hit F1 to see the help topic).

It should be:


FOR k=1 to Ntimes
MsgBox (0, "element: "+FORMAT$(WArray(k))) ' show them
NEXT

Thanks, in effect I did not even know about the existence of $FORMAT (and that it was necessary to use it to display an array element) it works now!
(Purpose is to use these handles later, just wanted to check they were saved correctly by displaying them with a MsgBox)

Thanks again

Carlo

Petr

CARLO
15-12-2009, 19:01
Hi Carlo and welcome in thinBasic community.

Sorry, not much time to reply at the moment (I'm at work, I will have more time later this evening CET) but Petr already gave some tricks.

Please check attached file for a SendKeys examples that opens and drive an Internet Explorer session.
It may help you.

Ciao
Eros


Thanks, indeed Petr replied and solved my problem.

Thank you for the file, there are a couple of tricks that may be helpful.
Btw, great work

Ciao

Carlo