ENumWindowTexts?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Wahnfang
Newbie
Posts: 6
Joined: Thu May 05, 2005 7:54 pm

ENumWindowTexts?

Post by Wahnfang » Thu May 05, 2005 8:13 pm

Hello,
I just did a piece of Libfunc-Stuff and I'm wondering what the shortening of the outcoming Window-Texts are about??

Let>WIN_USEHANDLE=1
// Just to get one Hwnd
GetActiveWindow>win,x,y
// Just to get the first Hwnd
Let>gw=0
Label>start
LibFunc>user32,GetWindow,win,%win%,%gw%
//Now the next ones
Let>gw=2
// Bye bye after the last Hwnd
If>win=0,fin
LibFunc>user32,GetWindowTextLengthA,wtlen,win
Let>buffer_SIZE=wtlen
LibFunc>user32,GetWindowTextA,gwt,win,buffer,wtlen
// Is gwt_2 closed with Ascii 0? You can't put another text or variable after gwt_2! Any solution?
MessageModal>Text: %gwt_2%
Goto>start
Label>fin

The other question is in the commentary.
Thanx
Wahnfang

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu May 05, 2005 8:52 pm

You need to add 1 to wt_len which you pass to GetWindowTextA to allow room for the terminating character. So you need to modify the following part of your script as follows:

LibFunc>user32,GetWindowTextLengthA,wtlen,win
Let>buffer_SIZE=wtlen
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,gwt,win,buffer,wtlen

This will now let you add something after gwt_2.
MJT Net Support
[email protected]

Wahnfang
Newbie
Posts: 6
Joined: Thu May 05, 2005 7:54 pm

Enum, ie. SearchLeftTRuncatedStuff

Post by Wahnfang » Fri May 06, 2005 1:09 am

Ok. so far many thanx
But now:

// Macro would pass the hwnd of the searched WindowText
// 1. Problem: "Babylon" should be imported. How to do that???
Let>stext=Babylon
Let>WIN_USEHANDLE=1
// Just to get one Hwnd
GetActiveWindow>win,x,y
// Just to get the first Hwnd
Let>gw=0
Label>start
LibFunc>user32,GetWindow,win,%win%,%gw%
//Now the next ones
Let>gw=2
// Bye bye after the last Hwnd
If>win=0,fin
LibFunc>user32,GetWindowTextLengthA,wtlen,win
Let>buffer_SIZE=wtlen
// Great, that works!
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,gwt,win,buffer,wtlen
Let>wtext=%gwt_2%
Length>wtext,len
// Hupps: if %gwt_2% is empty, len delivers 255, thats the dimension of your string-type?
if>lenat={Pos(%stext%,%wtext%)}// don't let it run!!!!!!
ENDIF
if>at0
MessageModal>Ergebnis: %stext%: Hwnd: %win%
Goto>fin
EndIf
Goto>start
Label>fin

The 2 Problems are posted in the commentry again.
And if you can fix them, - we all would have a FindWindowWithLeftTRancatableWindowTExt-Function. Cause that's what I was looking for.
Wahnfang

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri May 06, 2005 7:16 am

Not really sure I follow what the problem is, or what you're trying to achieve ... feel free to explain further.
MJT Net Support
[email protected]

Wahnfang
Newbie
Posts: 6
Joined: Thu May 05, 2005 7:54 pm

Post by Wahnfang » Fri May 06, 2005 10:48 am

What to achieve is a comparison of a WindowText with a given searched TextString, because the FindWindowWithTExt-Routine doesn't accept left and right trancated string like f.e. *babylon*...

....
LibFunc>user32,GetWindowTextA,gwt,win,buffer,wtlen
//now *gwt_2* contains either nothing or the string (depends on the WClass...)
//if it contains nothing, then after
Let>wtext=%gwt_2%
//and
Length>wtext,len
// wtext contains nothing, but with a len of 255!
//this of course causes a kind of terrible miss in the following line:
Let>at={Pos(%stext%,%wtext%)}
// as I remember the error message is like 'wrong string termination' or something and you can't get out of that error-message-loop
//so I tried to work around the problem with
if>lenat={Pos(%stext%,%wtext%)}
// but now the macro fucks up terribly somehow

Solution? As far as I now the API delivers strings with an closing ASCII 0. Maybe that causes the conflicts?
Wahnfang

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri May 06, 2005 12:25 pm

Wahnfang wrote:What to achieve is a comparison of a WindowText with a given searched TextString, because the FindWindowWithTExt-Routine doesn't accept left and right trancated string like f.e. *babylon*...
Not sure what you mean. This will find a window containing the text "rivers of babylon" and "babylon 5" and just "babylon".

FindWindowWithText>babylon,0,win

Is that not the same thing?

As for the #0 character. The following will include it. All strings are terminated with this character. Should be fine using the following:

LibFunc>user32,GetWindowTextLengthA,wtlen,win
Let>buffer_SIZE=wtlen
Let>wtlen=wtlen+1
LibFunc>user32,GetWindowTextA,gwt,win,buffer,wtlen
MJT Net Support
[email protected]

Wahnfang
Newbie
Posts: 6
Joined: Thu May 05, 2005 7:54 pm

Post by Wahnfang » Fri May 06, 2005 1:39 pm

Hallo,
I wouldn't have asked you if FindWindowWithText would work...
1) The case:
View System Windows has the following result
656342 - #32770 "problem - Babylon-Pro"
Fin>problem,0,win
win contains: problem - Babylon-Pro
Fin>babylon,0,win
win contains: NOT FOUND
2) Solution
a) the "problem"-string in the WinText will change with the next item to handle with Babylon -> we HAVE to find the window with "babylon-pro"
b) I read the comments to FindWindowWithText in the help-file quite closely.
c) My EnumWindows-Thing does show the WinText in Question, but - POS doesnt work properly.
Thats the whole story.
Wahnfang

Wahnfang
Newbie
Posts: 6
Joined: Thu May 05, 2005 7:54 pm

Post by Wahnfang » Fri May 06, 2005 1:45 pm

Sorry,
it just came to my mind to try
Let>VAREXPLICIT=1
in the first Line
and all works properly now.
Wahnfang

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts