GWKB2038 : Accessing Text in a Custom Control

Product: Window-Eyes
Author: Aaron Smith
Date Added: 08/16/2013
Last Modified: 08/16/2013

The following example demonstrates how to get the text of a custom control. More specifically, the code editor in Visual Studio 2008, although the technique can be applied to any application.

Note: this example uses the Immediate Mode script for real-time testing and debugging.

To get the text of the code editor window in Microsoft Visual Studio 2008, I put focus in the code editor, launch the Immediate Mode window, and do the following:

print FocusedWindow.ClassName

I then get back:

VsTextEditPane

Then I do:

print FocusedWindow.ModuleName

Which gives me back:

MSENV

With that knowledge, I can then do:

Set codeWindows = ActiveWindow.Children.FilterByClassAndModule("VsTextEditPane, "MSENV")

I then verify the number of windows returned by doing:

print codeWindows.Count

In this example, I get back 9. I'm only interested in the window that contains the text, so now I have to narrow things down by examining each one, and determining which window has an acceptable number of clips, by doing:

For Each wObj In codeWindows : print wObj.Clips.Count : Next

That gives me back:

0
0
0
0
0
0
0
0
51

Bingo. That window with 51 clips is most likely the one I want. So now I'll do:

For Each wObj In codeWindows : If wObj.Clips.Count > 0 Then : Set codeWindow = wObj : Exit For : End If : Next

To verify that codeWindow got set, I can do:

print TypeName(codeWindow)

Which gives me back:

Window

So now I have a Window object representing the window that contains all the text I'm interested in. So now it's time to iterate through the clips, and print out all the ones that are text. I have a header file currently loaded in the IDE, so I can get the text of the window by doing this:

For Each clip In codeWindow.Clips : If clip.Type = ctText Then : print clip : End If : Next

And I get back:

#ifndef
_SWPMAIN_
#define
_SWPMAIN_
#include

"swap.h" // Declare Menu constants

#define
LOGON     1
#define
SELECT_RECIPIENT  2
#define
ENTER_RECIPIENT   3
#define
GET_DETAILS    4
#define
SEND_NO_UI    5
#define
SEND_UI     6
#define
SEND_ATTACH    7
#define
CREATE_MSG    8
#define
LIST_INBOX    9
#define
READ_MAIL    10
#define
LOGOFF     11
#define
EXIT        12
#define
REFRESH     13
void
 main(
int
argc,
char
 argv[ ],
char
  envp[ ] );
void
 PrintMenuToConsole (
void
 );
#endif

Viola! Note that you're only going to get the text that's visible on screen, since that's what clips are. So if I make my IDE window really small, then do the same thing above, I might only get:

#ifndef
_SWPMAIN_
#define
_SWPMAIN_
#include

"swap.h" // Declare Menu constants

#define
LOGON     1

That's one way to get clips from a specific window.