drawing a rectangle in CDC - Programmer

This is a discussion on drawing a rectangle in CDC - Programmer ; What is the best method of drawing a rectangle which is unfilled in the centre, but the actual lines (border?) are say 5 pixels wide ? I could set the Pen to 5 width and then use Polyline, but if ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: drawing a rectangle in CDC

  1. drawing a rectangle in CDC

    What is the best method of drawing a rectangle which is unfilled in
    the centre, but the actual lines (border?) are say 5 pixels wide ?

    I could set the Pen to 5 width and then use Polyline, but if I set the
    points like:

    0,0
    100,0
    100,100
    0,100
    0,0

    I dont get my 5 pixel width because the width is centred on the
    co-ordinates and aren't drawn inwards which is what I want.

    Thanks.

  2. Re: drawing a rectangle in CDC

    HPEN hpen = CreatePen(PS_INSIDEFRAME, 5, RGB(255,0,0));
    HPEN oldpen = reinterpret_cast(SelectObject(dc, hpen));
    HBRUSH oldbrush = reinterpret_cast(SelectObject(dc, GetStockObject(NULL_BRUSH)));

    Rectangle(dc, 5, 5, 105, 105);

    SetPixel(dc, 5, 5, RGB(0,0,255));
    SetPixel(dc, 5, 105, RGB(0,0,255));
    SetPixel(dc, 105, 5, RGB(0,0,255));
    SetPixel(dc, 105, 105, RGB(0,0,255));

    SelectObject(dc, oldbrush);
    DeleteObject(SelectObject(dc, oldpen));

    ---- Takeshi SHIGIHARA
    cygnus@po.jah.ne.jp
    cygnus@tka.att.ne.jp ------------

+ Reply to Thread