procedure DrawYours(c: TCanvas; r: TRect);
const size = 5;
var
  x, y: integer;
begin
  x := (r.Right - r.Left) div size;
  y := (r.Bottom - r.Top) div size;
  c.Pen.Style := psSolid;  with c, r do
  begin
  MoveTo(left, top);
  LineTo(left, top + y);
  MoveTo(left, bottom);
  LineTo(left, Bottom - y);  MoveTo(left, top);
  LineTo(left + x, Top);
  MoveTo(right, top);
  LineTo(Right - x, top);  MoveTo(right, top);
  LineTo(Right, top + y);
  MoveTo(right, Bottom);
  LineTo(Right, Bottom - y);  MoveTo(Left, Bottom);
  LineTo(Left + x, bottom);
  moveto(Right, Bottom);
  LineTo(right - x, bottom);
  end;
end;demo: drawYours( formX.canvas, rect(20,20,200,200));
麻烦把这个转成 C++

解决方案 »

  1.   

    const size = 5;void DrawYours(c: CDC; r: Rect){  int x,y;
      x = (r.Right - r.Left) / size;
      y := (r.Bottom - r.Top) / size;
        c.SelectStockObject (BLACK_PEN);
      c.MoveTo(left, top);
      c.LineTo(left, top + y);
      c.MoveTo(left, bottom);
      c.LineTo(left, Bottom - y);  c.MoveTo(left, top);
      c.LineTo(left + x, Top);
      c.MoveTo(right, top);
      c.LineTo(Right - x, top);  c.MoveTo(right, top);
      c.LineTo(Right, top + y);
      c.MoveTo(right, Bottom);
      c.LineTo(Right, Bottom - y);  c.MoveTo(Left, Bottom);
      c.LineTo(Left + x, bottom);
      c.moveto(Right, Bottom);
      c.LineTo(right - x, bottom);
     
    }
      

  2.   

    #define size 5void draw(HDC c, RECT r)
    {
    int x = (r.right - r.left) / size;
    int y = (r.bottom - r.top) / size;

    //c.Pen.Style = psSolid;

    //HPEN CreatePen(
    // int fnPenStyle,    // pen style
    // int nWidth,        // pen width
    // COLORREF crColor   // pen color
    //);
    HGDIOBJ hNew = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
    HGDIOBJ hOld = SelectObject(c, hNew); MoveToEx(c, r.left, r.top, NULL);
    LineTo(c, r.left, r.top + y);
    MoveToEx(c, r.left, r.bottom, NULL);
    LineTo(c, r.left, r.bottom - y); MoveToEx(c, r.left, r.top, NULL);
    LineTo(c, r.left + x, r.top);
    MoveToEx(c, r.right, r.top, NULL);
    LineTo(c, r.right - x, r.top); MoveToEx(c, r.right, r.top, NULL);
    LineTo(c, r.right, r.top + y);
    MoveToEx(c, r.right, r.bottom, NULL);
    LineTo(c, r.right, r.bottom - y); MoveToEx(c, r.left, r.bottom, NULL);
    LineTo(c, r.left + x, r.bottom);
    MoveToEx(c, r.right, r.bottom, NULL);
    LineTo(c, r.right - x, r.bottom); SelectObject(c, hOld);
    DeleteObject(hNew);
    }