Click here to Skip to main content
15,868,016 members

Trouble with area fixing using ValidateRect()

Revision 10
Hello everyone

I'm trying to resolve the problem with image blinking and I almost get it ,but I got some problems.

I want to redraw all the rest of the window except only the image. I'm trying to throw the Image's rectangle(i.e.coordinates) into ValidateRect and perform rendering but somehow it doesn't work

If I just overriding OnEraseBkgnd(CDC* pDC) {return false;}
It gives me a workable code,without any flickering(especially it looks great with high-definition images like 1680x1050) . But with small pictures where all the rest window is free when I begin resize it, it lefts remains(thats why I need to redraw it)
I've tried a lot of different ways and can't make it work
All the code is in OnDraw(CDC* pDC/*pDC*/) function
1)
if(oldpathName!=pathName){
	memDC.DeleteDC();
	memDC.CreateCompatibleDC(pDC);
	cImg.Destroy();
	if(cImg.Load((LPCTSTR)pathName)!=S_OK)
		AfxMessageBox(L"Error");
	memDC.SelectObject(cImg);
	pDC->BitBlt(0, 0, cImg.GetWidth(), cImg.GetHeight(), &memDC, 0, 0, SRCCOPY);
	oldpathName=pathName;erase=true;}
	else{
		CRect s(0,0,tmpImg->width,tmpImg->height);
		////InvalidateRect(s,FALSE);
		//RedrawWindow(s,NULL,RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
		ValidateRect(&s);
		pDC->BitBlt(0, 0, cImg.GetWidth(), cImg.GetHeight(), &memDC, 0, 0, SRCCOPY);
		//RedrawWindow(s,NULL,RDW_VALIDATE | RDW_UPDATENOW | RDW_ERASENOW);


If I run the program,the area where the image hangs (I validated it) begins blinking when I resize the borders.With small images I almost see nothing , but when I do it with the large ones some blinks occurs. It means that the function didn't fix the image

Maybe I should carry my code from OnDraw() into OnPaint(),than (maybe) OnPaint()'d call ->WM_PAINT->and then OnEraseBkgnd() would redraw the window or smth like that? It may look stupidly but I dont see any way now.Where is the mistake???

Please gimme a clue what I should change

After many efforts I at last got What I need
To resolve my problem I dragged all drawing operations from OnDraw() to OnPaint()
But somehow I noticed on GPU widget that my video accelerator(i.e. videocard) sustains some load when I begin load\reload some amount of images. If I operate with resizing on MsPaint all look fine. I assume maybe I somewhere have some unnecessary overheads.
Now my code looks that way:
void CMicrofilmOfficeView::OnPaint()
{
if(tmpImg){
	CClientDC aDC(this);
    CDC* pDC =&aDC;
	if(oldpathName!=pathName){
	memDC.DeleteDC();
	memDC.CreateCompatibleDC(pDC);
	cImg.Destroy();
	if(cImg.Load((LPCTSTR)pathName)!=S_OK)
		AfxMessageBox(L"Error");
	memDC.SelectObject(cImg);
	pDC->BitBlt(0, 0, cImg.GetWidth(), cImg.GetHeight(), &memDC, 0, 0, SRCCOPY);
	oldpathName=pathName;}
	else{
		pDC->BitBlt(0, 0, cImg.GetWidth(), cImg.GetHeight(), &memDC, 0, 0, SRCCOPY);
		ValidateRect(&CRect(0,0,tmpImg->width,tmpImg->height));
	}
}


Please gimme plz an advice how to maximum optimize my code /
Posted 8-Oct-12 12:33pm by JOHN 602.
Tags: ,