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

📄 ucreatepenindirect.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit UCreatePenIndirect;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  Pen: TLogPen;       // the logical pen record
  PenHandle: HPen;    // the handle of a pen
begin
  {erase any previous image}
  Canvas.Brush.Color := clBtnFace;
  Canvas.FillRect(Rect(10, 10, 111, 111));

  {initialize the logical pen structure}
  with Pen do
  begin
    {determine the pen style}
    Case RadioGroup1.ItemIndex of
      0: lopnStyle := PS_SOLID;
      1: lopnStyle := PS_DASH;
      2: lopnStyle := PS_DOT;
      3: lopnStyle := PS_DASHDOT;
      4: lopnStyle := PS_DASHDOTDOT;
      5: lopnStyle := PS_NULL;
      6: lopnStyle := PS_INSIDEFRAME;
    end;

    {set the pen width and color}
    lopnWidth.X := 1;
    lopnColor   := clRed;
  end;

  {create the new pen}
  PenHandle := CreatePenIndirect(Pen);

  {draw a square with the new pen}
  Canvas.Pen.Handle := PenHandle;
  Canvas.MoveTo(10, 10);
  Canvas.LineTo(110, 10);
  Canvas.LineTo(110, 110);
  Canvas.LineTo(10, 110);
  Canvas.LineTo(10, 10);

  {delete the new pen}
  DeleteObject(PenHandle);
end;

end.

⌨️ 快捷键说明

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