⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extcreatepen2unit.pas

📁 Delphi Win32核心API参考光盘源码 本书包含了常用的Windows API函数
💻 PAS
字号:
unit extCreatePen2Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  NewPen, OldPen: HPen;   // holds the old and new pens
  FormDC: HDC;            // holds a handle to the form's device context
  BrushInfo: TLogBrush;   // the logical brush structure
  MiterLimit: Single;     // the mite limit
begin
  {get the form's device context}
  FormDC := GetDC(Form1.Handle);

  {define the brush}
  with BrushInfo do
  begin
    lbStyle := BS_SOLID;
    lbColor := clBlue;
    lbHatch := 0;
  end;

  {create a geometric pen with square end caps and mitered joins, 20 units wide}
  NewPen := ExtCreatePen(PS_GEOMETRIC or PS_ENDCAP_SQUARE or PS_JOIN_MITER, 20,
                         BrushInfo, 0, nil);

  {select the pen into the form's device context}
  OldPen := SelectObject(FormDC, NewPen);

  {begin a path bracket}
  BeginPath(FormDC);

  {define a closed triangle path}
  MoveToEx(FormDC, ClientWidth div 2, 20, nil);
  LineTo(FormDC, ClientWidth-20, 90);
  LineTo(FormDC, 20, 90);
  CloseFigure(FormDC);

  {end the path bracket}
  EndPath(FormDC);

  {insure that the miter limit is 2 units}
  GetMiterLimit(FormDC, MiterLimit);
  if MiterLimit>2 then
    SetMiterLimit(FormDC, 2, NIL);

  {draw the path with the geometric pen}
  StrokePath(FormDC);

  {delete the pen and the device context}
  SelectObject(FormDC, OldPen);
  ReleaseDC(Form1.Handle, FormDC);
  DeleteObject(NewPen);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -