void MyFrame::OnButtonClicked(wxCommandEvent& event) { int id = event.GetId(); // do something with id }
void MyFrame::OnMenuItemSelected(wxCommandEvent& event) { int id = event.GetId(); switch(id) { case wxID_OPEN: // handle open menu item break; case wxID_SAVE: // handle save menu item break; // more cases for other menu items } }In this example, we have a menu item selected event handler in a frame class. When a menu item is selected, the event object is passed to the handler function. We then call the GetId function to get the identifier of the event, which we can use to determine which menu item was selected. We can then handle each menu item separately based on its identifier. The wxCommandEvent GetId function is part of the wxWidgets library.