Click here to Skip to main content
16,008,469 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DIBSections Pin
Mike Nordell29-Oct-01 12:19
Mike Nordell29-Oct-01 12:19 
GeneralRe: DIBSections Pin
Christian Graus29-Oct-01 12:51
protectorChristian Graus29-Oct-01 12:51 
Generalargh, dialog resource menu enabling/graying Pin
Kuniva28-Oct-01 10:35
Kuniva28-Oct-01 10:35 
GeneralRe: argh, dialog resource menu enabling/graying Pin
Crercio O. Silva28-Oct-01 10:57
Crercio O. Silva28-Oct-01 10:57 
GeneralRe: argh, dialog resource menu enabling/graying Pin
Michael Dunn28-Oct-01 13:36
sitebuilderMichael Dunn28-Oct-01 13:36 
Generalthanks Pin
Kuniva28-Oct-01 22:47
Kuniva28-Oct-01 22:47 
GeneralDynamic building of menu in an MFC Application Pin
Stephane Routelous28-Oct-01 9:46
Stephane Routelous28-Oct-01 9:46 
GeneralRe: Dynamic building of menu in an MFC Application Pin
Joaquín M López Muñoz28-Oct-01 11:05
Joaquín M López Muñoz28-Oct-01 11:05 
One possible approach (though by no means the only one) for this problem is as follows:

  1. First, reserve some range of user defined message identifiers, say WM_FIRST_TREECOMMAND, WM_FIRST_TREECOMMAND+1, ... , WM_FIRST_TREECOMMAND+max_commands-1, where max_commands is large enough so that the range holds room for all the commands on your command tree. This decision you have to made it on compile time, so allow for a reasonably large range.
  2. Have all the range of message IDs mapped to the same message handler (say OnTreeComand) by means of the MFC ON_COMMAND_RANGE.
  3. Define a map (use std::map, for instance, or your favorite map container) that translates message IDs to TreeCommand objects (or whatever your command objects are named).
  4. On initialization time, build a CMenu object that mimicks the structure of your command tree, by recursively transversing the tree. The key member function to call is CMenu::AppendMenu() that serves both for inserting commands and submenus. Use the range of user defined message IDs for assigning identifiers. For each new command inserted into the menu add an entry to the map of the form treecommand_map[id_command]=command, where command is the appropriate TreeCommand object (or a reference to it, or a pointer, you are the designer).
  5. That's it, now your message handler OnTreeCommand only has to retrieve the TreeCommand object from the identifier passed using treecommand_map and execute it:
void CYourWnd::OnTreeCommand(UINT nID){
 treecommand_map[nID].Execute();
}

Et voilà. Hope this helps.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralOverlay Mode Pin
28-Oct-01 8:52
suss28-Oct-01 8:52 
GeneralMulti Threaded Server Pin
28-Oct-01 5:40
suss28-Oct-01 5:40 
GeneralRe: Multi Threaded Server Pin
Anders Molin28-Oct-01 12:15
professionalAnders Molin28-Oct-01 12:15 
GeneralRe: Multi Threaded Server Pin
28-Oct-01 20:12
suss28-Oct-01 20:12 
GeneralSending messages directly to other windows Pin
Kuniva28-Oct-01 2:39
Kuniva28-Oct-01 2:39 
GeneralRe: Sending messages directly to other windows Pin
#realJSOP28-Oct-01 3:37
professional#realJSOP28-Oct-01 3:37 
Questionrequest code for usefully problem? Pin
Huu Quynh28-Oct-01 1:12
Huu Quynh28-Oct-01 1:12 
QuestionATL equivalent of PreTranslateMessage? Pin
Michael Dunn27-Oct-01 22:40
sitebuilderMichael Dunn27-Oct-01 22:40 
AnswerRe: ATL equivalent of PreTranslateMessage? Pin
Rashid Thadha28-Oct-01 8:36
Rashid Thadha28-Oct-01 8:36 
Questionsetting the font ? Pin
JekYu27-Oct-01 21:01
JekYu27-Oct-01 21:01 
AnswerRe: setting the font ? Pin
l a u r e n27-Oct-01 21:21
l a u r e n27-Oct-01 21:21 
AnswerRe: setting the font ? Pin
Nish Nishant27-Oct-01 21:23
sitebuilderNish Nishant27-Oct-01 21:23 
AnswerRe: setting the font ? Pin
Simon Walton29-Oct-01 0:12
Simon Walton29-Oct-01 0:12 
GeneralRe: setting the font ? Pin
JCY29-Oct-01 3:06
JCY29-Oct-01 3:06 
QuestionHow to set item height of a listbox base on the item data? Pin
27-Oct-01 17:13
suss27-Oct-01 17:13 
AnswerRe: How to set item height of a listbox base on the item data? Pin
Tomasz Sowinski29-Oct-01 1:31
Tomasz Sowinski29-Oct-01 1:31 
Generalneed some help!!! Pin
27-Oct-01 16:48
suss27-Oct-01 16:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.