为了在背景上画上固定网格,我重载了我的类的ERASEBKGND,但原来VIEW中的Ondraw中的绘画代码在发生滚动后就不起作用了。
BOOL CInnerView::OnEraseBkgnd(CDC*   pDC)     
{   
int i,j;
CRect rect ;
    this->GetClientRect (&rect);
this->GetWindowRect (&rect);
this->ScreenToClient (&rect);
TRACE("rect left %d, top %d\n", rect.left , rect.top );
CPoint point(rect.left,rect.top);
this->ViewDPtoLP (&point);
int iWidth = rect.Width ();
rect.left = point.x;
rect.right = point.x + iWidth;
// TRACE("ONERASEBACKx:%d y:%d\n",point.x ,point.y);
CWindowDC dc(this);
CWindowDC * pDC1 = &dc;
OnPrepareDC(&dc);
CSize bar;
this->GetScrollBarSizes (bar);
rect.bottom -= (bar.cy + 1);
pDC1->FillSolidRect (&rect,RGB(255,255,255));
TRACE("ONERASEBACKx:%d y:%d\n",rect.left ,rect.top);
        //画背景网格
for (i = 0; i< XGRIDNUM; i++)
{
pDC1->MoveTo (rect.left + i *this->iGridWidth ,rect.top );
pDC1->LineTo (rect.left + i *this->iGridWidth ,rect.bottom );
}
for (j = 0; j < YGRIDNUM; j++)
{
pDC1->MoveTo (rect.left , rect.top +j * this->iGridHeight ); 
pDC1->LineTo (rect.right, rect.top +j * this->iGridHeight ); 
}
static kk = 0;
TRACE("ONERASEBACK%d\n",kk);
kk++;
BOOL rst = true;
rst = CZoomView::OnEraseBkgnd (pDC);
return rst;
}
下面是我绘图代码,很简单,就是画了一组连续线段
void CInnerView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
TRACE("in draw \n");    for (int k = 0; k < this->dstArray .GetCount ()-1; k++)
{
MemDC.MoveTo (this->dstArray  .GetAt (k));
MemDC.LineTo (this->dstArray  .GetAt (k + 1));
}
}
我的CInnerView是一个继承于CZoomView(一个放缩类其基类是CScrollView)的类,在没有重载OnEraseBkgnd绘图代码正常在滚动后也正常。而重载后发生滚动后显示就有问题(好象背景把ONDROW的内容挡住了,但我用trace跟踪又发现ondraw确实在OnEraseBkgnd之后被调用过的),请高手指教,问题很急,多谢了
如有高手能提供可以绘制不随滚动条滚动的固定背景网格线的绘制思路就太感激了,感觉我现在的思路太笨了,(在背景探险事件中每次得到当前窗口区的位置再转换成逻辑坐标绘出)