void CNCaptureView::PrepareDC(CDCHandle dc)
{
	ATLASSERT(m_sizeAll.cx >= 0 && m_sizeAll.cy >= 0);
	dc.SetMapMode(MM_ANISOTROPIC);
	dc.SetWindowExt(m_sizeLogAll);
	dc.SetViewportExt(m_sizeAll);
	dc.SetViewportOrg(-m_ptOffset.x, -m_ptOffset.y);

	if (m_pImage)
	{
		CRect rcPaintAll(CPoint(0), m_sizeAll);	//device unit
		if (m_sizeClient.cx > m_sizeAll.cx)
		{
			rcPaintAll.right = m_sizeClient.cx;
		}
		if (m_sizeClient.cy > m_sizeAll.cy)
		{
			rcPaintAll.bottom = m_sizeClient.cy;
		}

		dc.DPtoLP((LPPOINT)(&rcPaintAll), 2);  //change to logical
		CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
		m_rcDrawTarget = _GetPhotoRect(rcPaintAll, &(rcImage.Size()));
	}

	dc.SetWindowOrg(-m_rcDrawTarget.left, -m_rcDrawTarget.top);
}
void CNCaptureView::DoPaint(CDCHandle dc)
{
	FUNCTION_BLOCK_TRACE(20);
	if ( m_bIsDrawing )
	{
		return;
	}

	m_bIsDrawing = TRUE;
	BOOL bRet = FALSE;

	CRect rcClientLogical;
	GetClientRect(rcClientLogical);
	dc.DPtoLP(rcClientLogical);

	rcClientLogical.InflateRect(4, 4);	//fix scroll brush display error

	//CRect rcClient;
	//GetClientRect(&rcClient);
	//CWindowDC WndDc(m_hWnd);
	//WndDc.FillRect(&rcClient, m_brBackground);

	{
		//make sure MemDC bitblt

		//CMemoryDC memDC(dc.m_hDC, rcClient);
		CZoomScrollMemDC memDC (dc.m_hDC, rcClientLogical);
		PrepareDC(memDC.m_hDC);
		memDC.SetBrushOrg( -m_ptOffset.x , -m_ptOffset.y);

		//API_VERIFY(memDC.FillRect(&rcClip, m_brBackground));
		//API_VERIFY(memDC.FillRect(&rcClientLogical, m_brBackground));
		memDC.FillSolidRect(&rcClientLogical, NCAPTUREVIEW_BACKGROUND_CLR);
		if (m_pImage)
		{
			CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
			if (m_canvasImage.IsCanvasChanged(rcImage) || m_bImageChanged)
			{
				m_canvasImage.Release();
				API_VERIFY(m_canvasImage.Create(m_hWnd, rcImage.Width(), rcImage.Height()));

				m_bImageChanged = FALSE;
				//API_VERIFY(m_pImage->Draw(m_canvasImage, rcImage));
			}
			API_VERIFY(m_pImage->Draw(m_canvasImage, rcImage));
			DrawObjects(m_canvasImage.GetMemoryDC());
			{
				//When Capture image size multiply by zoom bigger than 32767, GDI CAN NOT display the image
				memDC.SetStretchBltMode(HALFTONE); //HALFTONE);

				bRet = memDC.BitBlt(
					0, 0, //rcClientLogical.left, rcClientLogical.top
					rcImage.Width(), rcImage.Height(),// rcClientLogical.Width(), rcClientLogical.Height(),
					m_canvasImage.GetMemoryDC(), 
					0, 0, //rcClientLogical.left, rcClientLogical.top, 
					SRCCOPY);
				if(!bRet)
				{
					FTLTRACE(TEXT("%s StretchBlt Failed, LastError=%d\n"), __FILE__LINE__, ::GetLastError());
				}
			}
			DrawTextObject(memDC.m_hDC);
			{
				CFMMTextDCGuard mmTextDCGuard(memDC);

				if (!m_pImage && m_pDefaultImage)
				{
					//no image ,just draw default image
					CRect rcClientDevice;
					GetClientRect(&rcClientDevice);
					CSize szDefaultImage(m_pDefaultImage->GetWidth(), m_pDefaultImage->GetHeight());
					CRect rcDefaultImageTarget = m_pCalcRect->GetPhotoRect(rcClientDevice, &szDefaultImage, 1.0f, FALSE, FALSE);
					NDGraphics::DrawGdiplusImage(memDC, m_pDefaultImage, rcDefaultImageTarget.left, rcDefaultImageTarget.top,
						rcDefaultImageTarget.Width(), rcDefaultImageTarget.Height());
				}
				DrawObjectsTracker(memDC.m_hDC);
			}
		}
	}


	//FTLTRACE(TEXT("DoPaint, m_rcDrawTarget=[%d,%d]x[%d,%d]\n"), m_rcDrawTarget.left, m_rcDrawTarget.top,
	//	m_rcDrawTarget.right, m_rcDrawTarget.bottom);
	//CClientDC clientDC(m_hWnd);

	m_bIsDrawing = FALSE;
}