wxDC::Clear() problem In wxWidgets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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
        virtual bool 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
    return true;
}
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?
Last edited on
Topic archived. No new replies allowed.