MyFrame.h
#pragma once
#include <wx/wx.h>
class MyFrame:public wxFrame
{
private:
wxPoint start_;
wxPoint end_;
public:
MyFrame(const wxString& title);
~MyFrame(void);
private:
void OnPaint(wxPaintEvent& event);
void OnDown(wxMouseEvent& event);
void OnUp(wxMouseEvent& event);
};
class MyApp:public wxApp
{
public:
MyApp(void);
~MyApp(void);
virtual bool OnInit();
};
DECLARE_APP(MyApp);
MyFrame.cpp
#include "MyFrame.h"
#include <wx/dcbuffer.h>
IMPLEMENT_APP(MyApp);
MyFrame::MyFrame(const wxString& title)
:wxFrame(NULL, -1, title)
{
this->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
this->Bind(wxEVT_PAINT,&MyFrame::OnPaint, this);
this->Bind(wxEVT_LEFT_DOWN, &MyFrame::OnDown, this);
this->Bind(wxEVT_LEFT_UP, &MyFrame::OnUp, this);
}
void
MyFrame::OnDown(wxMouseEvent& event){
wxClientDC cdc(this);
wxBufferedDC dc(&cdc);
dc.DrawCircle( 0,0,30);
wxBitmap& map = dc.GetSelectedBitmap();
map.SaveFile("c:\\Client.jpg", wxBITMAP_TYPE_JPEG);
this->start_ = event.GetPosition();
}
void
MyFrame::OnUp(wxMouseEvent& event){
this->end_ = event.GetPosition();
this->RefreshRect( wxRect(start_, end_) );
}
void
MyFrame::OnPaint(wxPaintEvent& event){
//wxPaintDC dc(this);
wxBufferedPaintDC dc(this);
wxRect invalid_rect = this->GetUpdateClientRect();
dc.SetPen( wxColor(255,0,0) );
dc.DrawRectangle( invalid_rect);
wxBitmap& map = dc.GetSelectedBitmap();
map.SaveFile("c:\\paint.jpg", wxBITMAP_TYPE_JPEG);
}
MyFrame::~MyFrame(void)
{
}
MyApp::MyApp(void)
{
}
MyApp::~MyApp(void)
{
}
bool
MyApp::OnInit(){
wxInitAllImageHandlers();
wxFrame* mx = new MyFrame("Paint1");
mx->Show(true);
return true;
}