DC의 사용 예 – background 이벤트와 foreground(Paint) 이벤트


MyFrame.h
#pragma  once

#include  <wx/wx.h>

class  MyFrame:public  wxFrame
{
private:
   wxBitmap bitmap_;


public:
    MyFrame(const  wxString& title);
    ~MyFrame(void);
private:
   void OnErase(wxEraseEvent& event);
   void afterdc(wxDC& dc);

   void OnFore(wxPaintEvent& event);
};

class  MyApp:public  wxApp
{
public:
    MyApp(void);
    ~MyApp(void);

   virtual  bool OnInit();
};

DECLARE_APP(MyApp);

MyFrame.cpp
#include  "MyFrame.h"


MyFrame::MyFrame(const  wxString& title)
    :wxFrame(NULL, wxID_ANY, title)
{
    bitmap_.LoadFile("bird4.jpg", wxBITMAP_TYPE_JPEG);
   
   this->Bind(wxEVT_ERASE_BACKGROUND,&MyFrame::OnErase, this);
   this->Bind(wxEVT_PAINT, &MyFrame::OnFore, this);

   this->SetBackgroundStyle( wxBG_STYLE_CUSTOM);

   wxBoxSizer* m = new  wxBoxSizer(wxHORIZONTAL);

   wxButton* btn = new  wxButton(this,-1, "Test");
    m->Add(btn,0,wxALL, 5);


   this->SetSizer(m);
}


void
MyFrame::OnFore(wxPaintEvent& event){
   wxPaintDC dc(this);
    dc.Clear();
    dc.DrawCircle(wxPoint(100,100), 50 );
}


void
MyFrame::OnErase(wxEraseEvent& event){
   if( event.GetDC()){
       afterdc( *event.GetDC());
      return;
   }

   wxClientDC dc(this);
    afterdc(dc);
}

void 
MyFrame::afterdc(wxDC& dc){
   dc.Clear();
   if( !this->bitmap_.IsOk()) return;

   dc.DrawBitmap( this->bitmap_, wxPoint(0,0));

}


MyFrame::~MyFrame(void)
{
}


MyApp::MyApp(void)
{
}


MyApp::~MyApp(void)
{
}

IMPLEMENT_APP(MyApp);

bool
MyApp::OnInit(){
    wxInitAllImageHandlers();

   wxFrame* m = new  MyFrame("DC1");
    m->Show(true);
   return  true;
}

- 목록:

2 thoughts on “wxPaintDC 이해하기

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>