#include <wx/wx.h>
// application class
class MyFrame : public wxFrame
{
public:
// Constructor
MyFrame(const wxString& title, long style=wxDEFAULT_FRAME_STYLE);
// Event handlers
void OnMouse(wxMouseEvent& event);
void OnPaint(wxMouseEvent& event);
void OnClear(wxCommandEvent& event);
wxPoint Start;
wxClientDC *Canvas;
private:
// This class handles events
DECLARE_EVENT_TABLE()
};
class MyApp : public wxApp
{
public:
// function called at the application initialization
virtualbool OnInit();
};
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_BUTTON(wxID_CLEAR, MyFrame::OnClear)
END_EVENT_TABLE();
void MyFrame::OnMouse(wxMouseEvent& event)
{
Canvas = new wxClientDC(this);
Start = event.GetLogicalPosition(*Canvas);
}
void MyFrame::OnPaint(wxMouseEvent& event)
{
Canvas->DrawLine(Start,event.GetLogicalPosition(*Canvas));
}
void MyFrame::OnClear(wxCommandEvent& event)
{
Canvas->Clear();
}
bool MyApp::OnInit()
{
// create a new frame and set it as the top most application window
MyFrame *frame = new MyFrame(wxT("Paint"));
// show main frame
frame->Show(true);
// enter the application's main loop
returntrue;
}
MyFrame::MyFrame(const wxString& title, long style):
wxFrame(NULL, wxID_ANY, title)
{
wxPanel *panel = new wxPanel(this);
wxButton *ClearBoard=new wxButton(panel,wxID_CLEAR,wxT("Clear Board"));
panel->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(MyFrame::OnMouse));
panel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(MyFrame::OnPaint));
}
It says error every time you click the clear button. Does anyone know how to fix it?