const
PenStyles: array[TPenStyle] of DWORD = (PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME);
procedure TForm1.Button1Click(Sender: TObject);
var
tb: tagLOGBRUSH;
lbr: tagLOGBRUSH;
NewH, OldH: HGDIOBJ;
procedure SetPS(b: TPenStyle; aColor: TColor; w: integer);
begin
tb.lbStyle := BS_SOLID;
tb.lbColor := aColor;
NewH := ExtCreatePen(PS_GEOMETRIC + PS_ENDCAP_SQUARE + PenStyles, w, tb, 0, nil);
OldH := SelectObject(Canvas.Handle, NewH);
end;
begin
SetPS(psDash, clRed, 10);
MoveToEx(Canvas.Handle, 0, 100, nil);
LineTo(Canvas.Handle, 300, 100);
SelectObject(Canvas.Handle, OldH);
DeleteObject(NewH);
end;