说明

    从wxControl中派生出一个控件,调用OnPaint函数对控件进行渲染

例子


头文件

#include "wx/bitmap.h"

#include "wx/control.h"

#include "wx/dcclient.h"


声明

class CFlightInstrumentCompass : public wxControl

{

private:

DECLARE_DYNAMIC_CLASS(CFlightInstrumentCompass)

DECLARE_EVENT_TABLE()


public:

CFlightInstrumentCompass() {Init();}

void Init() {}


CFlightInstrumentCompass(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator)

{

Init();

Create(parent, id, pos, size, style, validator);

}


bool Create(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator);

~CFlightInstrumentCompass(void);


protected:

void OnPaint(wxPaintEvent& event);

};


定义


BEGIN_EVENT_TABLE(CFlightInstrumentCompass, wxControl)

EVT_PAINT(CFlightInstrumentCompass::OnPaint)

END_EVENT_TABLE()

IMPLEMENT_DYNAMIC_CLASS(CFlightInstrumentCompass, wxControl)


void CFlightInstrumentCompass::OnPaint( wxPaintEvent& event )

{

}


提醒

    为了减少闪烁,重写OnEraseBackground函数,并且留空,说明不再需要擦除背景