However when I do either of the following:
1. comment out the two lines with [#1] related to the scrollbar, or
2. comment out the single line containing [#2] related to binding the mouse event wxEVT_LEFT_DOWN
... then the wxEVT_KEY_DOWN event is caught. So I don't quite know what's going on
Code: Select all
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame();
private:
void OnKeyPress(wxKeyEvent& event);
void OnMousePress(wxMouseEvent& event);
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "")
{
wxScrollBar * scrollbar = new wxScrollBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL); // #1
wxPanel* panel = new wxPanel(this, wxID_ANY);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
hbox->Add(panel, 1, wxEXPAND, 0);
hbox->Add(scrollbar, 0, wxEXPAND, 0); // #1
SetSizer(hbox);
panel->Bind(wxEVT_KEY_DOWN, &MyFrame::OnKeyPress, this); // this doesn't work. Only works if I replace it with wxEVT_KEY_UP
panel->Bind(wxEVT_LEFT_DOWN, &MyFrame::OnMousePress, this); // #2
}
void MyFrame::OnKeyPress(wxKeyEvent& event)
{
wxLogMessage("Key press event captured!");
}
void MyFrame::OnMousePress(wxMouseEvent& event)
{
wxLogMessage("Mouse press event captured!");
}