|
-
April 24th, 2005, 09:26 PM
#1
Screen flicker problem? InvalidateRect()
I have some problem with screen flicker, I copy one image from hard disk to view, and draw one circle on the screen, when I move the circle using direction arrow of keyboard, there is flicker problem because redrawing the whole screen. So I called the function InvalidateRect() to redraw specific rectangular, but it seems no action. the following is my code, can you please give some suggestion?
Thanks in advance!
void MyView::OnDraw(CDC* pDC)
{
CString szFilename("c:\\image.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
dc.SelectObject(pOldbmp);
DrawCircle(pDC);
}
void MyView: rawCircle(CDC *pDC)
{
CPen *penold, pennew;
pennew.CreatePen(PS_DOT,1,RGB(255,255,255));
penold=pDC->SelectObject(&pennew);
CBrush *pBrhold, Brhnew;
Brhnew.CreateStockObject(NULL_BRUSH);
pBrhold=pDC->SelectObject(&Brhnew);
m_tracker.AdjustRect(false,&m_tracker.m_rect);
m_tracker.m_rect.bottom=m_tracker.m_rect.top+m_tracker.m_rect.right -m_tracker.m_rect.left;
m_tracker.AdjustRect(true,&m_tracker.m_rect);
pDC->Ellipse(m_tracker.m_rect);
pDC->SelectObject(penold);
pDC->SelectObject(pBrhold);
pennew.DeleteObject();
}
void MyDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CRect rcClient;
p_view->GetClientRect(&rcClient);
rcClient.top=rcClient.top/2;
if(nChar==VK_LEFT)
{
p_view->m_tracker.m_rect.left-=1;
p_view->m_tracker.m_rect.right-=1;
InvalidateRect(rcClient);
//Invalidate();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|