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

_AFXWIN_INLINE CDC* CWnd::GetDC()
	{ 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

	if(!dc)
		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);

	grpx.DrawImage(BG,rect);
}

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

DrawBackground(0);

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

Am i Calling GetDC() wrong?

Recommended Answers

All 7 Replies

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.

if i do it in the dialog, it flashes like mad between grey and the BG.

Here's my project so you can see whats going on with full detail.

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.

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.