my 2nd reply.
Now the bitmap displays BUT it is not within the picture window.
the bottom and right of the ShowBmp box.
On 1/10/2011 4:52 PM, Joseph M. Newcomer wrote:
On Mon, 10 Jan 2011 15:05:54 -0500, Ed<me@right.her> wrote:
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
=====================================================================
****
This is pretty elementary C programming, something you really shouldl have figured out on
your own. A cast is required, as I pointed out in my reply in the earlier thread. I'm
very surprised you couldn't figure out something this simple.
****
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);
****
My error; this should have said
filename.Format(_T("%s%02d.bmp"), t, filenumber);
I changed the name and didn't catch all the uses.
****
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);
}
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm