|
-
July 21st, 2005, 05:06 AM
#1
Drawing Line
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?
-
July 21st, 2005, 05:35 AM
#2
Re: Drawing Line
Where are you drawing the 2nd line? Do you have a code-example?
-
July 21st, 2005, 05:45 AM
#3
Re: Drawing Line
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?
-
July 21st, 2005, 05:57 AM
#4
Re: Drawing Line
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.
Requests such as
"I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.
-
July 21st, 2005, 06:18 AM
#5
Re: Drawing Line
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.
Life is what u make it and u can make it more simple..........and woderful.
Rate is what give and it give me pleasure.
-
July 21st, 2005, 06:32 AM
#6
Re: Drawing Line
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;
}
}
-
July 21st, 2005, 06:41 AM
#7
Re: Drawing Line
Requests such as
"I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.
-
July 21st, 2005, 06:42 AM
#8
Re: Drawing Line
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.
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
|