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

📄 enumenhmetau.pas

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

interface

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

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    Panel1: TPanel;
    Image1: TImage;
    Label1: TLabel;
    procedure FileListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  {the callback function for enumerating enhanced metafile records}
  function EnumerateEnhMetafile(DisplaySurface: HDC;
                              var MetafileTable: THandleTable;
                              var MetafileRecord: TEnhMetaRecord;
                              ObjectCount: Integer;
                              var Data: Longint): Integer; stdcall;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FileListBox1Click(Sender: TObject);
var
  TheMetafile: HENHMETAFILE;    // holds an enhanced metafile
begin
   {open and retrieve a handle to the selected metafile}
   TheMetafile:=GetEnhMetaFile(PChar(FileListBox1.FileName));

   {erase the last image}
   Image1.Canvas.FillRect(Image1.Canvas.ClipRect);

   {enumerate the records in the metafile}
   EnumEnhMetaFile(Image1.Canvas.Handle, TheMetafile, @EnumerateEnhMetafile,
                   nil, Image1.BoundsRect);
end;

{this function will fire for every record stored in the metafile}
function EnumerateEnhMetafile(DisplaySurface: HDC;
                              var MetafileTable: THandleTable;
                              var MetafileRecord: TEnhMetaRecord;
                              ObjectCount: Integer;
                              var Data: Longint): Integer;
var
  NewBrush: HBRUSH;       // holds a new brush
  BrushInfo: TLogBrush;   // defines a new brush
begin
  {if the metafile is trying to create a brush...}
  if MetafileRecord.iType=EMR_CREATEBRUSHINDIRECT then
  begin
    {...intercept it and create our own brush}
    BrushInfo.lbStyle := BS_SOLID;
    BrushInfo.lbColor := clRed;
    BrushInfo.lbHatch := 0;
    NewBrush := CreateBrushIndirect(BrushInfo);

    {select this brush into the device context where the
     metafile is being played. this will replace all brushes
     in the metafile with a red, solid brush}
    SelectObject(DisplaySurface,NewBrush);
  end
  else
    {if it's not a create brush record, play it}
    PlayEnhMetaFileRecord(DisplaySurface, MetafileTable, MetafileRecord,
                          ObjectCount);

  Result:=1;  // continue enumeration
end;

end.

⌨️ 快捷键说明

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