[Solved] GetWindowTextEx Issue

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
OrangeAndBlue
Newbie
Posts: 18
Joined: Thu Feb 06, 2014 5:19 pm

[Solved] GetWindowTextEx Issue

Post by OrangeAndBlue » Thu Dec 04, 2014 11:15 pm

Hi,

I've already done some searching, but can't seem to find a solution to what I'm experiencing.

I've piecewise developed my script based on GetWindowTextEx results and expectations, however sometimes it just doesn't seem to grab anything from the window. It finds the window, and even in the Text Capture Wizard it has seemed to start failing to grab the text. I've set up the following to attempt to grab it, but it never succeeds:

Code: Select all

SetFocus>Reports

Let>i=0
Repeat>i
    Add>i,1
    GetTextInit
    GetWindowTextEx>Reports,WINDOW_TEXT
    If>%WINDOW_TEXT%<>
        GoTo>LBL_SUCCESS
    EndIf
    Wait>1
Until>i=20

//FAIL
**Breakpoint**

//SUCCESS
LABEL>LBL_SUCCESS
**Breakpoint**
I didn't need the loop initially, it used to work on-demand when I stepped through during development. However I added that based on what I found in the forums. Any additional advice anyone could provider?

v14.1, Windows 7 x32

Thank you!

Solution at last post.
Last edited by OrangeAndBlue on Fri Dec 05, 2014 4:24 pm, edited 1 time in total.

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

Re: GetWindowTextEx Issue

Post by Marcus Tettmar » Fri Dec 05, 2014 10:13 am

Try initializing the library only once so that it continually monitors. Change your code to:

Code: Select all

GetTextInit
SetFocus>Reports

Let>i=0
Repeat>i
    Add>i,1
    GetWindowTextEx>Reports,WINDOW_TEXT
    If>%WINDOW_TEXT%<>
        GoTo>LBL_SUCCESS
    EndIf
    Wait>1
Until>i=20
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

OrangeAndBlue
Newbie
Posts: 18
Joined: Thu Feb 06, 2014 5:19 pm

Re: GetWindowTextEx Issue

Post by OrangeAndBlue » Fri Dec 05, 2014 2:49 pm

Hey Marcus -

Thanks for your reply. I feel dead in the water on this one!

I made the change you advised and restarted the machine... Still no luck. Very frustrating that this initially was working just fine.

Any other ideas on how to get this functional?

Thanks again for your help.

OrangeAndBlue
Newbie
Posts: 18
Joined: Thu Feb 06, 2014 5:19 pm

Re: GetWindowTextEx Issue

Post by OrangeAndBlue » Fri Dec 05, 2014 3:55 pm

If I use MS's View System Windows tool, it does see the window but reports it empty:

66558 - TListView ""

Again, I'm just confused how it was able to do this operation before when I constructed a whole script based on its output.


EDIT: Actually, that tool reports that my notepad window is empty too, even though it is definitely not. I've tried refreshing it.

Is there a windows registry tweak?

OrangeAndBlue
Newbie
Posts: 18
Joined: Thu Feb 06, 2014 5:19 pm

Re: [Solved] GetWindowTextEx Issue

Post by OrangeAndBlue » Fri Dec 05, 2014 4:25 pm

SOLUTION / WORKAROUND

The workaround I used is below. I think this function simply is having issues with hooks. Still perplexed as to why it would not work when it had many times previously...

Simply use this other function and force a full screen read.

Code: Select all

GetScreenRes>SCREEN_RES_X,SCREEN_RES_Y

SetFocus>Reports
Wait>2
GetTextInRect>0,0,%SCREEN_RES_X%,%SCREEN_RES_Y%,WINDOW_TEXT

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

Re: GetWindowTextEx Issue

Post by Marcus Tettmar » Sun Dec 07, 2014 12:46 pm

OrangeAndBlue wrote: EDIT: Actually, that tool reports that my notepad window is empty too, even though it is definitely not. I've tried refreshing it.

Is there a windows registry tweak?
The View System Windows Tool reports "caption" text. "caption text" is what you see in window titles and button captions but is not usually editable text. This is the only text that regular "windowed controls" publicly report - caption text is a published property if you will. As you can see it is rarely useful. It's useful for window titles and buttons but rarely anything else.

For other forms of text we have to go deeper and "hook" into the process that produces it and then HOPE that to produce it it uses one of the Windows API functions in the "TextOut" family of functions. We "hook" into these functions (we spy on them effectively) so we can see what text the app is requesting should be rendered.

Unfortunately not all apps use these "standard" functions. When you consider that as far as a computer is concerned text is just a series of dots or pixels an app could choose to generate text by drawing pixels on the screen directly. We would therefore have no concept of it being text and it is therefore not "capturable".

Read this to understand more:
https://www.mjtnet.com/blog/2009/02/19/ ... d-objects/

And this:
https://www.mjtnet.com/blog/2009/01/23/ ... scheduler/

And:
https://www.mjtnet.com/blog/2007/12/12/ ... reen-text/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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