[wxMSW][wx3.0.3] Get menu-item label on click of a dynamically added menu in toolbar Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

[wxMSW][wx3.0.3] Get menu-item label on click of a dynamically added menu in toolbar

Post by Rudra »

Hi,

In my wx application, I have wxITEM_DROPDOWN tool in which I am adding menu-items dynamically as follows,

Code: Select all

m_tooBar = new wxToolBar(m_titlePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_NODIVIDER|wxTB_HORZ_TEXT);
m_tooBar->AddTool(wxID_LOAD, wxT("Load"), wxMEMORY_PNG(ICON_LOAD),
				  wxMEMORY_PNG(ICON_LOAD), wxITEM_DROPDOWN,
				  wxEmptyString, wxEmptyString, NULL);

xMenu *loadMenu = new wxMenu;
for(size_t iter = 0; iter < gloadMenuList.size(); ++ iter)
	loadMenu->Append(wxID_ANY, gloadMenuList[iter]);
	
m_tooBar->SetDropdownMenu(wxID_LOAD, loadMenu);
m_tooBar->Realize();
The menu-items count is not fixed so I used wxID_ANY while appending the menu-item.

On click, I get event but unable to figure out which menu-item is clicked. The menu-item label is unique so I want to know it to process further.

Please suggest.

Thanks,
R.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.3] Get menu-item label on click of a dynamically added menu in toolbar

Post by doublemax »

loadMenu->Append() returns a wxMenuItem. With wxMenuItem::GetId() you can retrieve the ID it was assigned. With that ID you can create a logical connection to another piece of information, e.g. through a hashmap.
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.3] Get menu-item label on click of a dynamically added menu in toolbar

Post by Rudra »

Thanks for the reply. It works for me.
Post Reply