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.

[IMG]http://i14.photobucket.com/albums/a325/AntiBNI/beforeclick.jpg[/IMG]

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.

[IMG]http://i14.photobucket.com/albums/a325/AntiBNI/Clicked.jpg[/IMG]

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.

[IMG]http://i14.photobucket.com/albums/a325/AntiBNI/AfterClick.jpg[/IMG]


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.

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;
}

Recommended Answers

All 5 Replies

I only have one image, twice the size of the button, with two states/pictures in the image, and css position it up for the up and down for the down.
Never learned to erase either {:(

I only have one image, twice the size of the button, with two states/pictures in the image, and css position it up for the up and down for the down.
Never learned to erase either {:(

I heard you can't erase but redraw,but i don't know how to redraw the whole window.

I heard you can't erase but redraw,but i don't know how to redraw the whole window.

this->Refresh(); ?

Bumping your thread every few hours won't make you very populair..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.