-
April 17th, 2015, 07:12 PM
#1
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
-
April 18th, 2015, 02:51 AM
#2
Re: Edit message map at startup
You could try ON_COMMAND_RANGE macro rather than ON_COMMAND in your message map.
Victor Nijegorodov
-
April 18th, 2015, 11:37 AM
#3
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.
-
April 20th, 2015, 06:51 AM
#4
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.
-
April 20th, 2015, 02:06 PM
#5
Re: Edit message map at startup
ON_COMMAND_RANGE works. Thanks everyone.
-
April 20th, 2015, 02:30 PM
#6
Re: Edit message map at startup
Victor Nijegorodov
-
April 21st, 2015, 01:06 AM
#7
Re: Edit message map at startup
Originally Posted by Gregorina
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.
-
April 22nd, 2015, 03:55 AM
#8
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".
-
April 22nd, 2015, 06:40 AM
#9
Re: Edit message map at startup
Originally Posted by ovidiucucu
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|