跪求高手 基于vc++的画直线程序设计编写一画直线的程序 要求可以设置线的宽度如1像素、5像素等; 要求可以
展开全部
void CPICDlg::DrawLine(CDC* pDC/*绘图DC*/,CPoint pStart/*起点*/,CPoint pEnd/*终点*/,int LineWidth/*线宽*/)
{
CPen thePen1;
thePen1.CreatePen(PS_SOLID,LineWidth,RGB( 0, 0, 0) );//黑色
CPen *lOldPen=NULL;
pDC->SetROP2( R2_COPYPEN );
lOldPen = pDC ->SelectObject(&thePen1);
// ***************开始画图*****************
pDC->MoveTo(pStart);
pDC->LineTo(pEnd);
pDC->SelectObject(lOldPen); // 恢复原先的画笔
thePen1.DeleteObject();
}
{
CPen thePen1;
thePen1.CreatePen(PS_SOLID,LineWidth,RGB( 0, 0, 0) );//黑色
CPen *lOldPen=NULL;
pDC->SetROP2( R2_COPYPEN );
lOldPen = pDC ->SelectObject(&thePen1);
// ***************开始画图*****************
pDC->MoveTo(pStart);
pDC->LineTo(pEnd);
pDC->SelectObject(lOldPen); // 恢复原先的画笔
thePen1.DeleteObject();
}
展开全部
使用moveto()和lineto()函数。
CClientDC ClientDC(this);
pen[0].CreatePen(PS_SOLID,1,RGB(0,0,0));
Brush[0].CreateSolidBrush(RGB(254,234,234));
LOGFONT logFont[2];
logFont[0].lfHeight=24;
logFont[0].lfWidth=0;
logFont[0].lfEscapement=0;
logFont[0].lfOrientation=0;
logFont[0].lfWeight=FW_NORMAL;
logFont[0].lfItalic=0;
logFont[0].lfUnderline=0;
logFont[0].lfStrikeOut=0;
logFont[0].lfCharSet=ANSI_CHARSET;
logFont[0].lfOutPrecision=OUT_DEFAULT_PRECIS;
logFont[0].lfClipPrecision=CLIP_DEFAULT_PRECIS;
logFont[0].lfQuality=PROOF_QUALITY;
logFont[0].lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
strcpy(logFont[0].lfFaceName,"Times New Roman");
UINT position=20;
logFont[1].lfHeight=16;
logFont[1].lfWidth=6;
logFont[1].lfEscapement=0;
logFont[1].lfOrientation=0;
logFont[1].lfWeight=FW_NORMAL;
logFont[1].lfItalic=0;
logFont[1].lfUnderline=0;
logFont[1].lfStrikeOut=0;
logFont[1].lfCharSet=ANSI_CHARSET;
logFont[1].lfClipPrecision=CLIP_DEFAULT_PRECIS;
logFont[1].lfQuality=PROOF_QUALITY;
logFont[1].lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
strcpy(logFont[0].lfFaceName,"Times New Roman");
CFont font[2];
font[0].CreateFontIndirect(&logFont[0]);
font[1].CreateFontIndirect(&logFont[1]);
CFont *oldFont=ClientDC.SelectObject(&font[0]);
ClientDC.SelectObject(&pen[0]);
ClientDC.SelectObject(&Brush[0]);
ClientDC.SelectObject(&font[0]);
ClientDC.MoveTo(45,140);
ClientDC.LineTo(905,140);
CClientDC ClientDC(this);
pen[0].CreatePen(PS_SOLID,1,RGB(0,0,0));
Brush[0].CreateSolidBrush(RGB(254,234,234));
LOGFONT logFont[2];
logFont[0].lfHeight=24;
logFont[0].lfWidth=0;
logFont[0].lfEscapement=0;
logFont[0].lfOrientation=0;
logFont[0].lfWeight=FW_NORMAL;
logFont[0].lfItalic=0;
logFont[0].lfUnderline=0;
logFont[0].lfStrikeOut=0;
logFont[0].lfCharSet=ANSI_CHARSET;
logFont[0].lfOutPrecision=OUT_DEFAULT_PRECIS;
logFont[0].lfClipPrecision=CLIP_DEFAULT_PRECIS;
logFont[0].lfQuality=PROOF_QUALITY;
logFont[0].lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
strcpy(logFont[0].lfFaceName,"Times New Roman");
UINT position=20;
logFont[1].lfHeight=16;
logFont[1].lfWidth=6;
logFont[1].lfEscapement=0;
logFont[1].lfOrientation=0;
logFont[1].lfWeight=FW_NORMAL;
logFont[1].lfItalic=0;
logFont[1].lfUnderline=0;
logFont[1].lfStrikeOut=0;
logFont[1].lfCharSet=ANSI_CHARSET;
logFont[1].lfClipPrecision=CLIP_DEFAULT_PRECIS;
logFont[1].lfQuality=PROOF_QUALITY;
logFont[1].lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
strcpy(logFont[0].lfFaceName,"Times New Roman");
CFont font[2];
font[0].CreateFontIndirect(&logFont[0]);
font[1].CreateFontIndirect(&logFont[1]);
CFont *oldFont=ClientDC.SelectObject(&font[0]);
ClientDC.SelectObject(&pen[0]);
ClientDC.SelectObject(&Brush[0]);
ClientDC.SelectObject(&font[0]);
ClientDC.MoveTo(45,140);
ClientDC.LineTo(905,140);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询