home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 12 / dunteman.asc < prev    next >
Text File  |  1990-11-15  |  4KB  |  145 lines

  1. _STRUCTURED PROGRAMMING COLUMN_
  2. by Jeff Duntemann
  3.  
  4. [LISTING ONE]
  5.  
  6. {--------------------------------------------------------}
  7. {                                                        }
  8. {                        JXDESK                          }
  9. {                                                        }
  10. {  Jeff's Experimental Desktop Manager for Turbo Vision  }
  11. {                                                        }
  12. {                               by Jeff Duntemann        }
  13. {                               For Turbo Pascal V6.0    }
  14. {                                                        }
  15. {--------------------------------------------------------}
  16.  
  17.  
  18. PROGRAM JDesk;
  19.  
  20. { These are all Turbo Vision units: }
  21. USES Objects, Drivers, Views, Menus, Dialogs, App;
  22.  
  23.  
  24. CONST
  25.   SysStatCmd = 102;
  26.   NullCmd    = 101;
  27.  
  28.  
  29. TYPE
  30.   PDesk = ^TDesk;
  31.   TDesk = OBJECT(TApplication)
  32.     PROCEDURE HandleEvent(VAR Event: TEvent); VIRTUAL;
  33.     PROCEDURE InitMenuBar; VIRTUAL;
  34.     PROCEDURE InitStatusLine; VIRTUAL;
  35.     PROCEDURE SystemStatistics;
  36.   END;
  37.  
  38.  
  39. VAR
  40.   Desk: TDesk;   { Allocate an instantiation of TDesk }
  41.  
  42. { TDesk method definitions: }
  43.  
  44.  
  45. PROCEDURE TDesk.HandleEvent(VAR Event: TEvent);
  46.  
  47.  
  48. BEGIN
  49.   TApplication.HandleEvent(Event);
  50.   IF Event.What = evCommand THEN  { If the event was a command }
  51.   BEGIN
  52.     CASE Event.Command of
  53.       { The system invokes a method in response to a command: }
  54.       SysStatCmd : SystemStatistics;
  55.     ELSE
  56.       Exit;  { Exit the event handler; i.e., do nothing }
  57.     END;
  58.     ClearEvent(Event);
  59.   END;
  60. END;
  61.  
  62.  
  63. PROCEDURE TDesk.SystemStatistics;
  64.  
  65.  
  66. VAR
  67.   R: TRect;
  68.   D: PDialog;
  69.   C: Word;
  70.  
  71.  
  72. BEGIN
  73.   { Create a new dialog: }
  74.   R.Assign(25, 5, 55, 14);
  75.   D := New(PDialog,Init(R,'System Stats'));
  76.  
  77.   { Create and insert controls into the dialog: }
  78.   R.Assign(9, 6, 21, 8);
  79.   D^.Insert(New(PButton,Init(R,'OK',cmCancel,bfNormal)));
  80.  
  81.   { Execute the modal dialog: }
  82.   C := DeskTop^.ExecView(D);
  83. END;
  84.  
  85.  
  86. PROCEDURE TDesk.InitMenuBar;
  87.  
  88.  
  89. VAR
  90.   R: TRect;
  91.  
  92.  
  93. BEGIN
  94.   GetExtent(R);
  95.   R.B.Y := R.A.Y+1;
  96.   MenuBar := New(PMenuBar,Init(R,NewMenu(
  97.     NewSubMenu('~p~',hcNoContext,NewMenu(
  98.       NewItem('~A~bout',          '',0,NullCmd,hcNoContext,
  99.       NewItem('How to ~R~egister','',0,NullCmd,hcNoContext,
  100.       nil))),
  101.     NewSubMenu('~S~ystem', hcNoContext, NewMenu(
  102.       NewItem('~S~tatistics',    '',0,SysStatCmd,hcNoContext,
  103.       NewItem('Set ~T~ime',      '',0,NullCmd,hcNoContext,
  104.       NewItem('Set ~D~ate',      '',0,NullCmd,hcNoContext,
  105.       NewItem('~R~un DOS app...','',0,NullCmd,hcNoContext,
  106.       NewLine(
  107.       NewItem('E~x~it','Alt-X',kbAltX,cmQuit,hcNoContext,
  108.       nil))))))),
  109.     NewSubMenu('Address ~B~ook',hcNoContext,NewMenu(
  110.       NewItem('~O~pen book',  '',0,NullCmd,hcNoContext,
  111.       NewItem('~C~reate book','',0,NullCmd,hcNoContext,
  112.       NewItem('~P~rint book', '',0,NullCmd,hcNoContext,
  113.       nil)))),
  114.     NewSubMenu('~T~erm',hcNoContext,NewMenu(
  115.       NewItem('Link to ~M~CI',       '',0,NullCmd,hcNoContext,
  116.       NewItem('Link to ~C~ompuServe','',0,NullCmd,hcNoContext,
  117.       NewItem('Link to ~B~ix',       '',0,NullCmd,hcNoContext,
  118.       NewItem('~T~erminal window',   '',0,NullCmd,hcNoContext,
  119.       nil))))),
  120.   nil)))))));
  121. END;
  122.  
  123.  
  124. PROCEDURE TDesk.InitStatusLine;
  125.  
  126. VAR
  127.   R: TRect;
  128.  
  129.  
  130. BEGIN
  131.   GetExtent(R);
  132.   R.A.Y := R.B.Y-1;
  133.   StatusLine := New(PStatusLine, Init(R,
  134.     NewStatusDef(0, $FFFF,
  135.       NewStatusKey('~Alt-X~ Exit',kbAltX,cmQuit,nil),nil)));
  136. END;
  137.  
  138.  
  139. BEGIN
  140.   Desk.Init;
  141.   Desk.Run;
  142.   Desk.Done;
  143. END.
  144.  
  145.