SavePictureDialog (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This code displays a Save Picture dialog box with the TBitmap default extension that is added automatically to files that are given no extension. Confirm that the bitmap file has been saved under the file name and path specified.

Code

#include <memory>       //For STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  String NewFileName, OldFileName;
  SavePictureDialog1->DefaultExt = GraphicExtension(__classid(Graphics::TBitmap));
  SavePictureDialog1->Filter = GraphicFilter(__classid(Graphics::TBitmap));
  OldFileName = L"../factory.bmp";
  if (SavePictureDialog1->Execute())
  {
	NewFileName = SavePictureDialog1->FileName;
	std::auto_ptr<TFileStream> OldFile(new TFileStream(OldFileName, (fmOpenRead | fmShareDenyWrite)));
	std::auto_ptr<TFileStream> NewFile(new TFileStream(NewFileName, (fmCreate | fmShareDenyRead)));
	NewFile->CopyFrom(OldFile.get(), OldFile->Size);
  };
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  Image1->Picture->LoadFromFile(L"../factory.bmp");
}

Uses