allow user move drawn lines by mouse click and move events visual studio C++

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
my code allow user draw lines then he can do any modifications on it such as: change line properties ,delete line ,change its length and move it
I did code most of them but I could not do the moving part I wrote these lines for it but when I run the code the lines get disappear:
the part related to move shapes:
<pre class="prettyprint" style=" vector<Line*> mylines; // vector of all lines

#include "stdafx.h"
#include "Lines.h"
#include <windows.h>
#include "patron1View.h"

Line::Line()
{
color=RGB(0,0,0);
}

void Line::setPoints(POINT s,POINT e){
start=s;
end=e;

}//setpoints

POINT Line::getspoints(){
return start;
}

POINT Line::getepoints(){
return end;
}

void Line::setColor(int c){
switch(c){
case 1:
color=RGB(255,0,0);//red
break;
case 2:
color=RGB(0,0,255);//blue
break;
case 3:
color=RGB(20,255,0);//green
break;
default: color=RGB(0,0,0);//black
break;
}//switch
}

void Line::setStyle(int c){

style=c;

}



void Line::drawline(CDC* pDC){

pDC->SetMapMode(MM_LOMETRIC);
if(style==1){
mypen.CreatePen(PS_DOT,1,color);
}else if(style==2){
mypen.CreatePen(PS_DASH,1,color);
}else if(style==3){
mypen.CreatePen(PS_DASHDOT,1,color);
}else {
mypen.CreatePen(PS_SOLID,1,color);
}

pDC->SelectObject(&mypen);
pDC->MoveTo ( start.x, start.y) ;
pDC->LineTo (end.x,end.y ) ;
}




//the below code written within view.cpp class
/////////////////////////

CScrollView::OnLButtonDown(nFlags, point){


CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); // set up mapping mode and viewport origin
dc.DPtoLP(&point);



if(sel){
relativest.x=mylines.at(selind)->getspoints().x-point.x;
relativest.y=mylines.at(selind)->getspoints().y-point.y;
relativend.x=mylines.at(selind)->getepoints().x-point.x;
relativend.y=mylines.at(selind)->getepoints().y-point.y;
}


CScrollView::OnLButtonDown(nFlags, point);
}


void Cpatron1View::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); // set up mapping mode and viewport origin
dc.DPtoLP(&point);
Cpatron1Doc* doc = GetDocument();

//do move shape
if(((nFlags& MK_LBUTTON)== MK_LBUTTON)&&sel){
relativest.x= point.x + relativest.x;
relativest.y= point.x + relativest.y;
relativend.x= point.x + relativend.x;
relativend.y= point.x +relativend.y;
}

CScrollView::OnMouseMove(nFlags, point);
}


void Cpatron1View::OnLButtonUp(UINT nFlags, CPoint point)
{


CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); // set up mapping mode and viewport origin
dc.DPtoLP(&point);


if(sel){
relativest.x= point.x + relativest.x;
relativest.y= point.x + relativest.y;
relativend.x= point.x + relativend.x;
relativend.y= point.x +relativend.y;
mylines.at(selind)->setPoints(relativest,relativend);
}

CScrollView::OnLButtonUp(nFlags, point);
}


[/code]
could you please help me in doing this
thanks
<br/>

View the full article
 
Back
Top