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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "unit1.h"
  5. #include "Main.h"
  6. #include "About.h"
  7. //---------------------------------------------------------------------------
  8. #pragma resource "*.dfm"
  9. TMainForm *MainForm;
  10. //---------------------------------------------------------------------------
  11. __fastcall TMainForm::TMainForm(TComponent *Owner)
  12. : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TMainForm::CreateMDIChild(String Name)
  17. {
  18. TMDIChild *Child;
  19. //--- create a new MDI child window ----
  20. Child = new TMDIChild(Application);
  21. Child->Caption = Name;
  22. if (FileExists (Name))
  23. Child->Memo1->Lines->LoadFromFile(Name);
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TMainForm::FileNew1Execute(TObject *Sender)
  27. {
  28. CreateMDIChild("NONAME" + IntToStr(MDIChildCount + 1));
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TMainForm::FileOpen1Execute(TObject *Sender)
  32. {
  33. if (OpenDialog->Execute())
  34. CreateMDIChild(OpenDialog->FileName);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TMainForm::HelpAbout1Execute(TObject *Sender)
  38. {
  39. AboutBox->ShowModal();
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TMainForm::FileExit1Execute(TObject *Sender)
  43. {
  44. Close();
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TMainForm::Button1Click(TObject *Sender)
  48. {
  49.   TForm1 *wnd;
  50.   wnd = new TForm1(Application);
  51.   wnd->Caption="我的子窗口";
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TMainForm::Button2Click(TObject *Sender)
  55. {
  56.   for(int i = 0; i < MDIChildCount; i++)
  57.     ShowMessage(MDIChildren[i]->Caption);
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TMainForm::Button3Click(TObject *Sender)
  61. {
  62.   TForm1 *wnd;
  63.   for(int i = 0; i < MDIChildCount; i++)
  64.     MDIChildren[i]->Close();
  65.   wnd = new TForm1(Application);
  66.   wnd->Caption="我的子窗口";
  67. }
  68. //---------------------------------------------------------------------------