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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <registry.hpp>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::Button1Click(TObject *Sender)
  17. {
  18.   char buff[MAX_PATH];
  19. //获取Windows目录
  20.   GetWindowsDirectory(buff,MAX_PATH);
  21.   Edit1->Text=buff;
  22. //获取Windows的系统目录
  23.   GetSystemDirectory(buff,MAX_PATH);
  24.   Edit2->Text=buff;
  25. //获取Windows的临时目录
  26.   GetTempPath(MAX_PATH,buff);
  27.   Edit3->Text=buff;
  28. }
  29. //---------------------------------------------------------------------------
  30. void __fastcall TForm1::Button2Click(TObject *Sender)
  31. {
  32.   TRegistry *rg;
  33.   rg=new TRegistry();
  34.   rg->RootKey=HKEY_LOCAL_MACHINE;
  35.   rg->OpenKey("\Software\Microsoft\Windows\CurrentVersion",False);
  36.   Edit1->Text=rg->ReadString("ProgramFilesDir");
  37.   Edit2->Text=rg->ReadString("CommonFilesDir");
  38.   rg->CloseKey();
  39.   rg->Free();
  40. }
  41. //---------------------------------------------------------------------------