Re: Command IDs in message map handlers.




"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:m8og43t4577g8380pimg3jpi32iugspo46@xxxxxxxxxx

No. Because you are in that handler, you KNOW what ID got it there.

If you want to have several ON_COMMAND dispatches go to the SAME handler, use
ON_COMMAND_RANGE(low, high, OnHandler)

As Seetharam pointed out, ON_COMMAND_EX also passed the ID. But I have a million and one ON_COMMAND handlers and I wanted to avoid having to change them all (and the form of the functions they call) if possible.

But I have been playing with GetCurrentMessage() and this seems to be doing the trick.

A bit of background:

Just about all my OnCommand handlers are essentially three line functions with a call to

- a preparation function
- an execute function
- a tidy-up function

I introduced this structure to allow multiple levels of undo: the preparation function makes some definitions, and the tidy-up function adds to the undo stack if the command was successful.

So it was the work of a moment to add GetCurrentMessage as the first task of the preparation function, and extract the command ID and store it temporarily. The tidy-up function stores it for the longer term if the commend succeeded.

And the point: after a couple of user-requests I have added a "repeat previous command" command, (on F4 by default, as in Microsoft Office) which just looks up this ID and, yes, *posts* a WM_COMMAND message. It is still somewhat embryonic but it appears to be working quite well so far.

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm





.



Relevant Pages

  • Re: Command IDs in message map handlers.
    ... you shouldn't need to know the ID of the control because by definition by ... A simple replace-in-files pattern should fix up all the handlers. ... and the tidy-up function adds ... to the undo stack if the command was successful. ...
    (microsoft.public.vc.mfc)
  • Re: WM_COMMAND not arriving?
    ... The menu is on a dialogue but the WM_COMMAND messages are handled by the CMyView of which the dialogue is a child. ... The CMyView has ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for all the menu commands. ... The offending behaviour occurred because for one of the menu items an ON_UPDATE_COMMAND_UI entry had also crept into the *dialogue's* message map. ... The function it purported to map didn't exist and so the command was disabled. ...
    (microsoft.public.vc.mfc)
  • Re: UPDATE COMMAND UI doesnt update!
    ... command handlers don't work in dialogs so you need check these things ... the command and update feature automatically. ... handlers for the commands from wich I can call the same functions as the ...
    (microsoft.public.vc.mfc)
  • Re: Routing of handlers
    ... It all depends upon the context in which the command is used. ... This is how MFC routes it to various CCmdTarget objects(CMainFrame, ... > should I write handlers of toolbar buttons. ...
    (microsoft.public.vc.mfc)