wxBitmap display on a panel/frame
Sanghamitra Biswas
SBiswas at sirf.com
Mon Jul 9 04:39:00 PDT 2007
I'm new to the Windows GUI programming. I need to display the bitmap on
the screen at the start Up. How do I invoke the OnPaint event of the
MyFrame at start up?
My Constructor is as follows:
Create certain menus and add them to menubar.
Init certain list controls.
Some extra processing.
-----Original Message-----
From: Stephan Rose [mailto:kermos at somrek.net]
Sent: Monday, July 09, 2007 4:43 PM
To: wx-users at lists.wxwidgets.org
Subject: Re: wxBitmap display on a panel/frame
On Mon, 2007-07-09 at 14:57 +0530, Sanghamitra Biswas wrote:
>
> Hi,
>
> One more beginners' question. How can I paint a bitmap on a panel or
> frame?
>
> I have the following set of code:
>
> void MyFrame::DisplayImageOnPanel()
> {
> wxBitmap* bmp = new wxBitmap(_T("test"),wxBITMAP_TYPE_BMP_RESOURCE);
> wxClientDC dc(m_panel);
> PrepareDC(dc);
> this->PrepareDC(dc);
> dc.DrawBitmap(*bmp, 0, 0);
> }
>
> This function is called from:
> MyFrame::MyFrame(const wxString& title)
> : wxFrame(NULL, wxID_ANY, title)
>
>
> But this doesn't display the bitmap. But the bitmap has been loaded
all
> right.
> Please tell me if I have missed something.
Yep you did. You are trying to draw from the constructor, a really bad
idea.
Instead, draw from your OnPaint event, that is what it is there for.
In your Event table, add the following line:
EVT_PAINT(MyFrame::OnPaint)
Then add the following function to the class:
void MyFrame::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
// Drawing code next
}
Then go use that dc to paint.
No need to call "PrepareDC" or anything, just use it.
Also for best results performance-wise, I suggest you make the bitmap
pointer variable a member of your class, load it at startup, and then
you can just use it during OnPaint without needing to reload it from the
hard drive.
Just make sure to deallocate it again in your class' destructor.
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
More information about the wx-users
mailing list