Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   Graphics::TBitmap *bmp;
  18.   TMemoryStream *sm;
  19.   bmp = new Graphics::TBitmap();
  20.   sm=new TMemoryStream();
  21.   sm->Clear();
  22.   sm->LoadFromFile("te.bmp");
  23.   bmp->LoadFromStream(sm);
  24.   Canvas->Draw(20,20,bmp);
  25.   delete bmp;
  26.   delete sm;
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::Button2Click(TObject *Sender)
  30. {
  31.   TFileStream *fm;
  32.   TMemoryStream *sm;
  33.   int sz;
  34.   if(OpenDialog1->Execute())
  35.   {
  36.     if(FileExists("FILE.TXT"))
  37.       fm=new TFileStream("FILE.TXT",fmOpenReadWrite);
  38.     else
  39.       fm=new TFileStream("FILE.TXT",fmCreate);
  40.     sm=new TMemoryStream();
  41.     sm->LoadFromFile(OpenDialog1->FileName);
  42.     sz=sm->Size;
  43.     sm->Position=0;
  44.     fm->Seek(0,soFromEnd);
  45.     fm->CopyFrom(sm,sz);
  46. //也可以用Write
  47. //    fm->Write(sm->Memory,sz);
  48.     delete fm;
  49.     delete sm;
  50.   }
  51. }
  52. //---------------------------------------------------------------------------