» Home

  » Plugins

      » Mime

            » Supported Directives

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.

  1. Load Notepad (Start - Run - Notepad)
  2. Load Winspector.
  3. In Winspector, open the "Edit" menu and select "Options".
  4. Tick the option titled "Show message parameters on one line".
  5. Drag the red bullseye window finder from Winspector on to the Notepad titlebar.
  6. "Class: Notepad" will appear. Release the mouse button.
  7. Go back to Winspector. "Notepad" will be highlighted in the window list.
  8. Right click "Notepad" in the Winspector window list and select "Messages". The "Messages" window opens.
  9. Go to the Winspector "Messages" menu and select "Edit messages filter..."
  10. The "Message Filter" window appears. Click "Filter all"
  11. Locate "WM_COMMAND" in the left hand list and double click it.
  12. "WM_COMMAND" moves to the right hand list. Click "OK"
  13. Right click in the "Messages" window in Winspector (the window will say "Messages 00xxxxxx: (Notepad)"
  14. Make sure "Show return values" is unticked
  15. Return to notepad. Click the "Format" menu, select the "Font" item. The font selection dialog appears. Do nothing.
  16. Immediately return to Winspector. There will be a number of "WM_COMMAND" entries in the message window.
  17. 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.