Bitmap continued
I am down to two errors during build...
HBITMAP bmp = ::LoadImage(AfxGetInstanceHandle(), filename,
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_SHARED);
error C2440: 'initializing' : cannot convert from 'void *' to 'struct
HBITMAP__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
=====================================================================
dc.FillSolidRect(&r, &br);
error C2664: 'void __thiscall CDC::FillSolidRect(const struct tagRECT
*,unsigned long)'
cannot convert parameter 2 from 'class CBrush *' to 'unsigned long'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
=====================================================================
I still would like to know where the bitmap selection comes in.
void CShowBmp::OnPaint()
{
CPaintDC dc(this);
int filenumber;
// ... formulate filename here, based on the ID
// Example: Files are found in the project's executable directory
CString t;
LPTSTR p = t.GetBuffer(MAX_PATH);
::GetModuleFileName(NULL, p, MAX_PATH);
p=_tcsrchr(p, _T('\\'));
if(p == NULL)
{ /* not possible */
ASSERT(FALSE);
t.ReleaseBuffer();
return;
} /* not possible */
++p;
*p = _T('\0');
t.ReleaseBuffer();
CString filename;
filename.Format(_T("%s%02d.bmp"), filename, filenumber);
HBITMAP bmp = ::LoadImage(AfxGetInstanceHandle(), filename,
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_SHARED);
// Depending on what I am doing, I might add LR_LOADMAP3DCOLORS or
LR_LOADTRANSPARENT
if(bmp == NULL)
{ /* failed to load */
CRect r;
GetClientRect(&r);
// Define an error brush. To make it invisible, you might use
// a solid brush of ::GetSysColor(COLOR_3DFACE)
// or a hatched brush
// For a hatched brush, I might set a dark background color
CBrush br(HS_DIAGCROSS, RGB(0,0,0));
dc.SetBkColor(RGB(96, 96, 96));
// This can be recognized as the indication of a failure
dc.FillSolidRect(&r, &br);
return;
} /* failed to load */
CBitmap bm;
bm.Attach(bmp);
BITMAP bmd;
bm.GetBitmap(&bmd);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
int save = MemDC.SaveDC();
MemDC.SelectObject(&bm);
// I could use BitBlt or StretchBlt; I;m showing BitBlt below
dc.BitBlt(0, 0, bmd.bmWidth, bmd.bmHeight, &MemDC, 0,0, SRCCOPY);
MemDC.RestoreDC(save);
}