I've been experimenting with GDI+ and i managed to draw 2 PNG in a button button.
1 for the normal state
and one for the Clicked (down state)
but when i click the button,the down state image gets draw on top of the normal state, and when i release the button,the normal state image gets drawn on top of the down state.
I don't want this,I want to when the button is in the down state,erase the normal state png and draw the new Down state png and so forth with the normal state.
i made an example so you have a basic idea of what i mean.
this is the dialog with the button un clicked.
http://i14.photobucket.com/albums/a325/AntiBNI/beforeclick.jpg
and this is what happends when i click the button (Down state)
Note that the check mark png draws on top of the logo,you can still see part of the logo.
http://i14.photobucket.com/albums/a325/AntiBNI/Clicked.jpg
And this is what happends when i release the button (normal state again)
note that the logo gets drawn on top of the check mark png.
http://i14.photobucket.com/albums/a325/AntiBNI/AfterClick.jpg
But if i drag the dialog off screen,the dialog redraws and the back png gets erased.
How can i erase the back png without having to move the dialog off screen?
Here's the part of the code where the button gets drawn with the png.
Note: "MyButton" is a derived class from CButton.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
void MyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
Gdiplus::GdiplusStartupInput gdiplusstartupinput;
Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusstartupinput,NULL);
// TODO: Add your code to draw the specified item
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rt;
rt = lpDrawItemStruct->rcItem;
Graphics grpx(dc);
Rect rect(0,0,90,90);//size of image
Image * Img = Image::FromFile(L"C:\\11.png",FALSE);//Downstate Image
Image * Img2 = Image::FromFile(L"C:\\10.png",FALSE);//Upstate Image
UINT state = lpDrawItemStruct->itemState; //Get state of the button
if ( (state & ODS_SELECTED) ) // If it is pressed
{
grpx.DrawImage(Img,rect);//Downstate Image
}
else
{
grpx.DrawImage(Img2,rect);//Upstate Image
}
dc.Detach();
}
BOOL MyButton::OnEraseBkgnd(CDC* pDC) //erase the BG so it's transparent and not grey
{
// Erase the BG of the CButton
return TRUE;
}
|