CBitmapButton:LoadBitmaps() question....
Hello...
I am using CBitmapButton class for creating buttons and using LoadBitmaps() function to load bitmaps. In my application I need to change the bitmaps several times. Thus there will be significant no of calls to LoadBitmaps()
My question is whether LoadBitmaps() erases previously loaded bitmaps. If not then it will eat up the memory. Is there any way I can remove those bitmaps from the memory.
Thanks.
Re: CBitmapButton:LoadBitmaps() question....
The source code for the function is:
Code:
// LoadBitmaps will load in one, two, three or all four bitmaps
// returns TRUE if all specified images are loaded
BOOL CBitmapButton::LoadBitmaps(LPCTSTR lpszBitmapResource,
LPCTSTR lpszBitmapResourceSel, LPCTSTR lpszBitmapResourceFocus,
LPCTSTR lpszBitmapResourceDisabled)
{
// delete old bitmaps (if present)
m_bitmap.DeleteObject();
m_bitmapSel.DeleteObject();
m_bitmapFocus.DeleteObject();
m_bitmapDisabled.DeleteObject();
if (!m_bitmap.LoadBitmap(lpszBitmapResource))
{
TRACE(traceAppMsg, 0, "Failed to load bitmap for normal image.\n");
return FALSE; // need this one image
}
BOOL bAllLoaded = TRUE;
if (lpszBitmapResourceSel != NULL)
{
if (!m_bitmapSel.LoadBitmap(lpszBitmapResourceSel))
{
TRACE(traceAppMsg, 0, "Failed to load bitmap for selected image.\n");
bAllLoaded = FALSE;
}
}
if (lpszBitmapResourceFocus != NULL)
{
if (!m_bitmapFocus.LoadBitmap(lpszBitmapResourceFocus))
bAllLoaded = FALSE;
}
if (lpszBitmapResourceDisabled != NULL)
{
if (!m_bitmapDisabled.LoadBitmap(lpszBitmapResourceDisabled))
bAllLoaded = FALSE;
}
return bAllLoaded;
}
So yes, the previous loaded bitmaps, if any, are destroyed.
Re: CBitmapButton:LoadBitmaps() question....
Hi Cilu..
Thanks a lot for that.
:thumb:
Re: CBitmapButton:LoadBitmaps() question....
Hello,
For me, this function doesn't work (under Visual C++ 6).
I had to rewrite it like this :
Code:
BOOL CMyBitmapButton::LoadBitmaps(LPCTSTR lpszBitmapResource, LPCTSTR lpszBitmapResourceSel, LPCTSTR lpszBitmapResourceFocus, LPCTSTR lpszBitmapResourceDisabled)
{
HBITMAP hBitmap = NULL;
// delete old bitmaps (if present)
m_bitmap.DeleteObject();
m_bitmapSel.DeleteObject();
m_bitmapFocus.DeleteObject();
m_bitmapDisabled.DeleteObject();
hBitmap = (HBITMAP)LoadImage(NULL, lpszBitmapResource, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if (!hBitmap)
{
TRACE(traceAppMsg, 0, "Failed to load bitmap for normal image.\n");
return FALSE; // need this one image
}
m_bitmap.Attach(hBitmap);
BOOL bAllLoaded = TRUE;
if (lpszBitmapResourceSel != NULL)
{
hBitmap = (HBITMAP)LoadImage(NULL, lpszBitmapResourceSel, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if (!hBitmap)
{
TRACE(traceAppMsg, 0, "Failed to load bitmap for selected image.\n");
bAllLoaded = FALSE;
}
else{
m_bitmapSel.Attach(hBitmap);
}
}
if (lpszBitmapResourceFocus != NULL)
{
hBitmap = (HBITMAP)LoadImage(NULL, lpszBitmapResourceFocus, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if (!hBitmap){
bAllLoaded = FALSE;
}
else{
m_bitmapFocus.Attach(hBitmap);
}
}
if (lpszBitmapResourceDisabled != NULL)
{
hBitmap = (HBITMAP)LoadImage(NULL, lpszBitmapResourceDisabled, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if (!hBitmap){
bAllLoaded = FALSE;
}
else{
m_bitmapDisabled.Attach(hBitmap);
}
}
return bAllLoaded;
}