Jump to content
Macro Express Forums

If Message and Window Activation


Recommended Posts

Is there any way to accomplish the following? Inside a larger macro, at the end of a complex operation, I want to be able to view the results of the modification undertaken by the macro on an open document. If I like the result, I click "Accept," if not, I click "Undo." The "Accept" and "Undo" options become available through an If Message:

 

If Message "Accept result?"

Delay: .2 seconds

Window Activate: %activeWindow%

Goto:end

Else

Goto:undo

End If

 

I want the If Message to stay open until I have perused the entire document specified in %activeWindow%. But in order to examine that document (I need to scroll inside of it using the arrow keys), I always have to ACTIVATE that document first, once the If Message appears. I can do that by clicking on the document, of course, but it would be much more convenient to have the Window activate automatically, so I could immediately proceed to scrolling with the arrow keys. I tried out the approach above, but I see why I wouldn't work, as the macro itself pauses at the If Message, waiting for True or False input; therefore, the embedded Window Activate command doesn't execute when I need it to.

 

Is there a solution to this problem?

 

Thanks!

Link to comment
Share on other sites

There is a way to achieve what you want, but it's slightly tricky!

You need 2 macros for this:

Macro1
 Macro Run: Macro2
 Window Activate: Notepad
 Delay: 1 seconds
 Repeat Until %n[1]% Does not Equal "%n[1]%"
   If Not Window "Respond Y or N" is running
     Repeat Exit
   End If
 End Repeat

Macro2
 Multiple Choice Menu: Respond Y or N
 code to process Accept or Undo

 

- In my example, I'm activating Notepad rather than your open document

- The window title in the Repeat loop must match the title of your multiple choice menu

- It is essential that the macro run statement in Macro1 does not wait for Macro2 to terminate before proceeding

- The multiple choice menu statement must be in a separate macro, otherwise you cannot return focus to your document window

- The logic to process Accept or Undo is in Macro2, which is the only macro to know what the user response was; you either have to click on the menu choice you want, then press Enter, or, in my example, you can activate the menu window and press Alt-y or Alt-n followed by Enter. If you were happy to write a small amount of AutoIt code, then I imagine the whole thing could be made more elegant and less clunky.

 

 

And here's the actual code:

 

Macro1
<MACRO RUN Use_ID="FALSE" Name="Macro2" ID="-1" Wait="FALSE"/>
<WINDOW ACTIVATE Title="Notepad" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<DELAY Flags="\x01" Time="1"/>
<REPEAT UNTIL Variable="%n[1]%" Condition="\x01" Value="%n[1]%"/>
<IF NOT WINDOW Option="\x01" Title="Respond Y or N" Partial="TRUE" Wildcards="FALSE"/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>

Macro2
<MULTIPLE CHOICE MENU Style="\x00" Result="\x01" Dest="%tResponse%" Title="Respond Y or N" Prompt="Do you want to accept the result?" Options="&Yes\r\n&No" Left="Center" Top="Center" Monitor="0" Width="443" Height="296" OnTop="TRUE"/>

Link to comment
Share on other sites

Paul,

 

thanks indeed for your solution. It didn't work when modified to suit my requirements, but it steered me in the right direction. For some reason, the new macro you suggested I needed to create was not able to get the window information (the window to activate) from %activeWindow%, even though it is defined as a global variable. I know there is some reason why the information isn't been passed on, but I didn't care enough to investigate.

 

Contrary to your suggestion, I am not calling my existing macro from the new macro. Rather, I call the new macro from the existing macro just before the If Message is displayed. The way I get %activeWindow% to be recognized by the new "activation" macro is by passing it through an Environment Variable that I've set aside for that type of thing. The "activation" macro is extremely simple now and gets me what I need:

 

Variable Set String %activeWindow% to Environment Variable, "%SwapVariable1%"

:start

If Window "Accept ES result?" is running

Window Activate: %activeWindow%

Macro Stop

Else

Goto:start

End If

 

Anyhow, it was your suggestion that within minutes steered me to the solution I needed. Thanks very much, indeed!

Link to comment
Share on other sites

Well, my congratulations to you in working your way towards a satisfactory solution based on a 3rd party suggestion! This is refreshingly different from so many participants in these forums, who simply expect someone else to do all the work. I'm glad it's all working well for you.

Link to comment
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...