none
Draw lines in various pen sizes in GDI RRS feed

  • Question

  • I need to draw lines using GDI functions in various pen sizes. For insatnce, below shows the bug I have. That is, line B is displayed correctly with pend size set to 100, and then line A is displayed incorrectly with pend size set to 50 (Yes, line A is displayed AFTER line B is displayed):

    And, below is the displaying result I expect:

    Here are the GDI functions I used to initialize my Canvas window and draw the lines:

    SetROP2(hDC, R2_NOTXORPEN);
    SetPolyFillMode(hDC, WINDING);
    
    penStyle = PS_GEOMETRIC | PS_INSIDEFRAME | PS_ENDCAP_FLAT;
    logicalBrush.lbStyle = BS_SOLID;
    logicalBrush.lbColor = 0x000000FF; // red
    
    // Draw "line B" with penSize = 100
    HGDIOBJ newPen = ExtCreatePen (penStyle, 100, &logicalBrush, 0, NULL); // dwWidth = 100
    HGDIOBJ oldPen = SelectObject (hDC, newPen);
    
    BeginPath (hDC);
    MoveToEx (hDC, ...);
    PolyDraw (hDC, ...);
    EndPath (hDC);
    
    StrokePath (hDC); // renders the line path using the current pen
    
    DeleteObject(newPen);
    
    // Draw "line A" with penSize = 50
    newPen = ExtCreatePen (penStyle, 50, &logicalBrush, 0, NULL); // dwWidth = 50
    SelectObject (hDC, newPen);
    
    BeginPath (hDC);
    MoveToEx (hDC, ...);
    PolyDraw (hDC, ...);
    EndPath (hDC);
    
    StrokePath (hDC);
    
    SelectObject (hDC, oldPen); // restore old pen
    

    Any helps will be highly appreciated.

    Many thanks indeed,

    CH

    Sunday, June 17, 2012 12:58 AM

Answers