From: Manuel Hoeger on
Hi,

I want to overdraw an Image on a CWnd Object with a second Image including
transparent parts.
But I can see the first Image through the second Image.

I can't use fillRect because I I want to see the Background of the CWnd
Object behind it.

Is it possible to clear the CWnd so that I have a "transparent" Background
as it is on creation?



I am using two CImage Objects and two png Images
On Mousemove I change the CImage Pointer mp_ActiveBook to the second CImage
Object and onMouseleave I switch the pointer again and call OnPaint


void CLitBoardItem::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
Invalidate(1);

DrawItem();

CWnd::OnPaint();


}

int CLitBoardItem::DrawItem(void)
{
CWindowDC pDC(this);
mp_ActiveBook->AlphaBlend(pDC.m_hDC,0,0,255,0);
return 0;
}


Thanks for Answers

Manu

From: Seetharam on
>>I can't use fillRect because I I want to see the Background of the CWnd Object behind it.
Is your window background transparent so that you see contents of your
desktop/windows behind it?
If not, then before drawing your new image in the window, just do a
fill rect with whatever color/background the window background needs
to be.

-Seetharam


From: Joseph M. Newcomer on
See below...
On Mon, 1 Mar 2010 14:16:34 +0100, "Manuel Hoeger"
<Manuel.Hoeger(a)physik.stud.uni-erlangen.de> wrote:

>Hi,
>
>I want to overdraw an Image on a CWnd Object with a second Image including
>transparent parts.
>But I can see the first Image through the second Image.
****
Define what you mean by this. You said you wanted transparent parts, which means you will
be able to see the first image through the second, at least at the transparent parts. Or
are you seeing it in some other way? Are you creating a transparent window in some way,
or using alpha blending? The only alpha blending I see is 255 (100%, no transparency).
****
>
>I can't use fillRect because I I want to see the Background of the CWnd
>Object behind it.
****
You wouldn't use FillRect to draw a picture
****
>
>Is it possible to clear the CWnd so that I have a "transparent" Background
>as it is on creation?
****
Override OnEraseBkgnd and do nothing. In OnPaint, do nothing if there is nothing to draw.
****
>
>
>
>I am using two CImage Objects and two png Images
>On Mousemove I change the CImage Pointer mp_ActiveBook to the second CImage
>Object and onMouseleave I switch the pointer again and call OnPaint
****
I hope you do NOT "call" OnPaint. If you did
switch pointers
OnPaint();
it cannot POSSIBLY work, ever. So whatever you are getting is no indication of correct
behavior. If, on the other hand, you did
switch pointers
Invalidate();
UpdateWindow();
then it should work. So if you are doing the first, you get undefined results, and you
won't know what you have until you fix it to represent the second form.

When a WM_PAINT message is issued, the clipping region of the window has been computed
properly, and the clipping areas are all you can draw into. If you just call OnPaint,
there is no clipping area (it is actually undefined), so who knows what's going to happen?
I don't, except that it will not be right.
****
>
>
>void CLitBoardItem::OnPaint()
>{
> CPaintDC dc(this); // device context for painting
> CRect rect;
> Invalidate(1);
****
This is clearly a mistake, in several ways
Invalidate() takes a BOOL operator, e.g., TRUE or FALSE. Why you would
write an integer there escapes me.
The default argument is TRUE, so no argument needs to be supplied
You would NEVER call Invalidate() in an OnPaint handler because
the whole POINT of OnPaint is to revalidate!
****
>
> DrawItem();
>
> CWnd::OnPaint();
*****
You should not be calling CWnd::OnPaint.
*****
>
>
>}
>
>int CLitBoardItem::DrawItem(void)
>{
> CWindowDC pDC(this);
> mp_ActiveBook->AlphaBlend(pDC.m_hDC,0,0,255,0);
****
This seems overkill; you are effectively doing a BitBlt/SRC_COPY. And note that the last
argument of AlphaBlend must either be omitted, or be AC_SRC_OVER; I have NO IDEA how you
could imagine that "0" could possibly make sense here. Read the documentation! At no
point does it EVER indicate that "0" is a valid value for the last parameter. And NEVER,
EVER "look inside" a header file to find what a symbolic value is so you can write the
integer instead of the specified name!

Note that you didn't have to write 255 either; that's the default!
****
> return 0;
>}
>
>
>Thanks for Answers
>
>Manu
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Manuel Hoeger on


> Define what you mean by this. You said you wanted transparent parts,
> which means you will
> be able to see the first image through the second, at least at the
> transparent parts. Or
> are you seeing it in some other way? Are you creating a transparent
> window in some way,
> or using alpha blending? The only alpha blending I see is 255 (100%, no
> transparency).

