Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Gdi Overlay drawing

244 views
Skip to first unread message

beauwlf

unread,
Jan 15, 2009, 8:32:39 PM1/15/09
to
Hi

I want to achieve a true overlay drawing method.

My SDI view has an image, i want to draw on a overlay surface on top of this
image, This drawing should be erased without corrupting the image (hence
overlay drawing).

Most example i find on the net shows drawing on OnPaint / OnDraw handlers
only..
I have few classes that is doing DC drawing on a memory DC. And once all
drawing is done i bitblt the mem DC drawing on to the screen. My problem is
the memDC bitmap is not transparent, so how to create/set a bitmap to
Transparent.. ?

i have tried the masking method but they result in my drawing colours being
corrupted if that portion of the background image is too bright...


~Blessed 2009~
Regards


Joseph M. Newcomer

unread,
Jan 16, 2009, 1:02:26 AM1/16/09
to
Well, this consists of
(a) drawing the image
(b) drawing the overlay stuff on top of it

Note that since (b) is a separate step, it doesn't change the image.

And indeed you want to do it in the OnPaint/OnDraw handlers.

Note that you can do it to a memory DC, because (a) and (b) above don't care if they are
drawing to the screen or a memory DC.

You would have to use alpha-blending, and therefore not BitBlt but use CDC::AlphaBlend.

Note the problem about "drawing colors being corrupted" deals with how colors combine, and
that is not going to magically fix itself, because it is a function of how the
transparency works. That is, if you take a piece of transparent red cellophane and place
it over a color image, blues look black, yellows look orange, etc., and you should expect
to see that phenomenon here as well.

Does this help?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

beauwlf

unread,
Jan 16, 2009, 3:15:42 AM1/16/09
to

"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:rc80n45fr3ioqt0vv...@4ax.com...

> Well, this consists of
> (a) drawing the image
> (b) drawing the overlay stuff on top of it

> You would have to use alpha-blending, and therefore not BitBlt but use

> CDC::AlphaBlend.
>
> Note the problem about "drawing colors being corrupted" deals with how
> colors combine, and
> that is not going to magically fix itself, because it is a function of how
> the
> transparency works. That is, if you take a piece of transparent red
> cellophane and place
> it over a color image, blues look black, yellows look orange, etc., and
> you should expect
> to see that phenomenon here as well.
>
> Does this help?
> joe
>

Yes it does joe..

but unable to use AlphaBlend, AC_SRC_ALPHA is not defined in wingdi.h of
my system. plus AlphaBlend exist as a win32 SDK function not a member of MFC
CDC:: . I am still using VS6.0

then i tried TransparentBlt.... since my drawing already have a coloured
background... i just specified that background colour to be transparent
using TransparentBlt..
then it worked! ... thank you Joe..

Joseph M. Newcomer

unread,
Jan 16, 2009, 9:41:38 AM1/16/09
to
Note that if you have a function
CDC::whatever(...)
that is defined in modern Win32, but isn't defined for MFC, well, it is a rather trivial
transformation to write
::whatever(dc, ...)
where dc is of type CDC. The (HDC) operator of CDC will cause the compiler to do the
right thing. It is unfortunate, but even in VS2008 they haven't brought MFC up to the
level of the Win32 API and you have to do this a lot.

Glad TransparentBlt works for you.
joe

0 new messages