home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 7.ddi / OWLDEMOS.ZIP / MDITEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.5 KB  |  109 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <owl.h>
  6. #include <mdi.h>
  7. #include <checkbox.h>
  8. #include "mditest.h"
  9.  
  10. class TTestApp : public TApplication
  11. {
  12. public:
  13.   TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  14.     LPSTR lpCmdLine, int nCmdShow)
  15.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  16.   virtual void InitMainWindow();
  17. };
  18.  
  19. class TMyMDIChild : public TWindow
  20. {
  21. public:
  22.   TCheckBox *CloseBox;
  23.   TMyMDIChild(PTWindowsObject AParent, int ChildNum);
  24.   virtual BOOL CanClose();
  25. };
  26.  
  27. class TMyMDIFrame : public TMDIFrame
  28. {
  29. public:
  30.   TMyMDIFrame(LPSTR ATitle) : TMDIFrame(ATitle, "COMMANDS") {};
  31.   void SetupWindow();
  32.   virtual PTWindowsObject CreateChild();
  33.   int GetChildCount();
  34.   virtual void CMCountChildren(RTMessage Msg)
  35.     = [CM_FIRST + CM_COUNTCHILDREN];
  36. };
  37.  
  38. // TMyMDIChild's constructor instantiates a checkbox
  39. TMyMDIChild::TMyMDIChild(PTWindowsObject AParent, int ChildNum)
  40.   : TWindow(AParent, "")
  41. {
  42.   char TitleStr[12];
  43.  
  44.   sprintf(TitleStr, "%s%i", "Child #", ChildNum);
  45.   Title = _fstrdup(TitleStr);
  46.   CloseBox =
  47.     new TCheckBox(this, ID_CLOSEBOX, "Cannot Close", 10, 10, 200, 20, NULL);
  48. }
  49.  
  50. //  CanClose is dependent upon the state of the checkbox
  51. BOOL TMyMDIChild::CanClose()
  52. {
  53.   BOOL BoxChecked;
  54.  
  55.   BoxChecked = ( CloseBox->GetCheck() == BF_CHECKED );
  56.   return !BoxChecked;
  57. }
  58.  
  59. // set up the TMDIFrame, creating its first child
  60. void TMyMDIFrame::SetupWindow()
  61. {
  62.   TMDIFrame::SetupWindow();
  63.   CreateChild();
  64. }
  65.  
  66. //  create a new MDI child
  67. PTWindowsObject TMyMDIFrame::CreateChild()
  68. {
  69.   return GetApplication()->MakeWindow(
  70.     new TMyMDIChild(this, GetChildCount()+1));
  71. }
  72.  
  73. void CountChild(void *, void *CountPtr)
  74. {
  75.  ++*(int *)CountPtr;    
  76. }
  77.  
  78. //  return a count of the MDI children
  79. int TMyMDIFrame::GetChildCount()
  80. {
  81.   int Count = 0;
  82.  
  83.   ForEach(CountChild, &Count);
  84.   return Count;
  85. }
  86.  
  87. //  display a message box which shows the number of children
  88. void TMyMDIFrame::CMCountChildren(RTMessage)
  89. {
  90.   char CountStr[5];
  91.  
  92.   sprintf(CountStr, "%i", GetChildCount());
  93.   MessageBox(HWindow, (LPSTR)CountStr, "Total Children", MB_OK);
  94. }
  95.  
  96. void TTestApp::InitMainWindow()
  97. {
  98.   MainWindow = new TMyMDIFrame(Name);
  99. }
  100.  
  101. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  102.   LPSTR lpCmdLine, int nCmdShow)
  103. {
  104.   TTestApp TestApp("MDI Conformist", hInstance, hPrevInstance,
  105.     lpCmdLine, nCmdShow);
  106.   TestApp.Run();
  107.   return TestApp.Status;
  108. }
  109.