CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2011
    Posts
    60

    Edit message map at startup

    Hello,

    Thanks for taking the time to help. Is it possible to edit the message map at startup instead of just having it set at compile time?

    I'm reading some values from an XML file at startup. The menu options will be determined from what I find in there. But I need to assign those menu options to the message map. Any help would be great.

    Thanks!
    Greg

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Edit message map at startup

    You could try ON_COMMAND_RANGE macro rather than ON_COMMAND in your message map.
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Edit message map at startup

    The shortest answer is: No.
    A little bit more elaborated: It is not possible to "edit the message map" at run-time as long it uses macros and the macros are expanded in the first compiler phase.
    However, depending on your final goal, you have some choices to dynamically enable or disable some features in your application:
    • if talking about a limited, well known number of features to be enabled, handle all commands either using ON_COMMAND or ON_COMMAND_RANGE; from the configuration file provide only the desired command IDs so the user can see and choose only the menu commands you want.
    • otherwise, use a plug-in technique: implemented each additional feature in a separate module (usually a DLL); at start-up, your application loads the provided plugins, inserts a menu item for each one and finally, each plug-in module will do its own job;
    • and probably, may be yet other solutions.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Edit message map at startup

    You can't add stuff to the messagemap at runtime because the messagemap macro's are essentially a wrapper around a static table.

    You can however do dynamic command routing. And there's ON_COMMAND_RANGE as other already explained, but that's only for handling commands, it can't do other stuff.

    But the 'clean' solution for problems like this is to handle the dynamic buttons etc in the PreTranslate(), and change the incomming messages (click a button) into another message for further handling 'the normal way'.
    People seem to think PreTranslate() is ONLY for handling accelerators, but you can redirect pretty much any message to something else.

    If even that isn't enough and you need to handle stuff that wasn't even in the regular messagemap, then you can override the windows procedure do your custom handling and then pass all the rest back through the parent implementation.

  5. #5
    Join Date
    Mar 2011
    Posts
    60

    Re: Edit message map at startup

    ON_COMMAND_RANGE works. Thanks everyone.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Edit message map at startup

    You are welcome!
    Victor Nijegorodov

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Edit message map at startup

    Quote Originally Posted by Gregorina View Post
    ON_COMMAND_RANGE works.
    Of course it works. I never thought it doesn't...
    Last edited by ovidiucucu; April 21st, 2015 at 01:26 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Edit message map at startup

    @OReubens
    I'm pretty sure you already know but please let me explain to others: in C/C++ a macro is expanded/resolved at preprocessing time which is the very first phase of code compiling. Besides, C++ is a quite "static" programming language, i.e. at compile time a class (for example) has to be well defined, unlike other languages that may state something like this:
    From C++ to Objective-C
    [...] in Objective-C, classes are objects and can be dynamically managed: it is possible to add
    classes at run-time, create instances based on the name of the class, ask a class for its methods,
    and so on. [...]
    C++ is a wonderful programming language which I love in the same degree that I do hate Objective-C, but that's it... it does not allow something like "run-time definitions".

    That being said and returning to the OP, there's no direct way to "edit message map at startup".
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Edit message map at startup

    Quote Originally Posted by ovidiucucu View Post
    C++ is a wonderful programming language which I love in the same degree that I do hate Objective-C, but that's it... it does not allow something like "run-time definitions".
    The C++ language doesn't innately support it.
    But it is very much possible to have "runtime definitions" if you make provisions for this in your code.

    One of my projects uses this principle to provide IDispatch type objects at runtime then can then be used from scripted languages like VB/javescript to interact with my program.

    That being said and returning to the OP, there's no direct way to "edit message map at startup".
    edit the actual map, no, since that's a static structure.
    But you can have dynamic handling/routing of messages if you provide for this in your code (easiest being using PreTranslateMessage())

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured