我已经开始编写组件,我想编写一个程序来为我生成 DCR 文件。一个组件的图片必须是24x24的位图,所以我需要创建一个资源文件,然后brcc32
用来创建DCR。
脚步:
- 创建 24x24 位图(油漆,旧但金色)
- 创建 RC 文件
- 使用 brcc32 创建 DCR
所以,我想编写一个程序来为我制作所有这些东西,这就是表格。在编辑字段中,我写了他们的Name
属性。
这是代码:
unit uBmp2rc;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.IOUtils,
Vcl.ExtDlgs, Vcl.ExtCtrls, ShellApi;
type
TBitmapConverter = class(TForm)
Label1: TLabel;
edtClassName: TEdit;
Label2: TLabel;
edtSource: TEdit;
Label3: TLabel;
Label4: TLabel;
edtDirectory: TEdit;
OpenPicture: TOpenPictureDialog;
Label5: TLabel;
edtBitmap: TEdit;
Button1: TButton;
Button2: TButton;
Label6: TLabel;
Preview: TImage;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
path: string;
public
{ Public declarations }
end;
var
BitmapConverter: TBitmapConverter;
implementation
{$R *.dfm}
procedure TBitmapConverter.Button1Click(Sender: TObject);
begin
if OpenPicture.Execute then
begin
edtBitmap.Text := OpenPicture.FileName;
Preview.Picture.LoadFromFile(OpenPicture.FileName);
end;
end;
procedure TBitmapConverter.Button2Click(Sender: TObject);
var sw: TStreamWriter;
tmpName, source, command: string;
begin
path := edtDirectory.Text;
source := edtSource.Text;
tmpName := TPath.Combine(path, source+'.rc');
Preview.Picture.SaveToFile(TPath.Combine(path, source + '.bmp'));
sw := TStreamWriter.Create(tmpName, False, TEncoding.UTF8);
try
sw.Write(edtClassName.Text + ' BITMAP "' + source + '.bmp"');
finally
sw.Free;
end;
command := '/C brcc32 -fo"' + TPath.Combine(path, source) + '.dcr" "' + TPath.Combine(path, source) + '.rc"';
ShellExecute(0, nil, PChar('cmd.exe'), PChar(command), nil, SW_HIDE);
end;
procedure TBitmapConverter.FormCreate(Sender: TObject);
begin
edtDirectory.Text := TPath.GetDocumentsPath;
end;
我可以正确创建 RC 文件,但没有创建 DCR。我在命令中做错了吗?
我PChar()
在谷歌搜索后添加了这个,我在 StackOverflow 上找到了提示,但我仍然不确定。