-
October 16th, 2003, 09:49 PM
#1
Erasing lines
erm i have read through all the post about erasing line.. and this is what i did...
After i draw the line, a dialog appear and after OnOk,
i set SetROP2 to R2_NOP and draw the line in same position.. but the line is still there. I have tried a number of flags for the SetROP2 but it has no effect.
I even tried to create a CPen with same background color and draw the line, it doesn works either.
Anyone knows where do i go wrong?
0 error(s), 0 warning(s)
-
October 16th, 2003, 09:58 PM
#2
Have you invalidated the region or rect you want updated? Also, if you are creating an ActiveX control you should call FireViewChange( ) to update.
-
October 17th, 2003, 12:33 AM
#3
i have tried but the line is still seen. ;(
0 error(s), 0 warning(s)
-
October 17th, 2003, 12:42 AM
#4
Post your code may be helpful.
If it helps you, thanks for rating.
-
October 17th, 2003, 01:52 AM
#5
Hi,
I have done a similar thing using either:
SetROP2(R2_NOTXORPEN)
or
SetROP2(R2_XORPEN)
You should call this before you draw the line both times. You will also need to set the pen color first.
Does that work for you?
If not, please post your code as suggested.
thanks,
Em
Last edited by Emster; October 17th, 2003 at 02:17 AM.
-
October 17th, 2003, 08:31 AM
#6
Code:
void CtestView::OnMouseMove(UINT nFlags, CPoint point)
{
if (move)
{
CClientDC ClientDC (this);
ClientDC.SetROP2(R2_NOTXORPEN);
DrawLine(&ClientDC, start_point, point);
}
}
start_point stores the point on mousedown
Code:
void DrawLine(CDC *pDC, CPoint m_pOne, CPoint m_pTwo)
{
pDC->MoveTo(m_pOne);
pDC->LineTo(m_pTwo);
}
on mouseup, i call a dialog.DoModal()....
Code:
void CLineDialog::OnOK()
{
CDialog::OnOK();
CDC *pDC = GetDC();
pDC->SetROP2(R2_NOTXORPEN);
CPen Pen;
Pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
pDC->SelectObject(&Pen);
pDC->MoveTo(pt_x1, pt_y1);
pDC->LineTo(pt_x2, pt_y2);
}
pt_x1 ... etc is global variable which i store the point.x and point.y on both mousedown and mouseup....
where did i make mistake??
Thanks a lot..
0 error(s), 0 warning(s)
-
October 17th, 2003, 09:46 AM
#7
Well, you are drawing to the dialog's DC using GetDC() - that' can't possibly work...
-
October 17th, 2003, 10:40 AM
#8
!! how do i get the CView dc? or should i draw at OnDraw ;\
0 error(s), 0 warning(s)
-
October 17th, 2003, 10:54 AM
#9
Originally posted by ayumi
!! how do i get the CView dc? or should i draw at OnDraw ;\
Yes. Always and only in OnDraw().
-
October 17th, 2003, 07:38 PM
#10
but i have tried doing so in OnDraw and i do a Invalidate() after the CDialog::OnOK(); .. the line is still there ........
Anyone has any better ideas??
Thanks.
0 error(s), 0 warning(s)
-
October 17th, 2003, 07:44 PM
#11
Originally posted by ayumi
but i have tried doing so in OnDraw and i do a Invalidate() after the CDialog::OnOK(); .. the line is still there ........
You mean, you moved the entire code of drawing from OnOk to OnDraw and it still doesn't work ?
BTW, I like your signature...
0 errors, 0 warnings... so funny
-
October 17th, 2003, 07:47 PM
#12
There should be no need to redraw the line using R2_NOTXORPEN after the dialog is closed. Basically, you erase / draw the line in OnMouseMove(), giving a rubber banding effect while the mouse is moved. On MouseUp, you display the dialog. When the dialog is closed, you call Invalidate(). Now OnDraw() will be called, where you redraw your data - without the line.
-
October 17th, 2003, 11:11 PM
#13
i'm not sure why.. even if i don't redraw the lines, after onok, i do a Invalidate(); , the line is still seen -_- it didn erase my background, or how should i erase the background? ;\
0 error(s), 0 warning(s)
-
October 18th, 2003, 03:37 AM
#14
Normally, you don't need to do extra background erasing (but you can by implementing a WM_ERASEBKGND handler). There seems to be something else wrong with your code. Can you post the code for- your view's class definition from the .h file,
- your implementation of OnDraw(),
- the place where you call Invalidate()?
-
October 18th, 2003, 05:28 AM
#15
Code:
class CtestView : public CView
{
protected: // create from serialization only
DECLARE_DYNCREATE(CtestView)
// Attributes
public:
CtestView();
CtestDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CtestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate();
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CtestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CtestView)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
Code:
void CtestView::OnMouseMove(UINT nFlags, CPoint point)
{
if (move)
{
CClientDC ClientDC (this);
ClientDC.SetROP2(R2_NOTXORPEN);
DrawLine(&ClientDC, start_point, point);
}
CView::OnMouseMove(nFlags, point);
}
Code:
void DrawLine(CDC *pDC, CPoint m_pOne, CPoint m_pTwo)
{
pDC->MoveTo(m_pOne);
pDC->LineTo(m_pTwo);
}
Code:
void CtestView::OnLButtonUp(UINT nFlags, CPoint point)
{
CLineDialog dlg;
dlg.DoModal();
CView::OnLButtonUp(nFlags, point);
}
Code:
void CLineDialog::OnOK()
{
CDialog::OnOK();
EraseLine = true;
Invalidate();
}
Code:
void CtestView::OnDraw(CDC* pDC)
{
CtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(EraseLine)
{
CPen Pen;
Pen.CreatePen(PS_SOLID,1,RGB(0,0,100));
pDC->SelectObject(&Pen);
pDC->MoveTo(pt_x1, pt_y1);
pDC->LineTo(pt_x2, pt_y2);
EraseLine = false;
}
......
......
//Code to draw back image... too long to post.
0 error(s), 0 warning(s)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|