I have drawn a line using CClientDC in OnPaint() event..
If I draw another line, the first line goes off...
Can anybody give me solution for the above?
Printable View
I have drawn a line using CClientDC in OnPaint() event..
If I draw another line, the first line goes off...
Can anybody give me solution for the above?
Where are you drawing the 2nd line? Do you have a code-example?
Thanks for your reply.....
To draw a line, i am getting my first point in OnLButtonDown...
When i move the mouse, I am drawing line from first point to the point where i move my mouse....
But it is drawing wherever i move.. If I give Invalidate() function, it flickers.. How to solve the problem?
When you draw a line it's rendered to the Device Context (DC).
When you invalidate it the entire contents are erased so your OnPaint function must repaint everything again including any lines you have previously drawn.
I think u r selecting the co-ordinate when user press left mouse button and when user moves pointer, u r drawing & erasing line. You need not frequently call the Invalidate(), ( You may call InvalidateRect()).
Supposing we have two CPoint object to denote the begin and end of line.
CPoint begin,end;
When user press left button, we initialize both (begin and end) with current value of co-oridantes.
And, whenver user move mouse, we write the code in OnMouseMove() to
1. Set the drawing mode R2_NOT using CDC::SetROP2.
2. Draw the line with previous co-ordinate to erase the previous line
3. Store the new co-ordinate in the end variable.
4. Draw the line.
And user release the mouse, we call InvalidateRect(). Rect area will determined by begin and end variables. and In OnDraw()/OnPaint() , we draw the line after setting the drawing mode R2_COPYPEN.
In OnPaint(), don't use CClientDC, use instead CPaintDC to draw.
I have written the below code in my project. (i am drawing this line in an image).
It is getting flickered.
---------------------------------------------------------------------------------------------
void MyClass::OnLButtonDown(UINT nFlags, CPoint point)
{
m_LMouseButton = TRUE;
point1 = point;
}
void MyClass::OnMoveDown(UINT nFlags, CPoint point)
{
if( m_LMouseButton == TRUE)
{
CClientDC dc(this)
dc.SetROP2(R2_NOT);
dc.MoveTo(point1);
dc.LineTo(point);
CRect rect(point1,point);
InvalidateRect(rect);
}
}
void MyClass::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_LMouseButton == TRUE)
{
m_LMouseButton=FALSE;
}
}
You need to use double bufferring
http://www.codeguru.com/Cpp/misc/mis...ticle.php/c389
Hello,
For whatever you wanted to see displayed after invalidation, you should include it in OnPaint function. You are doing the draw in a function OnMoveDown, is it not so? Is that function being called from OnPaint? Where the end points of lines are stored? I feel that you have to store the line information as an array in document or view class and draw the lines accordingly in OnPaint. Whenever a new line is created using mouse events, that line information should be appended to the array.
The tutorial example Scribble coming with VC++ explains the step-by-step method of creating an application on this line.
Best luck.
Pravin.
21-07-2005.