wxClientDC problem

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Danilo Namitala
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Mar 29, 2021 4:06 pm

wxClientDC problem

Post by Danilo Namitala »

Hi, i'm be beginning to use wxWidgets in a project and i'm using wxClientDc to draw on a image. I created a class that inherits wxStaticBitmap adding my properties and drawing over it. To clear the image i'm setting the background as the same wxBitmap that i used in MY image:

Code: Select all

//that is my class
class myImage : public wxStaticBitmap { 
public:	
	wxBitmap frame;  //imagem
	myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame);
private:
	void redesenha();
	void mouseUp(wxMouseEvent& event);
	void mouseDown(wxMouseEvent& event); 
	void mouseMove(wxMouseEvent& event); 
	wxDECLARE_EVENT_TABLE();
};
meuCanvas::myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame): wxStaticBitmap(parent, id, frame, pos, size){
	this->frame = frame;
}

//that is my function to clear my image
void myFrame::onClickClear(wxCommandEvent& event)
{
	wxClientDC dc(myImg);
	dc.SetBackground(wxBrush(myImg->frame)); //frame is a wxBitmap type
	dc.Clear();
}
The issue is that works in my laptop but when my friend download and compile it's doesn't work in his laptop.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxClientDC problem

Post by ONEEYEMAN »

Hi,
Please do not cross-post in a different forums - it just slow people down.

Also - please update the question with the info I requested on SO.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxClientDC problem

Post by doublemax »

Don't use wxClientDC, catch the wxPaintEvent and then draw your image onto the wxPaintDC.
https://docs.wxwidgets.org/trunk/classw ... event.html

https://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
Use the source, Luke!
Post Reply