Jump to content
Macro Express Forums

A potential hack to make the "Get Control" instruction more versatile


Recommended Posts

The "Get Control" instruction saves information about a control (e.g., a button, edit box, pane, etc.). Macro Express includes a capture utility to gather information by dragging the mouse pointer over the control, and saving it to a control variable.

When I use Get Control, my code usually looks like this:

 

Get Control: (OUTLOOK.EXE) Using z-order -> %Control%
 
Get Control Class from %Control% into %ControlClass%
Get Control Text from %Control% into %ControlText%

 

The first line captures information about the control. The following two lines extract information about the control: its "class" and "text." Both are stored as string (text) variables, so can be easily checked, e.g.,

 

  If Variable %ControlClass% Equals "OutlookGrid"
  // Do something
  End If

  If Variable %ControlText% Equals "Table View"
  // Do something
  End If

 

A perpetual problem I run into with Get Control is that the information about the control might change. For example, in Outlook, the information might be different if I capture a control while I am viewing my Inbox, but play it back while viewing my Sent Messages folder. When this happens, the script fails.

 

Here is a potential workaround:

 

1. Use "Get Control" in the usual way, i.e., via the capture utility. There are three capture modes:  Z-order, Content, and Coordinates. You'll need to experiment to discover which one (or ones) is/are going to work, but I usually start with the default Z-order and hope for the best!

 

2. When prompted to set the "Top Level Window Caption," decide whether it's best to set it to "Partial" or "Exact" match. It depends on the application. Check the title bar of the window that contains the control you are capturing, and see if it varies. For example, in Outlook messages, the "top level" title might read:

 

One more try - Message (HTML)

or

Re: Hello - Message (RTF)

or

- Message (Plain Text)

 

So you'll want to specify partial match that covers all three possibilities:

 

" - Message ("

 

3. Finally, the hack!

 

After using the capture utility, you'll see this in the Script Editor:

 

Get Control: (OUTLOOK.EXE) Using z-order -> %Control%

 

If you switch to the Direct Editor, you'll see something like this. (It appears as one long line, but I've reformatted it into several to make things a bit clearer):

 

<GET CONTROL Flags="1" 
     Program_Name="OUTLOOK.EXE" 
     Class="rctrl_renwnd32" 
     Title="Inbox - alan@cantoraccess.com - Outlook" 
     Control="\"rctrl_renwnd32\",\".... bla bla bla 
     Variable="%Control%" 
     Caption="- Outlook" 
     Partial="TRUE" 
     Wildcards="FALSE"/>

 

The entry for "Caption" is the partial match for "Top-Level Window Caption" that I described above.

 

The entry for "Title" appears to be the same: the title bar of the window. Macro Express does not provide a way to edit it via the user interface, but it looks like we can edit it in the Direct Editor to change an exact match into a  partial match:

 

     Title=" - Outlook"

 

My initial testing shows that Macro Express recognizes partial matches for "Title" in the Direct Editor. If this "hack" actually works, it opens up possibilities for performing more tasks programmatically via Macro Express.

 

For anyone inclined to use Get Control, please test this hack and report back. If it works reliably, I'll make a feature request: a way to edit the "Title" property of controls without the need to mess around in the Direct Editor.

Link to post
Share on other sites

Hi Alan,

 

Interesting post, thanks. I’ve used Controls very little, never having developed much confidence in their consistency. Are you saying that making Title identical to Caption improves or even fully resolves that issue? It naturally raises the question of potential adverse effects, as presumably the two fields are intentionally distinct?

 

I suspect I haven’t fully understood your recommendation. Perhaps you could give an example or two?

 

Terry

Link to post
Share on other sites

Hi Terry,

 

I have a Macro Express script that I use to move between Outlook controls and show three things about each: its class, its text, and the location of its top-left corner. The macro has helped me puzzle out controls, at least a little.

 

If you (or anyone else) might find this useful, I would be happy to post it here. The script can be adapted to work in other applications.

Link to post
Share on other sites

Thanks Alan, appreciate your offer, although as I don’t use Outlook I’ll pass. If/when I get more time on MX Pro I’ll try a few examples myself, using your suggested approach.

Link to post
Share on other sites

An update on editing "Get Control" information in the Direct Editor:

 

The approach seems to work only temporarily before Macro Express throws errors. (Typically, that the control does not exist).

 

I'm trying to understand what is causing the command to stop working. It's puzzling that it works like a treat for awhile, and then stops. It seemed so promising. In one test, I was able to copy information from Outlook while working in a different application, and without bringing Outlook into the foreground.

 

My initial theory was that the failures might result from the way that I captured controls: via Z-order, content, or coordinates. I don't think it makes a difference.

 

Perhaps I was overoptimistic about the approach. Although I'm continuing to tinker, I'm on the verge of abandoning it.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...