请高手指点
请高手指点
不太明白,比如我在鼠标事件中画个矩形如下:
void CDrowView::OnLButtonDown(UINT nFlags, CPoint point)
{
pDC = GetDC(); // CDC * pDC;在视图类中声明
CPen pen(PS_SOLID,m_wndToolBar.iPanWidth,RGB(0,0,255));
CPen *pPen = pDC->SelectObject(&pen);
pDC->Rectangle(CRect(5,55,50,85));
CView::OnLButtonDown(nFlags, point);
}
那怎样把pDC在onDraw中每次将这个内存DC拷贝到主屏上?onDraw函数中怎么写?
我这有点非MFC的代码,已经测试过了可以的,我就不重写成MFC中的类了了,你照着下面的代码改成MFC中的类就行了,或者直接用就行
定义两个变量:
HDC g_MemDC;
HBITMAP g_hBitmap;
在InitDialog中:
[CODE] HDC hdc = GetDC()->m_hDC;
CRect rcClient;
GetClientRect(&rcClient);
g_hBitmap = CreateCompatibleBitmap (hdc, rcClient.right, rcClient.bottom) ;
g_MemDC = CreateCompatibleDC (hdc) ;
SelectObject (g_MemDC, g_hBitmap) ;
PatBlt (g_MemDC, 0, 0, rcClient.right, rcClient.bottom, WHITENESS) ;[/CODE]
OnMouseMove函数中:
[CODE] pDC->LineTo(point.x, point.y);
pDC->MoveTo(point.x, point.y);
LineTo (g_MemDC, point.x, point.y) ;
MoveToEx (g_MemDC, point.x, point.y, NULL) ;[/CODE]
OnPaint方法中:
[CODE] CPaintDC dc(this);
CRect rcClient;
GetClientRect(&rcClient);
BitBlt (dc.m_hDC, 0, 0, rcClient.right, rcClient.bottom, g_MemDC, 0, 0, SRCCOPY) ;[/CODE]