可以有2个方法解决问题
第一个:在画线的同时用数组记录下你画的线的起点和终点,在wm_size事件中重画就可以解决问题
第二个:在OnDraw或者OnPaint中执行你在OnLButtonDown中的语句

解决方案 »

  1.   

    void CMyView::OnDraw(CDC* pDC)
    {
      CMyDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);
      RECT Rect;
      Rect.left = Rect.top = 10;
      Rect.right = Rect.bottom = 100;
      CBrush Brush(RGB(255,0,0));
      pDC->FillRect(&Rect,&Brush);
    }多看看MSDN吧
      

  2.   

    当窗口被覆盖,然后再重新显现的时候framework会自动发出一条消息,调用OnDraw()对窗口重绘。你的画图是在OnLButtonDown中画的。而在OnDraw中并没有重绘,自然什么都没有!
      

  3.   

    定义成员变量
    private:
    CArray<CPoint,CPoint> m_pointArray;
    int x,y;
    bool flag;
    实现:
    void CDrawLineDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    //======================================================
    if( flag == 0 )
    {
    x = point.x;
    y = point.y;
    flag = true;
    } m_pointArray.Add( point );
    CClientDC dc(this);
    dc.MoveTo( x, y );
    dc.LineTo(point.x,point.y);
    x=point.x;
    y=point.y;
    //======================================================
    CDialog::OnLButtonDown(nFlags, point);
    }void CDrawLineDlg::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
    {
    CDialog::OnPaint();
    }
    //======================================================
    CClientDC dc(this);
    for( int i=0; i<m_pointArray.GetSize()-1; i++ )
    {
    dc.MoveTo(m_pointArray[i]);
    dc.LineTo(m_pointArray[i+1]);
    }
    //======================================================
    }
    BOOL CDrawLineDlg::OnInitDialog()
    {
    ...
    //======================================================
    flag = false;
    //======================================================...
    }