1.可以通过流来实现,把你要的内容通过流写在文件的后面,我就通过这种方法,把许多
东西放在图片里,图片可以正常使用。然后我可以通过我的程序读出放的东西。
2。这需要通过com调用word。server页的控件可以实现你要的功能。
下面的代码是第一个问题的例子。
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ExtDlgs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
btnGo: TBitBtn;
FilePath: TEdit;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure btnGoClick(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
BMPFile: string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
bmpFile := OpenPictureDialog1.FileName;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
FilePath.Text := OpenDialog1.FileName;
btnGo.Enabled := true;
end;
end;
procedure TForm1.btnGoClick(Sender: TObject);
var
FileSM: TFileStream;
MemSM: TMemoryStream;
Bmp: TBitmap;
buf: ^Integer;
Temp: integer;
begin
if FilePath.Text<>'' then
begin
New(Buf);
FileSM := TFileStream.Create(FilePath.Text,fmOpenRead);
MemSM := TMemoryStream.Create;
Bmp := TBitmap.Create;
try
bmp.Assign(Image1.Picture.Bitmap);
bmp.SaveToStream(MemSM);
MemSM.Seek(0,soFromEnd);
Temp := MemSM.Position;
Buf^ := MemSM.Size;
FileSM.Position := 0;
MemSM.CopyFrom(FileSM,FileSM.Size);
MemSM.Seek(0,soFromEnd);
MemSM.Write(Buf^,4);
MemSM.SaveToFile('c:/bak.bmp');
MessageDlg('Ok!', mtInformation, [mbOK], 0);
finally // wrap up
FileSM.Free;
MemSM.Free;
FreeMem(Buf);
end
// try/finally
end
else
MessageDlg('请选择文件!', mtWarning, [mbOK], 0);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
FM: TFileStream;
MM: TMemoryStream;
Addr: ^integer;
begin
if BMPFile<>'' then
begin
New(Addr);
FM := TFileStream.Create(BMPFile,fmOpenRead);
MM := TMemoryStream.Create;
try
FM.Seek(0,soFromEnd);
FM.Position := FM.Position-4;
FM.Read(Addr^,4);
Caption := IntToHex(Addr^,8);
FM.Seek(Addr^,soFromBeginning);
MM.Position := 0;
MM.CopyFrom(FM,FM.Size-Addr^-4);
MM.SaveToFile('c:/a.exe');
finally
FM.Free;
MM.Free;
FreeMem(Addr);
end;
end;
end;
end.