void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString text;
GetDlgItemText(IDC_SET_CITY, text);
if ("绘制城市" != text) return;
CWnd *pWnd = GetDlgItem(IDC_MAIN_PANEL);
CRect rect;
pWnd->GetClientRect(rect);
this->ClientToScreen(rect);
pWnd->GetClientRect(rect);
if (!rect.PtInRect(point)) return;
City city;
city.r = 50;
city.x = point.x;
city.y = point.y;
text.Format("%C", 65 + m_citys.GetSize());
city.name = text;
m_citys.Add(city);
if (m_pLastCity != NULL){
Edge e;
e.beginCity = m_pLastCity;
e.endCity = &m_citys[m_citys.GetSize()-1];
m_edges.Add(e);
}
m_pLastCity = &m_citys[m_citys.GetSize()-1];
CDialog::OnLButtonDown(nFlags, point);
}
这是我的左键点击的代码 意思应该是点左键生成一个城市,后面右键是也生成城市,但是对相邻的城市不连线。
我现在想解决的问题是
void CMyDlg::OnDrawCitys(CDC *pDC)
{
CClientDC dc(this);
dc.MoveTo();
dc.LineTo();
}
画城市时,不知道MoveTo和LineTo参数填什么
谢谢大神~
http://blog.chinaunix.net/uid-25799257-id-3832907.html
鼠标点下设置moveto,一直点着就是lineto
onLbuttondown函数会有一个point返回,在这个响应函数里面画图,第一point设置为moveto(),后面全用lineto()
要是直接lineto(npoint)可能第一个点默认在(0,0),第一条线会有问题,后面没问题
在鼠标的点击的时候,即onLButtondown时,记录起始点和结束点为同一点
m_StartPoint = point;
m_EndPoint = point;
在鼠标移动时,onMousemove消息的时候,point为鼠标消息回传的点
dc.MoveTo(m_StartPoint);
dc.LineTo(point);
m_StartPoint = point;
这样就可以画出铅笔的轨迹
在鼠标的点击的时候,即onLButtondown时,记录起始点和结束点为同一点
m_StartPoint = point;
m_EndPoint = point;
在鼠标移动时,onMousemove消息的时候,point为鼠标消息回传的点
dc.MoveTo(m_StartPoint);
dc.LineTo(point);
m_StartPoint = point;
这样就可以画出铅笔的轨迹
楼上总结的不错