wmftoemfu.pas
来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 79 行
PAS
79 行
unit WMFtoEMFU;
{==============================================================================
This application demonstrates how to use Delphi's encapsulation of metafiles
to easily convert older Windows metafiles into the newer enhanced metafile
format. This same technique could easily be modified to do the conversion
in the opposite direction. Enjoy!
==============================================================================}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, FileCtrl, ComCtrls;
type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
DriveComboBox2: TDriveComboBox;
DirectoryListBox2: TDirectoryListBox;
BitBtn1: TBitBtn;
StatusBar1: TStatusBar;
ProgressBar1: TProgressBar;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Converted: Integer; // used to indicate conversion progress
iLoop: Integer; // general loop control
TempMeta: TMetafile; // a Delphi metafile object
begin
{create the temporary metafile}
TempMeta:=TMetaFile.Create;
{convert selected files}
Converted := 0;
for iLoop := 0 to FileListBox1.Items.Count-1 do
begin
{if this file is selected...}
if FileListBox1.Selected[iLoop] then
begin
{...load the WMF file...}
TempMeta.LoadFromFile(DirectoryListBox1.Directory+'\'+FileListBox1.Items[iLoop]);
{...convert it into an enhanced Windows metafile...}
TempMeta.Enhanced := TRUE;
{...and save the new enhanced metafile to disk}
TempMeta.SaveToFile(DirectoryListBox2.Directory+'\'+ChangeFileExt(FileListBox1.Items[iLoop],'.EMF'));
{display our progress}
Inc(Converted);
ProgressBar1.Position := (Converted div FileListBox1.SelCount)*100;
end;
{clear the temporary metafile and update the progress bar}
TempMeta.Clear;
Application.ProcessMessages;
end;
{we are done, so free the temporary metafile and reset the progress bar}
ProgressBar1.Position := 0;
TempMeta.free;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?