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
   | // Dans ton .h
// Je considère que tout le travail se fait dans ta classe hérité de wxPanel
 
class CustomPanel : public wxPanel
{
private:
	// Attribut de classe
	wxMemoryDC * m_pMemoryDC;
	wxClientDC * m_ClientDC;
	wxBitmap m_BufferBitmap; // La bitmap utilisé par le MemoryDC
public:
	CustomPanel();
	~CustomPanel();
 
	void TracerMonDessin();
	void OnPaint(wxPaintEvent &event)
};
 
// Dans ton .cpp
 
CustomPanel::CustomPanel()
{
	m_ClientDC = new wxClientDC(this);
	m_BufferBitmap = wxBitmap(this->GetClientSize().GetWidth(), this->GetClientSize().GetHeight());
	m_pMemoryDC = new wxMemoryDC( m_BufferBitmap );
}
 
CustomPanel::~CustomPanel()
{
	if ( NULL != m_pMemoryDC )
	{
		delete m_pMemoryDC;
	}
 
	if ( NULL != m_ClientDC )
	{
		delete m_ClientDC;
	}
 
}
 
// Ta méthode de tracé
void CustomPanel::TracerMonDessin()
{
	// Tu trace ce que tu veux dans ton MemoryDC
 
	// Tu blit ton memoryDC dans ton clientDC
	this->m_ClientDC->Blit(0,0,m_BufferBitmap.GetWidth(),m_BufferBitmap.GetHeight(),m_pMemoryDC,0,0);
}
 
// Le OnPaint event
void CWxPresentationView::OnPaint(wxPaintEvent &event)
{
   wxPaintDC PaintDC(this);
 
   // Tu blit ton memory DC dans le PaintDC de cette façon tu réutilise tout le temps l'image que tu as tracé
   PaintDC.Blit->Blit(0,0,m_BufferBitmap.GetWidth(),m_BufferBitmap.GetHeight(),m_pMemoryDC,0,0);
} | 
Partager