FindWindowWithText

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

FindWindowWithText

Post by armsys » Thu Oct 17, 2013 3:31 am

Has anyone used FindWindowWithText lately?
It appears to be dyfunctional!
I have tested and exhausted all possibilities imaginable but it fails.

Code: Select all

FindWindowWithText>Firefox,1,str
MDL>str

User avatar
Grovkillen
Automation Wizard
Posts: 1132
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Post by Grovkillen » Thu Oct 17, 2013 7:56 am

I can see your problem. It find the MS Editor when you run it. I put a wait command and highlighted a Notepad window with the text "Firefox" and it then found the correct window.

I think that the command work as expected when compiled or run as a script (without the editor opened). This happens because the command look through the windows and pick the first occurance of the wanted text. When run through the editor the editor it self contain the wanted text and is picked first...
Let>ME=%Script%

Running: 15.0.27
version history

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Oct 17, 2013 8:12 am

Hi Grovkillen,
Thanks for taking time to investigate the issue.
I confirm your finding with NotePad, which I didn't expect.
I mean, I open a huge number of Firefox/Mozilla webpages with "Firefox" words everywhere in plain sight. But FindWindowWithText can't find one. That's a mystic miracle!
Marcus reminds me repetitiously that the Firefox browser is a different animal. I'm sorry I still don't understand why FindWindowWithText can't find it.
Move heaven and earth, please help me learn the nuances.
Thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Oct 17, 2013 1:48 pm

FindWindowWithText works by looking at "window caption" text. That is the only text that is actually "published". Text inside firefox is not caption text.

Let's put it another way. FindWindowWithText should be able to see the text that you see in the Tools->View System Windows tool. It will see the text that appears within quote marks.

You will notice that text inside a webpage does NOT appear in here.

See also:
http://msdn.microsoft.com/en-us/library ... s.85).aspx
If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design.
In contrast - I've tried to explain this many, many, many times - the text capture fuctions GetText... install a system hook which monitors calls to TextOut (and variants):

http://msdn.microsoft.com/en-us/library ... s.85).aspx

This text isn't published - we have to snoop with a "hook" and monitor when a process calls this function.

And this still assumes that the application does actually call this function. Most standard apps usually do *even though the programmer may not be aware of it*. But some may not. Bear in mind that text is just our interpretation of a series of dots on a screen. If the application developer decided to create his own text output function by turning individual dots black using some form of graphics capability instead of telling Windows to do it using Windows own TextOut functions then as far as Windows/Macro Scheduler is concerned there is no text.

These hooks need to "listen" for a while, the text needs to be visible, and there are resource implications in calling them, so it would not be feasible to make a version of FindWindowWithText that uses these hooks - even if we did it would have to cycle through every window on the system, making it visible and making it active, one by one, in turn. That just isn't going to go down well with anyone. So realistically, we can't watch for all text using FindWindowWithText which is why it can only work with the caption text that Windows publishes.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Oct 17, 2013 11:00 pm


User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 18, 2013 6:31 am

Oh dear. No, it DOES look WITHIN the window. It will see all window caption text that exists on any controls within the window. You are now confusing what is meant by window caption text with window titles. Caption text can include button captions etc.When Microsoft refer to window in that doc I linked to they mean any windowed object. A windowed control includes buttons, panels, etc. Look at the view system windows tool like I said and you will see lots of objects with caption text which are objects within windows.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Fri Oct 18, 2013 9:02 am

Marcus,
Apologize for my misunderstadning.
Appreciate your patience in further clarification.
Now the "caption text" is crystal clear to me.

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