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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CBitmap::LoadBitmap problem 1

Status
Not open for further replies.

cello1000

Programmer
Jul 23, 2003
3
US
I'm using a multiple document interface program which saves its files as bitmaps. I also want to load bitmaps, so I do this:

BOOL CImageDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;

// TODO: Add your specialized creation code here
m_bmpImage.LoadBitmap(lpszPathName);

return TRUE;
}

For some reason, LoadBitmap always returns 0. Can someone help me? I just need to load an image.
 
Well, as MSDN states on CBitmap::LoadBitmap():

"Initializes the object by loading a named bitmap resource from the application's executable file and attaching the bitmap to the object.""

Ie LoadBitmap does't load from a file, but from the application's resources.

Use the LoadImage function:

/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
try with this:

HBITMAP hb;
BITMAP bm;
//the object HBITMAP load the bitmap from a file
hb = (HBITMAP) LoadImage(AfxGetInstanceHandle(), lpszPathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);

//now you attach it to a CBitmap
VERIFY(m_bmpImage.Attach(hb));

VERIFY(m_bmpImage.GetBitmap(&bm));

it should work,

i hope this is useful.

bye
D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top