transparent png over an bitmap - use in a button
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