any errors in my code anyone?? ;(
~~~
Printable View
any errors in my code anyone?? ;(
~~~
////
CPoint m_ptCur;//initialize it in OnLButtonDown(...)
// in your case : start_point = m_ptCur = point;
/////////////////
void CtestView::OnMouseMove(UINT nFlags, CPoint point)
{
if (move)
{
CClientDC ClientDC (this);
ClientDC.SetROP2(R2_NOT);
DrawLine(&ClientDC, start_point, m_ptCur);
DrawLine(&ClientDC,start_point,point);
m_ptCur = point;
}
CView::OnMouseMove(nFlags, point);
}
try
huh?? what does that do??
The code icewater posted correctly implements rubberbanding (it draws the line twice using R2_NOT, once to erase the old line, and once to draw the new one).Quote:
Originally posted by ayumi
huh?? what does that do??
The code you posted, in contrast, contains only one MoveTo/LineTo call in OnMouseMove. Furthermore, you still have a MoveTo/LineTo call in OnDraw. Why?
i have tried with and without moveto lineto in OnDraw.. its still the same...i can't remove the old line but after i minimise and maximise the window its gone.
i can't remove it from the background. if its on image, i redraw the image and its gone. but some part is still visible which is out of range of the image. ;(
Well, you are calling Invalidate() from CLineDialog::OnOK(). That will invalidate the dialog, not the view...
then after the user click on ok, where should i Invalidate()?
Either after DoModal() returns (which would be the better place anyway) or from inside the dialog (but then, you need to call it in OnCancel too, not only OnOK). However, the important thing is that you call your view's Invalidate(), not the dialog's.
how can i call the view Invalidate()?? after DoModal() returns i call a Invalidate() it would be the view's invalidate?
OK, let's get to the basics. CView and CDialog are both derived from CWnd, so they both inherit CWnd::Invalidate(). Likewise, your classes CtestView and CLineDialog inherit the same method. Your view is an instance of CtestView. Your dialog (dlg) is an instance of CLineDialog. So when you call Invalidate() from within a method of CtestView (like OnLButtonUp), your call will affect the view. If you call it from a method of CLineDialog (like OnOK), it will affect the dialog. In order to call the view's Invalidate() from the dialog, you will need a reference or pointer to the instance of your view (there are several ways to get that) and then call something pMyView->Invalidate(). And of course, when calling Invalidate() from OnLButtonUp() after DoModal() returns, you will invalidate the view: OnLButtonUp() is a method of your view. Note that this is very elementary C++ stuff, it has nothing to do with MFC or Windows.Quote:
Originally posted by ayumi
how can i call the view Invalidate()?? after DoModal() returns i call a Invalidate() it would be the view's invalidate?
Thanks a lot to all.. i have done my Invalidate() at mouseup and it works without having to redraw..
thanKs aLL!~