wxPaintDC 이해하기


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;
}

- 목록:

3 thoughts on “wxPaintDC 이해하기

  1. 공유해주신 동영상에서 많은 것을 배우고 있습니다. 감사합니다.
    윈도우에서 GUI 프로그래밍을 가끔 하지만, RAD 툴에서 만들어주는 코드를 약간 변형하는 정도입니다.
    동영상을 보다보니, 툴이 생성해주는 코드들에 대해 좀 더 이해할 수 있을 것 같습니다.
    wxSmith 를 이용하여 wxWidget 를 사용하려 알아보는 중인데, 설명을 들으니 wxSmith 나 wxFormWBuilder 가 해주는 일을 약간은 이해할 수 있게 된 것 같습니다. 해당 툴을 사용하는데 많은 도움이 될 것 같습니다.
    좋은 강좌에 감사드립니다.

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>