Yes I see the first Image through the second.
But I actually want to replace one bitmap with the other. and I want to
see the background of the parent CWnd.
I dont wan't to use alphablending yet, but maybe in future.



> Override OnEraseBkgnd and do nothing. In OnPaint, do nothing if there is
> nothing to draw.

Ok I did.

> I hope you do NOT "call" OnPaint. If you did
> switch pointers
> OnPaint();
> it cannot POSSIBLY work, ever. So whatever you are getting is no
> indication of correct
> behavior. If, on the other hand, you did
Now I don't call OnPaint but DrawItem() directly from OnMouseMove and
OnmouseLeave:


void CLitBoardItem::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: F�gen Sie hier Ihren Meldungsbehandlungscode ein, und/oder
benutzen Sie den Standard.


mp_ActiveBook=&m_BookImageOpen;
DrawItem();


CWnd::OnMouseMove(nFlags, point);
}

void CLitBoardItem::OnMouseLeave()
{
m_bMouseTracking = FALSE;

mp_ActiveBook=&m_BookImage;
DrawItem();


CWnd::OnMouseLeave();
}

int CLitBoardItem::DrawItem(void)
{
CWindowDC pDC(this);
CRect rect;

Invalidate();
UpdateWindow();

mp_ActiveBook->AlphaBlend(pDC.m_hDC,0,0);
return 0;
}

The OnPaint is now empty.




From: Joseph M. Newcomer on
You will have to "erase" the original image by writing the transparent pixels over it.

What you have done, apparently, works like this. Let T be the transparent color and other
letters opaque

Current picture
TTTabcTTT

New picture
TTTxTwTTT

Result of OnPaint after current image is replaced with new image and repainted:

TTTxbwTTT

So in this case, you either draw all-transparent or use OnEraseBkgnd to erase to the
transparent color. Because the color b was overwritten by a transparent pixel, it remains
in place, because you did nothing to make it go away.

Remember, the writing of a transparent color is the logical equivalent of an "OR"
operation, e.g.,

000111001
overwritten using "OR" by the pattern
000101000
leaves you
000111001

So note that bits 0 (rightmost) and 4 do not change, giving the illusion that the older
picture is still there.
joe


On Mon, 1 Mar 2010 18:25:32 +0100, "Manuel Hoeger"
<Manuel.Hoeger(a)physik.stud.uni-erlangen.de> wrote:

>
>
>> Define what you mean by this. You said you wanted transparent parts,
>> which means you will
>> be able to see the first image through the second, at least at the
>> transparent parts. Or
>> are you seeing it in some other way? Are you creating a transparent
>> window in some way,
>> or using alpha blending? The only alpha blending I see is 255 (100%, no
>> transparency).
>
>Yes I see the first Image through the second.
>But I actually want to replace one bitmap with the other. and I want to
>see the background of the parent CWnd.
>I dont wan't to use alphablending yet, but maybe in future.
>
>
>
>> Override OnEraseBkgnd and do nothing. In OnPaint, do nothing if there is
>> nothing to draw.
>
>Ok I did.
>
>> I hope you do NOT "call" OnPaint. If you did
>> switch pointers
>> OnPaint();
>> it cannot POSSIBLY work, ever. So whatever you are getting is no
>> indication of correct
>> behavior. If, on the other hand, you did
>Now I don't call OnPaint but DrawItem() directly from OnMouseMove and
>OnmouseLeave:
>
>
>void CLitBoardItem::OnMouseMove(UINT nFlags, CPoint point)
>{
> // TODO: F�gen Sie hier Ihren Meldungsbehandlungscode ein, und/oder
>benutzen Sie den Standard.
>
>
> mp_ActiveBook=&m_BookImageOpen;
> DrawItem();
>
>
> CWnd::OnMouseMove(nFlags, point);
>}
>
>void CLitBoardItem::OnMouseLeave()
>{
> m_bMouseTracking = FALSE;
>
> mp_ActiveBook=&m_BookImage;
> DrawItem();
>
>
> CWnd::OnMouseLeave();
>}
>
>int CLitBoardItem::DrawItem(void)
>{
> CWindowDC pDC(this);
> CRect rect;
>
> Invalidate();
> UpdateWindow();
>
> mp_ActiveBook->AlphaBlend(pDC.m_hDC,0,0);
> return 0;
>}
>
>The OnPaint is now empty.
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 |  Next  |  Last
Pages: 1 2
Prev: VS 2008
Next: Printing to multiple pages (horizontally)