📄 enumobjunit.pas
字号:
unit EnumObjUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ListBox: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{the callback function prototype}
function EnumObjProc(ObjType: PLogPen; lData: lParam): Integer; stdcall;
var
Form1: TForm1;
implementation
{$R *.DFM}
function EnumObjProc(ObjType: PLogPen; lData: lParam): Integer;
var
LocalObjType: TLogPen; // holds logical pen information
PenDescription: String; // holds a pen description
begin
{get the pen information}
LocalObjType := ObjType^;
{determine the type of pen being enumerated}
case LocalObjType.lopnStyle of
PS_SOLID: PenDescription := 'PS_SOLID';
PS_DASH: PenDescription := 'PS_DASH';
PS_DOT: PenDescription := 'PS_DOT';
PS_DASHDOT: PenDescription := 'PS_DASHDOT';
PS_DASHDOTDOT: PenDescription := 'PS_DASHDOTDOT';
PS_NULL: PenDescription := 'PS_NULL';
PS_INSIDEFRAME: PenDescription := 'PS_INSIDEFRAME';
end;
{determine the color of the pen being enumerated}
case LocalObjType.lopnColor of
clBlack: PenDescription := PenDescription+' Color: clBlack';
clMaroon: PenDescription := PenDescription+' Color: clMaroon';
clGreen: PenDescription := PenDescription+' Color: clGreen';
clOlive: PenDescription := PenDescription+' Color: clOlive';
clNavy: PenDescription := PenDescription+' Color: clNavy';
clPurple: PenDescription := PenDescription+' Color: clPurple';
clTeal: PenDescription := PenDescription+' Color: clTeal';
clGray: PenDescription := PenDescription+' Color: clGray';
clSilver: PenDescription := PenDescription+' Color: clSilver';
clRed: PenDescription := PenDescription+' Color: clRed';
clLime: PenDescription := PenDescription+' Color: clLime';
clYellow: PenDescription := PenDescription+' Color: clYellow';
clBlue: PenDescription := PenDescription+' Color: clBlue';
clFuchsia: PenDescription := PenDescription+' Color: clFuchsia';
clAqua: PenDescription := PenDescription+' Color: clAqua';
clWhite: PenDescription := PenDescription+' Color: clWhite';
end;
{indicate the pen's width}
PenDescription:=PenDescription+' Width: '+IntToStr(LocalObjType.lopnWidth.X);
{add the description to the list box}
Form1.ListBox.Items.Add(PenDescription);
{indicate that enumeration should continue}
Result := 1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{enumerate all pens in the form's device context}
EnumObjects(Canvas.Handle, OBJ_PEN, @EnumObjProc, 0);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -