// 画直线
void DrawLine(CDC* pDC, CPoint* ptFrom, CPoint* ptTo, COLORREF crLine, BYTE byAlpha/* = 255*/, float width/* = 1.0f*/)
{
if (1)
{
// GDI方式
CPen pen(PS_SOLID, width, crLine);
HGDIOBJ pOldPen = (HGDIOBJ)::SelectObject(pDC->GetSafeHdc(), (HGDIOBJ)pen.GetSafeHandle());
::MoveToEx(pDC->GetSafeHdc(), ptFrom->x, ptFrom->y, NULL);
::LineTo(pDC->GetSafeHdc(), ptTo->x, ptTo->y);
::SelectObject(pDC->GetSafeHdc(), pOldPen);
}
else
{
// GDI+方式
Graphics g(pDC->GetSafeHdc());
Gdiplus::Pen pen(Color(byAlpha, GetRValue(crLine), GetGValue(crLine), GetBValue(crLine)), width);
g.DrawLine(&pen, ptFrom->x, ptFrom->y, ptTo->x, ptTo->y);
}
}