I have an app which i draw a PNG on the button and all works great until i want to redraw the whole screen.

when i try to redraw the whole screen it gives me an exception and points to this part of afxwin2.h

	{ ASSERT(::IsWindow(m_hWnd)); return CDC::FromHandle(::GetDC(m_hWnd)); }

here's my code:

void CODBIIMakerDatabaseDlg::DrawBackground(CDC *dc/*=0*/)
	Gdiplus::Image * BG;//GDI+ Background variable

		dc = GetDC();

	Gdiplus::Graphics grpx(*dc);//GDI Graphics container
	Gdiplus::Rect rect(0,0,473,261);//GDI image pos and size

	BG = Gdiplus::Image::FromFile(L"Image\\BackGround.png",FALSE);


It works great the first time DrawBackground is called but when i call DrawBackground with this


I get an exception when the if(!dc) is executed.

Am i Calling GetDC() wrong?

My guess is that you should not be calling that function directly. Call InvalidateRect() instead, and let it call the redraw function.

The thing is that i have done exactly that on other apps and it works great.

I don't know if i am missing something here,but it just won't work >_<.

I'm hitting a solid wall.

I don't know how to do that.

I will appreciate if you can show me an example?

I don't know how to do that.

I will appreciate if you can show me an example?

Just replace DrawBackground(0) with InvalidateRec(0); Since I can't see/test your code I can't guarentee that will work either, but it certainly won't crash the program.

2 Downloads and no reply >_<.

I guess this is harder than i thought.

If i invalidate my dialog using the ODS_SELECTED Message function in my button,the dialogs Background gets drawn on top of everything and my button image gets drawn but flickers if i leave it pressed.