Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a bitmap in a view

Status
Not open for further replies.

bulgakov

Programmer
Apr 24, 2003
26
GB
hello all,
I am trying to display a bitmap in a rectangle on a view.
I have written this to do it...

void MyView::OnDraw(..)
{
HBITMAP MyBitmap = (HBITMAP)::LoadImage(0,"bit1.bmp", IMAGE_BITMAP, 0 ,0 ,LR_LOADFROMFILE);
CStatic BitDraw;
BitDraw.Create("", SS_BITMAP, ToDraw, this);
BitDraw.SetBitmap((HBITMAP)MyBitMap);
}
I have tried changing the CStatic from an auto object
to a dynamic (using new), but still no joy.

So any ideas please?

Marcus
 

Creating a CStatic object on the stack means that when it goes out of scope its destructor will be called (which will destroy the window). I'm not sure why creating the object on the heap failed...

But really, that's a really weird way to do things. I don't see why you can't do it the usual way with LoadImage (storing the HBITMAP as a member variable), and CreateCompatibleDC, SelectObject and BitBlt.

I REALLY hope that helps.
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top