May I ask who can explain the codes below a little bit? I do not quite understand these codes without any comments. Thanks a lot!
Does it mean that we need to use wxEraseEvent to paint the background image?
Thanks!
Sam
Paulsen wrote:It is truth universally acknowledged, that background images in wxWindows need to be painted in the erase event handler.
Rather than deriving individually from all those classes that may be suitable to display a background image, to setup the event table etc., it is far simpler to create one event handler class once and for all, which can be used with any wxWindow derived class.
Code: Select all
class wxBackgroundBitmap : public wxEvtHandler { typedef wxEvtHandler Inherited; public: wxBackgroundBitmap(const wxBitmap &B) : Bitmap(B), wxEvtHandler() { } virtual bool ProcessEvent(wxEvent &Event); protected: wxBitmap Bitmap; };
To change the background of e.g. a tool bar to an image, use this class like this:Code: Select all
bool wxBackgroundBitmap::ProcessEvent(wxEvent &Event) { if (Event.GetEventType() == wxEVT_ERASE_BACKGROUND) { wxEraseEvent &EraseEvent = dynamic_cast<wxEraseEvent &>(Event); wxDC *DC = EraseEvent.GetDC(); DC->DrawBitmap(Bitmap, 0, 0, false); return true; } else return Inherited::ProcessEvent(Event); }
Code: Select all
ToolBarBackground = new wxBackgroundBitmap(wxBITMAP("test")); ToolBar->PushEventHandler(ToolBarBackground);