How to add a semi-transparent gray rectangle on top of a bitmap

My MFC form is covered with a background bitmap.
This is done by adding a bitmap to a CImageList : (1 - See code attached)
and then, at the WM_PAINT handler, calling (2)

Now - sometimed I need to mark a rectangle on the bitmap as inactive/disabled.
I would like to draw a gray rectangle, make it semi - transparent and show it on top of the form.

Is it possible at all?
Any ideas how to do it?
m_BitmapBG.GetBitmap( &bm );
m_imageListBG.Create(bm.bmWidth,bm.bmHeight,ILC_COLOR24 | ILC_MASK ,1,1);

CPoint pt(0, 0);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi yossikally,

I'm not sure if there's another, easier way, but I would try doing this by creating a bitmap with the rectangles shape/color and draw it transparent using 'AlphaBlend' function. To get this working without flickering you should first copy the background image into a memory DC, then do the 'AlphaBlend' from the rectangle's bitmap into that memory DC, then 'BitBlt' the content of the memory DC into your window's DC.

Hope that helps,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yossikallyAuthor Commented:
Wish It had been as easy as it is on MAC/iPhone
Hm - I just looked around a bit more and found there may be an easier (and maybe more performant) possibility, but will require the use of GDI+.

GDI+ has a 'Graphics::FillRectangle' function which takes a brush as paramter. This brush can be created from a RGBA color, so transparency is supported via Alpha-channel.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.