📄 getobjectunit.pas
字号:
unit GetObjectUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit4: TEdit;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function GetStyle(Style: Integer): string;
begin
{display the brush style}
case Style of
BS_DIBPATTERN: Result := 'BS_DIBPATTERN';
BS_DIBPATTERN8X8: Result := 'BS_DIBPATTERN8X8';
BS_DIBPATTERNPT: Result := 'BS_DIBPATTERNPT';
BS_HATCHED: Result := 'BS_HATCHED';
BS_HOLLOW: Result := 'BS_HOLLOW';
BS_PATTERN: Result := 'BS_PATTERN';
BS_PATTERN8X8: Result := 'BS_PATTERN8X8';
BS_SOLID: Result := 'BS_SOLID';
end;
end;
function GetHatch(Hatch: Integer): string;
begin
{display the hatch style}
case Hatch of
HS_BDIAGONAL: Result := 'HS_BDIAGONAL';
HS_CROSS: Result := 'HS_CROSS';
HS_DIAGCROSS: Result := 'HS_DIAGCROSS';
HS_FDIAGONAL: Result := 'HS_FDIAGONAL';
HS_HORIZONTAL: Result := 'HS_HORIZONTAL';
HS_VERTICAL: Result := 'HS_VERTICAL';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hObject: HGDIOBJ; // holds the handle to a brush object
LogBrush: TLogBrush; // holds brush information
FormDC: HDC; // a handle to the form's device context
begin
{retrieve the form's device context}
FormDC := GetDC(Form1.Handle);
{initialize the form's brush, and then retrieve a handle to it}
Canvas.Brush.Color := clRed;
Canvas.Brush.Style := bsDiagCross;
hObject := GetCurrentObject(Canvas.Handle, OBJ_BRUSH);
{retrieve information about the object}
GetObject(hObject, SizeOf(TLogBrush), @LogBrush);
{indicate the type of object retrieved}
case GetObjectType(hObject) of
OBJ_BITMAP: Edit4.Text := 'Bitmap';
OBJ_BRUSH: Edit4.Text := 'Brush';
OBJ_FONT: Edit4.Text := 'Font';
OBJ_PAL: Edit4.Text := 'Palette';
OBJ_PEN: Edit4.Text := 'Pen';
OBJ_EXTPEN: Edit4.Text := 'Extended Pen';
OBJ_REGION: Edit4.Text := 'Region';
OBJ_DC: Edit4.Text := 'Device Context';
OBJ_MEMDC: Edit4.Text := 'Memory Device Context';
OBJ_METAFILE: Edit4.Text := 'Metafile';
OBJ_METADC: Edit4.Text := 'Metafile Device Context';
OBJ_ENHMETAFILE: Edit4.Text := 'Enhanced Metafile';
OBJ_ENHMETADC: Edit4.Text := 'Enhanced Metafile Device Context';
end;
{display the object's information}
with LogBrush do
begin
Edit1.Text := GetStyle(lbStyle);
Edit2.Text := IntToHex(lbColor, 8);
Edit3.Text := GetHatch(lbHatch);
end;
{select the brush into the form's device context}
SelectObject(FormDC, hObject);
{draw an ellipse with the brush}
Ellipse(FormDC, 50, 10, 150, 110);
{delete the device context}
ReleaseDC(Form1.Handle, FormDC);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -