View Single Post
  #2 (permalink)  
Old January 20th, 2005, 05:02 PM
dheath29 dheath29 is offline
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're working too hard...try
the following from Ronen Magid on www.codeguru.com

1. Create your own CBitmap-derived class (say, CMyBitmap)
2. Add a "load from bitmap" method as listed below

BOOL CMyBitmap::LoadBitmap(LPCTSTR szFilename)
{
  ASSERT(szFilename);
  DeleteObject();

  HBITMAP hBitmap = NULL;
  hBitmap = (HBITMAP)LoadImage(NULL, szFilename, IMAGE_BITMAP, 0, 0,
             LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
  return Attach(hBitmap);
}

Then do a CStatic::SetBitmap ( hBitmap ).

I noticed that your example code is all done in C, not C++. The above code assumes using MFC and C++. The LoadImage () call is a WinAPI C-function call that returns an HBITMAP handle.
Reply With Quote