//聲明:
CreatePenIndirect(
const LogPen: TLogPen {筆結構}
): HPEN; {返回筆句柄}
//TLogPen 是 tagLOGPEN 結構的重定義:
tagLOGPEN = packed record
lopnStyle: UINT; {筆樣式}
lopnWidth: TPoint; {筆寬; 只需要 TPoint.X}
lopnColor: COLORREF; {顏色}
end;
//lopnStyle 可選值:
PS_SOLID = 0; {實線}
PS_DASH = 1; {段線; 要求筆寬<=1}
PS_DOT = 2; {點線; 要求筆寬<=1}
PS_DASHDOT = 3; {線、點; 要求筆寬<=1}
PS_DASHDOTDOT = 4; {線、點、點; 要求筆寬<=1}
PS_NULL = 5; {不可見}
PS_INSIDEFRAME = 6; {實線; 但筆寬是向裡擴展}
//舉例:
procedure TForm1.FormPaint(Sender: TObject);
var
p: TLogPen;
PH1,PH2: HPEN;
begin
p.lopnStyle := PS_DOT;
p.lopnWidth.X := 0; {給筆寬賦值0, 會使用1像素筆寬}
p.lopnColor := clRed;
PH1 := CreatePenIndirect(p);
PH2 := SelectObject(Canvas.Handle, PH1);
Ellipse(Canvas.Handle, 20, 20, 96,132);
DeleteObject(PH1);
DeleteObject(PH2);
end;
//效果圖: