Command Reference - Action Examples
|
Actions used: |
In this example, we'll bring the "My Computer" window to the front and size it to fill the left half of the screen. If the "My Computer" window isn't open, we'll prompt the user to open it and try again.
Here's what the action list looks like:
.png)
First, we use a "Window - Find" action to search for a window with "My Computer" in its title bar. The hWnd value for the window will be stored in a variable called %hWnd%.

Now, if the user doesn't have the "My Computer" window open, this action will fail and generate an error. We'll use this error to determine whether the "My Computer" window is open.
We don't need the user to be told about the error, though, so we'll change the User Notification settings on the On Error tab for this action from "Verbose" to "None".

This will prevent the action from notifying the user about this error. (We want to do that ourselves.)
Next, we use a "Control Structure - WHILE" action to create a loop that will only be entered if an error was generated. To do that, we just check to see whether the built-in variable %LastErrorNum% is set to "1", which is the error code that "Window - Find" stores in %LastErrorNum% if the it didn't find a matching window.

If an error was generated—if the "My Computer" window wasn't found—we want to tell the user about it (so they can open the "My Computer" window) and ask them if they'd like to try again. So, we use a "Dialog - Message Box" action to present them with a Yes/No message box, and store their choice in a variable called %Result%.

After this action, the name of the button that they clicked ("YES" or "NO") will be stored in %Result%.
So, we use a "Control Structure - IF" action to compare the value in %Result% with "NO".

If the user's answer was "NO", we want to exit from this action script with a "Control Structure - RETURN" action.
Next, we end our IF block with a "Control Structure - END IF" action.
Now, if the user selected "YES", we need to search for the "My Computer" window again, using another "Window - Find" action that is exactly like the first one. (In fact, we simply copied the first "Window - Find" action with Ctrl-C and pasted it here with Ctrl-V.)
This is a very important step, because our "Control Structure - WHILE" action tests %LastErrorNum% to determine whether to perform the actions in the loop, or just skip the whole thing and move on. Since %LastErrorNum% holds the error code of the last action that was performed, we need to make sure that the last action performed in our loop is the "Window - Find" action. Otherwise, we'll be testing whether some other action generated an error...which isn't what we want.
Again, we made sure the User Notification setting on the On Error tab for the "Window - Find" action is set to "None".
Next, we mark the end of our while loop with a "Control Structure - END WHILE" action. When AutoPlay reaches this point, it will go back to the WHILE action, perform the test (%LastErrorNum% = 1) again, and either go through the loop once more if the test is true, or skip past the whole loop if the test is false.
The loop should keep on looping until either the "My Computer" window is found, or the user presses the "No" button to exit out of the loop (and the rest of the action script) with the RETURN action.
If the "My Computer" window is found, then we want to move it and resize it to fill the left half of the screen. First, we need to find out how big the user's screen is.
So, we use a "System - Get Information" action to get the width of the user's screen in pixels, and store that number in a variable called %ScreenWidth%...

...followed by another "System - Get Information" action to get the height of the user's screen in pixels, which we store in a variable called %ScreenHeight%.

Then we use a "Variable - Set Value" action to divide the screen width by half, and store the result in a variable called %width%.

Note that we've enabled the Evaluate value as expression option since we're performing a calculation.
Next, we use a "Window - Bring to Front" action to bring the "My Computer" window to the front. Since this action takes an hWnd value, we use the value that the "Window - Find" action stored in our %hWnd% variable.

Finally, we use a "Window - Move" action to move the top left corner of the "My Computer" window to the upper left corner of the screen, set its height to the full screen height (which we stored in %ScreenHeight%), and set its width to the value we stored in %width%.

Here's a link to the finished example, as an AutoPlay Media Studio 4.0 actions XML file that you can import into an action list:
Moving_a_window_(advanced).zip
(Note: save this file to your hard drive and use a tool like WinZip to extract the XML file)