MFC的根据鼠标点的位置进行画图 5
voidCMyDlg::OnLButtonDown(UINTnFlags,CPointpoint){//TODO:Addyourmessagehandlercodeher...
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参数填什么
谢谢大神~ 展开
{
// 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参数填什么
谢谢大神~ 展开
1个回答
2016-07-21
展开全部
你把cpaintdc 改成 clientdc看一下。。还有就是cpen.CreatePen(PS_SOLID,1,RGB(0,0,0)); 1换成3看看,加粗点。CPaintDC只能用于 wm_paint消息之中~~
记得release dc
记得release dc
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询