两个参数的问题?

void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
  CClientDC dc(this);
 CPen pen(m_nType,m_nLineWidth,RGB(255,0,0));
 CPen * pOldPen=dc.SelectObject(&pen);
 CBrush* pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
 CBrush* pOldBrush=dc.SelectObject(pBrush);
 switch(m_nDrawType)
 {
 case 1:
  dc.SetPixel(point,RGB(255,0,0));
  break;
 case 2:
  dc.MoveTo(m_ptOrigin);
  dc.LineTo(point);
  break;
 case 3:
  dc.Ellipse(CRect(m_ptOrigin,point));
  break;
 case 4:
  dc.Rectangle(CRect(m_ptOrigin,point));
  break;
 }
 dc.SelectObject(pOldBrush);
 dc.SelectObject(pOldPen);
 CView::OnLButtonUp(nFlags, point);
}

 

见上面程序段中的红色部分,很简单的两个参数m_nType指定要创建画笔的类型,m_nLineWidth指定要创建画笔的宽度,这两个参数均由外部传入。在m_nLineWidth赋值为1时,程序都能按照m_nType参数指定的类型进行绘图;但是当m_nLineWidth的赋值大于1时(即线宽大于1时),所绘制的图形均为实线类型,不管m_nType的值为多少。

 

解决:(参见MSDN)

  • PS_DASH   Creates a dashed pen. Valid only when the pen width is 1 or less, in device units.

  • PS_DOT   Creates a dotted pen. Valid only when the pen width is 1 or less, in device units.

  • PS_DASHDOT   Creates a pen with alternating dashes and dots. Valid only when the pen width is 1 or less, in device units.

  • PS_DASHDOTDOT   Creates a pen with alternating dashes and double dots. Valid only when the pen width is 1 or less, in device units

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值