Brass Plugins: Mime
Supported Directives: Api - Send
menu item
Often you'll want a Mime gesture to trigger a menu
action, for example File - Print. When you choose a menu item in
a Windows application, an associated "Command ID" is sent
to the application from the Windows interface.
Every menu item in every application has an associated
command ID. So to emulate opening the File menu then clicking Print,
you can use the "Send menu item" directive.
The format of the directive is:
[Menu(command id,target
window)]
Parameter 1, the command id, is the command id sent to the application
for this menu item. You can find this by using a window spy tool
such as Spy++ or Winspector and looking at only the WM_COMMAND messages.
The value in WPARAM is the command ID.
Parameter 2, the target window, is the window to send the menu
command to based on its relationship to the window the gesture was
made in. This parameter may be "window", "parent",
or "overall". If you are unsure what to put in this field
you should use "overall" as most applications will not
reflect menu commands to the parent window.
Notepad Example
This example will obtain the command ID for the "Format -
Font" menu item in Notepad.
- Load Notepad (Start - Run - Notepad)
- Load Winspector.
- In Winspector, open the "Edit" menu and select "Options".
- Tick the option titled "Show message parameters on one
line".
- Drag the red bullseye window finder from Winspector on to the
Notepad titlebar.
- "Class: Notepad" will appear. Release the mouse button.
- Go back to Winspector. "Notepad" will be highlighted
in the window list.
- Right click "Notepad" in the Winspector window list
and select "Messages". The "Messages" window
opens.
- Go to the Winspector "Messages" menu and select "Edit
messages filter..."
- The "Message Filter" window appears. Click "Filter
all"
- Locate "WM_COMMAND" in the left hand list and double
click it.
- "WM_COMMAND" moves to the right hand list. Click "OK"
- Right click in the "Messages" window in Winspector
(the window will say "Messages 00xxxxxx: (Notepad)"
- Make sure "Show return values" is unticked
- Return to notepad. Click the "Format" menu, select
the "Font" item. The font selection dialog appears.
Do nothing.
- Immediately return to Winspector. There will be a number of
"WM_COMMAND" entries in the message window.
- Locate the entry with "code: 0 control id: 37....".
The control ID is the command ID we require.
The directive is therefore as follows:
[Menu(37,overall)]
Technical Notes
This directive accepts a control ID as either its
integer value (37, as displayed by Winspector in the above example)
or as it's WPARAM DWORD value. When specifying the command ID in
DWORD form, prefix it with "0x" to indicate a hex value.
Therefore the following 2 statements are identical in operation:
[Menu(37,overall)]
[Menu(0x00000025,overall)]
25 in hex is of course equal to 37 in decimal.
Note that Spy++ returns the WPARAM hex value of
a WM_COMMAND message, whilst Winspector returns the integer value.
|