Re: bitmap on cbutton
I see that you got it working while loading it from a resource.
But in your example you are tryign to create a rectangle on the fly and use
that.
Well the primary reason why your code is not working is that your bitmap is
going out of scope at the end of the function an the bitmap handle that you
are sending to the button is no longer a valid bitmap. So you might want to
detach the handle from the CBitmap object.
There are also some errors. Passing a NULL to CreateCompatibleDC will
create a black and white dc. You should pass a window DC if you want to
create a dc compatible with the display.
Do you deselection of the bitmap from the memory dc before you start using
the bitmap for other things, like using it in a call to SetBitmap. With
your current code it's not going to make a difference, but one day it might.
//get the window dc and create a
//compatible memory dc and bitmap
CDC *pDC = GetDC();
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC,100,40);
ReleaseDC(pDC);
//draw a rectangle on the bitmap, with default pen
CBitmap* pOldImage = dc.SelectObject(&bmp);
CRect rect(0,0,100,40);
dc.FillSolidRect(&rect,RGB(0,200,200) );
dc.SelectObject(pOldImage);
//tell OK button to use this bitmap
m_OK.SetBitmap( (HBITMAP)bmp.Detach());
AliR.
"SteveR" <maxsrussellatremovethisembarqmail.com> wrote in message
news:e3LgNy4jIHA.6084@TK2MSFTNGP06.phx.gbl...
I am experimenting with a few things in a dialog. Can someone tell me why
the following bitmap is not displaying on my OK button?
CDC dc;
dc.CreateCompatibleDC(NULL);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,100,40);
CBitmap* pOldImage = dc.SelectObject(&bmp);
CRect rect(0,0,100,40);
dc.FillSolidRect(&rect,RGB(0,200,200) );
m_OK.SetBitmap( (HBITMAP)bmp.GetSafeHandle() );
dc.SelectObject(pOldImage);