I have a little problem with updating on a dialog. If I make a Dialog with onpaint:

Code:
void CTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC  dc(this);

		CRect winpos = dc.m_ps.rcPaint;

		dc.FillSolidRect(winpos.left, winpos.top, 
			winpos.Width(), winpos.Height(), 0);

	}
}
and OnEraseBkgn:

Code:
BOOL CTestDlg::OnEraseBkgnd(CDC* pDC) 
{	return TRUE;	
}
and move a small window (i.e. notepad) fast over, then it sometimes it doesn't refresh the window correctly. Why ?

It works if I always update the entire screen instead of the rectangle that "needs" to be updated. But I don't want to do that. I mean, I get the rectangle exactly for the reason that I don't have to update everything. That would make my program much slower.

I appreciate any help on this...


PS: The code fragments I posted are not my real code. I just used them to show the problem. My real code is far to complex to post but the problem is the same. So please do not get hung up on the code I posted, except of course there is something important that I didn't notice...