void MyFrame::OnClick(wxMouseEvent& event) { wxWindow* window = event.GetEventObject(); // get the window object on which the event occurred if (window == m_button1) { // do something if the event was generated by m_button1 } }
void MyPanel::OnMouse(wxMouseEvent& event) { wxWindow* window = event.GetEventObject(); // get the window object on which the event occurred if (window == this) { // do something if the event was generated by this panel } }In this example, we have a panel named MyPanel and a method named OnMouse that is called when the mouse is moved or clicked inside the panel. We use the GetEventObject method to determine if the event was generated by the panel itself. Package library: wxWidgets