Brass Plugins: Mime
Supported Directives: Directive
- Set Target Window
This directive changes the target window that will
receive all further directives.
The format of the directive is:
[SetTargetWnd(class,title)]
The 2 parameters are how the directive will identify the window
you want to make the new target. Both parameters are optional, but
you must supply at least one.
Parameter 1, the class name, is the explicitly matched class name
of the window you want to make the new target. If you don't want
to match on the class name supply "0" for this parameter.
Parameter 2, the title, is the pattern matched window title of
the window you want to make the new target. If you don't want to
match on the window title supply "0" for this parameter.
Detailed Explanation
This is the most powerful directive available. It's how cross-application
gestures are possible.
By default the application you make the gesture in is the one that
is used for the directives as a target. If you make a gesture in
Notepad, all directives will affect Notepad.
Using SetTargetWnd() allows you to send directives to another application.
A good example of this is the "Winamp Anywhere" actions
(these come preconfigured with the Mime installation). Regardless
of where a gesture is made, the Winamp Anywhere actions immediately
use SetTargetWnd() as the first directive to set the target to WinAmp.
Example
Regardless of where the gesture is made, set the target to Notepad
using the Notepad.exe window class only:
[SetTargetWnd(Notepad,0)]
Regardless of where the gesture is made, set the target to Notepad
only when myfile.txt is being edited (the window title will read
"Myfile.txt - Notepad", the directive will pattern match
"myfile.txt" to this window title):
[SetTargetWnd(Notepad,myfile.txt)]
Regardless of where the gesture is made, set the target to any
window that has a title of "amazing brass". This will
match Microsoft Word editing "Amazing Brass.doc", Windows
Explorer in "C:\Program Files\Amazing Brass" etc:
[SetTargetWnd(0,amazing
brass)]
Sample Notepad Anywhere directive
This directive will open the Font dialog in Notepad,
regardless of where the gesture is made.
- Create a new application and action using the Custom
Action Wizard
- The window criteria should be all empty, we want this gesture
to apply to every application
- Call the action "Notepad Font Anywhere"
- Set the directive to: [SetTargetWnd(Notepad,0)]%%[Menu(37,window)]
- Finish the wizard. Add a gesture to the new action.
- Make sure Mime is loaded and running.
- Load Notepad. Leave the Notepad window open, move it to one
side without minimizing.
- On the desktop, make the gesture you just configured for the
"Notepad Font Anywhere".
- The Notepad font selection dialog appears
The [Menu()] directive in step 4 is covered in
detail on the Api: Menu Item Command
page.
Technical Notes
You may supply one or both parameters to this directive.
The classname parameter is an explicit match, whereas the window
title is a pattern match. There is a detailed discussion of classname
and window title matching in the Creating
Good Criteria section - the principle is exactly the same.
If the specified window cannot be found, the directive
is ignored. Additionally the rest of the directive string is ignored
until a [RestoreTargetWnd()] or [SetTargetWnd()] directive is found.
Consider the following. Application AcmeWidget
has a very useful function accessed by pressing Control-A, then
Delete. The directive for this action might look like this:
[CTRL]a[/CTRL]%%{DEL}
No problems here. Now assume we want to access
this useful function from a gesture made in any application:
[SetTargetWnd(AcmeWidgets,0)]%%[CTRL]a[/CTRL]%%{DEL}
Still no problem, as long as AcmeWidget is running
and working properly. However what if AcmeWidgets wasn't running
and a gesture attached to this directive was made in Windows Explorer?
SetTargetWnd() would search the running applications
list for a window with a class name of "AcmeWidgets".
No window would be found, so the target window won't be changed.
The next directive is Control-A, which selects all the items in
the current Windows Explorer window. The last directive is an emulation
of pressing Delete, which deletes all the selected items. Very easy
to cause serious side effects.
To prevent this, if SetTargetWnd() cannot find
the window you specify it automatically rejects the rest of the
directive string until either another SetTargetWnd() is found, or
a RestoreTargetWnd() is found. If neither are found the entire directive
is rejected.
Another example: assume we want to access this
useful function from a gesture made in any application, then revert
to the original window and send a Control-C keypress. The directive
would look like this:
[SetTargetWnd(AcmeWidgets,0)]%%[CTRL]a[/CTRL]%%{DEL}%%[RestoreTargetWnd()]%%[CTRL]c[/CTRL]
Assuming the AcmeWidgets application wasn't running,
this would happen:
[SetTargetWnd(AcmeWidgets,0)]%%[CTRL]a[/CTRL]%%{DEL}%%[RestoreTargetWnd()]%%[CTRL]c[/CTRL]
'-- This directive fails --' '---Ignores
these---' '---- Resumes processing here ->
|