大家应该看过电子地图,在电子地图中,比如铁路,是一段黑,一段白组成的,请问想这样的线条如何绘制出来呢?
因为我们通常使用的 画笔对象(HPEN)不能达到这样的效果,ExtCreatePen也不行。
请问这样的线条应该如何绘制呢?非常感谢。

解决方案 »

  1.   

    自己在ResourceView中插入一个Bitmap,,ID为IDB_BRUSH,,然后自己画一段黑,一段白,,把下面的代码放到OnDraw中就行了,,
    // Resource handle to bitmap.
    HRSRC hRes;    
    // Global handles to bitmap resource.
    HGLOBAL hData;
    void* hLockedData;   
    CBrush brush;
    // Find the resource handle.
    hRes = ::FindResource(AfxGetResourceHandle(),
    MAKEINTRESOURCE(IDB_BRUSH), RT_BITMAP);
    if (hRes != NULL)
    {
    // Lock and Load (or Load and Lock).
    if (((hData = ::LoadResource(AfxGetResourceHandle(),
    hRes)) != NULL) && 
    ((hLockedData = ::LockResource(hData)) != NULL))
    {
    // Initialize the brush.
    brush.CreateDIBPatternBrush((const void*)hLockedData,
    DIB_RGB_COLORS);

    // Select the brush into the device context.
    CBrush* pOldBrush = pDC->SelectObject(&brush);

    // Draw.
    pDC->Rectangle(50, 50, 200, 200);

    // Restore the original device context.
    pDC->SelectObject(pOldBrush);

    // Free the resource.
    ::FreeResource(hLockedData);
    }
    }
      

  2.   

    再放一个效果图,,
    void CTestMuView::OnDraw(CDC* pDC)
    {
    CTestMuDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here CRect rect;
    GetClientRect(&rect);
    // Resource handle to bitmap.
    HRSRC hRes;    
    // Global handles to bitmap resource.
    HGLOBAL hData;
    void* hLockedData;   
    CBrush brush;
    // Find the resource handle.
    hRes = ::FindResource(AfxGetResourceHandle(),
    MAKEINTRESOURCE(IDB_BRUSH), RT_BITMAP);
    if (hRes != NULL)
    {
    // Lock and Load (or Load and Lock).
    if (((hData = ::LoadResource(AfxGetResourceHandle(),
    hRes)) != NULL) && 
    ((hLockedData = ::LockResource(hData)) != NULL))
    {
    // Initialize the brush.
    brush.CreateDIBPatternBrush((const void*)hLockedData,
    DIB_RGB_COLORS);

    // Select the brush into the device context.
    CBrush* pOldBrush = pDC->SelectObject(&brush);

    // Draw.
    pDC->Rectangle(rect.left, rect.Height()/2, rect.right, rect.Height()/2+5);

    // Restore the original device context.
    pDC->SelectObject(pOldBrush);

    // Free the resource.
    ::FreeResource(hLockedData);
    }
    }
    }这些代码是从MSDN上看来的
      

  3.   

    用LineDDA...函数实现,再回调函数中完成黑白,或特殊内容。