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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <stdlib.h>
  4. #include <registry.hpp>
  5. #pragma hdrstop
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15.   AnsiString assw,assh;
  16.   int ww,hh;
  17.   TRegistry *rg;
  18.   rg=new TRegistry();
  19.   rg->RootKey=HKEY_LOCAL_MACHINE;
  20. //
  21.   if(rg->OpenKey("\Software\MyTest",False))
  22.   {
  23.     assw=rg->ReadString("FormWidth");
  24.     assh=rg->ReadString("FormHeight");
  25.     ww=atoi(assw.c_str());
  26.     hh=atoi(assh.c_str());
  27.     Width=ww;
  28.     Height=hh;
  29.   }
  30. //
  31.   rg->CloseKey();
  32.   rg->Free();
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::FormDestroy(TObject *Sender)
  36. {
  37.   TRegistry *rg;
  38.   rg=new TRegistry();
  39.   rg->RootKey=HKEY_LOCAL_MACHINE;
  40. //
  41.   rg->OpenKey("\Software\MyTest",True);
  42.   rg->WriteString("FormWidth",IntToStr(Width));
  43.   rg->WriteString("FormHeight",IntToStr(Height));
  44. //
  45.   rg->CloseKey();
  46.   rg->Free();
  47. }
  48. //---------------------------------------------------------------------------