Re: transparent png over an bitmap - use in a button
It was kinda hard to read the while loop and the if statments because there
were no brackets, but after I got it parsed out, I noticed that your if
statment uses the assignment operator instead of ==, and honestly I don't
see the point of the loop. You are going to go back until the parent
doesn't have a WS_CHILD flag? Why, what if the dialog that is the parent of
the button is a child of another dialog.
Also not sure what you are doing with the rectangles.
I think this should be enough:
CRect Rect;
GetWindowRect(&Rect);
GetParent()->ScreenToClient(&Rect);
GetParent()->InvalidateRect(&Rect);
GetParent()->UpdateWindow();
But after all of that if you call the parent windows InvalidateRect from
within a WM_PAINT or WM_ERASEBKGND you will end up with an infinate loop.
Checkout Codeproject for some examples on how to do transparent buttons.
AliR.
"fiversen" <fiversen@wedding.in-berlin.de> wrote in message
news:4abc8c43-d3e3-46d0-be7c-407ab2aaae98@i29g2000prf.googlegroups.com...
Hello,
I draw a transparent png-file above an bitmap background and
it works very good.
I see a small figure above a structured bitmap.
----------------------------------------------------
//background - bitmap
{
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(bgBit);
int nX = 0;
int nY = 0;
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
}
// foreground bitmap
{
Gdiplus::Graphics _g(pDC->GetSafeHdc());
Gdiplus::PointF _p(400,10);
_g.DrawImage(imgEx, _p);
}
----------------------------------------------------
I want to use this feature also in a button.
I have two png-files - up-state and down-state -
and I want to display them.
The MyGdiBut::DrawItem function works well,
it display the png-files in the different states.
I have already a function, which erase the background.
void MyGdiBut::InvalidateBkg()
{
RECT rbw, rpw, rbc, r3;
GetClientRect(&rbc);
GetWindowRect(&rbw);
CWnd *w1 = GetParent(), *w2 = GetParent();
while (1)
if (w1 = w1->GetParent())
if (w1->GetStyle() & WS_CHILD)
w2 = w1;
else
break;
else
break;
w2->GetWindowRect(&rpw);
r3.left = rbw.left - rpw.left;
r3.top = rbw.top - rpw.top;
r3.right = r3.left + (rbc.right - rbc.left);
r3.bottom = r3.top + (rbc.bottom - rbc.top);
GetParent()->InvalidateRect(&r3);
}
My problems are
- the button is not transparent
- if I call InvalidateBkg()
in 'OnEraseBkgnd(CDC* pDC)' or
in 'void MyGdiBut::DrawItem(LPDRAWITEMSTRUCT lpDIS)'
the repainting never stops.
---
Thanks for help.
Frank Iversen