home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / MDITEST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  3.3 KB  |  137 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Demo                           }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program MDITest;
  9.  
  10. {$R MDITEST.RES}
  11.  
  12. uses WinTypes, WinProcs, Strings, OWindows, ODialogs;
  13.  
  14. const
  15.   cm_CountChildren = 102;
  16.   id_CantClose = 201;
  17.  
  18. type
  19.   TMDIApp = object(TApplication)
  20.     procedure InitMainWindow; virtual;
  21.   end;
  22.  
  23.   PMyMDIChild = ^TMyMDIChild;
  24.   TMyMDIChild = object(TWindow)
  25.     Num: Integer;
  26.     CanCloseCheckBox: PCheckBox;
  27.     constructor Init(AParent: PWindowsObject; ChildNum: Integer);
  28.     procedure SetupWindow; virtual;
  29.     function CanClose: Boolean; virtual;
  30.   end;
  31.  
  32.   PMyMDIWindow = ^TMyMDIWindow;
  33.   TMyMDIWindow = object(TMDIWindow)
  34.     procedure SetupWindow; virtual;
  35.     function CreateChild: PWindowsObject; virtual;
  36.     function GetChildCount: Integer;
  37.     procedure CMCountChildren(var Msg: TMessage);
  38.       virtual cm_First + cm_CountChildren;
  39.   end;
  40.  
  41. { TMyMDIChild's constructor instantiates a checkbox }
  42. constructor TMyMDIChild.Init(AParent: PWindowsObject; ChildNum: Integer);
  43. var
  44.   TitleStr: array[0..12] of Char;
  45.   ChildNumStr: array[0..5] of Char;
  46. begin
  47.   Str(ChildNum, ChildNumStr);
  48.   StrCat(StrECopy(TitleStr, 'Child #'), ChildNumStr);
  49.   inherited Init(AParent, TitleStr);
  50.   Num := ChildNum;
  51.   New(CanCloseCheckBox, Init(@Self, id_CantClose, 'Can Close', 10, 10,
  52.     200, 20, nil));
  53. end;
  54.  
  55. { Check the checkbox by default }
  56. procedure TMyMDIChild.SetupWindow;
  57. begin
  58.   inherited SetupWindow;
  59.   CanCloseCheckBox^.Check;
  60. end;
  61.  
  62. { CanClose is dependent upon the state of the checkbox }
  63. function TMyMDIChild.CanClose;
  64. begin
  65.   CanClose := CanCloseCheckBox^.GetCheck = bf_Checked;
  66. end;
  67.  
  68. { SetupWindow creates the first MDI child }
  69. procedure TMyMDIWindow.SetupWindow;
  70. var
  71.   ARect: TRect;
  72.   NewChild: PMyMDIChild;
  73. begin
  74.   inherited SetupWindow;
  75.   CreateChild;
  76. end;
  77.  
  78.  
  79. { Create a new MDI child }
  80. function TMyMDIWindow.CreateChild: PWindowsObject;
  81. var
  82.   ChildNum: Integer;
  83.  
  84.   function NumberUsed(P: PMyMDIChild): Boolean; far;
  85.   begin
  86.     NumberUsed := ChildNum = P^.Num;
  87.   end;
  88.  
  89. begin
  90.   ChildNum := 1;
  91.   while FirstThat(@NumberUsed) <> nil do Inc(ChildNum);
  92.   CreateChild := Application^.MakeWindow(New(PMyMDIChild,
  93.     Init(@Self, ChildNum)));
  94. end;
  95.  
  96. { Return a count of the MDI children }
  97. function TMyMDIWindow.GetChildCount: Integer;
  98. var
  99.   Count: Integer;
  100.  
  101.   procedure CountChild(AChild: PWindowsObject); far;
  102.   begin
  103.     Inc(Count);
  104.   end;
  105.  
  106. begin
  107.   Count := 0;
  108.   ForEach(@CountChild);
  109.   GetChildCount := Count;
  110. end;
  111.  
  112. { Display a message box which shows the number of children }
  113. procedure TMyMDIWindow.CMCountChildren(var Msg: TMessage);
  114. var
  115.   CountStr: array[0..5] of Char;
  116. begin
  117.   Str(GetChildCount, CountStr);
  118.   MessageBox(HWindow, CountStr, 'Total Children', mb_Ok);
  119. end;
  120.  
  121. { Construct a main window object }
  122. procedure TMDIApp.InitMainWindow;
  123. begin
  124.   MainWindow := New(PMyMDIWindow,
  125.     Init('MDI Conformist', LoadMenu(HInstance, MakeIntResource(100))));
  126.   HAccTable := LoadAccelerators(HInstance, MakeIntResource(100));
  127. end;
  128.  
  129. var
  130.   MDIApp: TMDIApp;
  131.  
  132. begin
  133.   MDIApp.Init('MDITest');
  134.   MDIApp.Run;
  135.   MDIApp.Done;
  136. end.
  137.