WINAPI - Check if popup menu item is selected

Hello!

I managed to create a menu with "submenus" like "File", "Edit", "View" and "Help". I also managed to insert items dynamically. Here's my way to create menu and handle it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/// Create a menu:
Menu menu("Menu Main");

/// Create submenus:
// General items:
ItemMenuSub item_sprt = {NULL};

// File:
ItemMenuSub item_export = {"Export"};
ItemMenuSub item_import = {"Import"};
ItemMenuSub item_newproject = {"New Project"};
ItemMenuSub item_openproject = {"Open Project"};
ItemMenuSub item_quit = {"Quit"};
ItemMenuSub item_saveproject = {"Save Project"};
ItemMenuSub item_saveprojectas = {"Save Project As..."};
MenuSub menu_sub_file("File", {&item_newproject, &item_openproject, &item_sprt, &item_saveproject, &item_saveprojectas, &item_sprt, &item_export, &item_import, &item_sprt, &item_quit});
menu.insert(menu_sub_file);

// Edit:
ItemMenuSub item_copy = {"Copy"};
ItemMenuSub item_cut = {"Cut"};
ItemMenuSub item_delete = {"Delete"};
ItemMenuSub item_paste = {"Paste"};
ItemMenuSub item_selectall = {"Select All"};
MenuSub menu_sub_edit("Edit", {&item_cut, &item_copy, &item_paste, &item_delete, &item_sprt, &item_selectall});
menu.insert(menu_sub_edit);

// View:
ItemMenuSub item_scripteditor = {"Script Manager"};
ItemMenuSub item_toolbar = {"Toolbar"};
MenuSub menu_sub_view("View", {&item_toolbar, &item_sprt, &item_scripteditor});
menu.insert(menu_sub_view);

// Help:
ItemMenuSub item_contents = {"Contents"};
MenuSub menu_sub_help("Help", {&item_contents});
menu.insert(menu_sub_help);


Now, the goal is to keep things as object-oriented and easy-to-use as possible. So far things have gone well, code could still be a little cleaner, but everything works as expected.

After I managed to get this all up and running, I wondered, how to add some functionality into these submenu items, like how can one select one of them to trigger an event of some kind. This is the reason why this topic has been created.

I want ItemMenuSub-class to have a following method:

bool const is_selected(void) const;

But how should I implement this method so that it actually checks if one has selected this item from the submenu where it belongs to?
Topic archived. No new replies allowed.