home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / VWCIS / VWSAMPLE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-28  |  4KB  |  122 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Vision Workshop for Turbo Vision                }
  5. {       Demo program                                    }
  6. {                                                       }
  7. {       o  Shows how to use a menu bar stored in a      }
  8. {          resource file - see TVWSampleApp.InitMenuBar }
  9. {       o  Shows how to use a string table for the      }
  10. {          hints in the status line - see               }
  11. {          THintStatusLine.Hint                         }
  12. {       o  Shows how to use a standard dialog           }
  13. {          loaded from the resource file                }
  14. {          see TVWSampleApp.HandleEvent                 }
  15. {                                                       }
  16. {       Copyright (c) 1992, 93 by FE                    }
  17. {                                                       }
  18. {*******************************************************}
  19.  
  20. PROGRAM VWSample;
  21.  
  22. USES Objects, App, Drivers, Views, Menus, Dialogs;
  23.  
  24. VAR
  25.   RezFile: TResourceFile;
  26.   Strings: PStringList;
  27.  
  28. TYPE
  29.   TVWSampleApp = object(TApplication)
  30.     PROCEDURE HandleEvent(VAR Event: TEvent); VIRTUAL;
  31.     PROCEDURE InitMenuBar; VIRTUAL;
  32.     PROCEDURE InitStatusLine; VIRTUAL;
  33.   END;
  34.  
  35.   PHintStatusLine = ^THintStatusLine;
  36.   THintStatusLine = OBJECT(TStatusLine)
  37.     FUNCTION Hint(AHelpCtx: Word): STRING; VIRTUAL;
  38.   END;
  39.  
  40. PROCEDURE TVWSampleApp.HandleEvent(VAR Event: TEvent);
  41. VAR
  42.   R: TRect;
  43.   D: PDialog;
  44. BEGIN
  45.   INHERITED HandleEvent(Event);
  46.   IF Event.What = evCommand THEN BEGIN
  47.     { display dialog when user chooses "Open..." }
  48.     IF Event.Command = cmOpen THEN BEGIN
  49.       D := PDialog(RezFile.Get('Dialog'));
  50.         { load dialog from resource file }
  51.       ExecuteDialog(D, NIL);
  52.     END;
  53.   END;
  54. END;
  55.  
  56. PROCEDURE TVWSampleApp.InitMenuBar;
  57. BEGIN
  58.   MenuBar := PMenuBar(RezFile.Get('MainMenu'));
  59.     { load menu bar from resource file }
  60.   IF MenuBar = NIL THEN
  61.     Halt;
  62. END;
  63.  
  64. PROCEDURE TVWSampleApp.InitStatusLine;
  65. VAR
  66.   R: TRect;
  67. BEGIN
  68.   GetExtent(R);
  69.   R.A.Y := R.B.Y - 1;
  70.   StatusLine := New(PHintStatusLine, Init(R,
  71.     NewStatusDef(hcDragging, hcDragging,
  72.       NewStatusKey('~F1~ Help', kbF1, cmHelp,
  73.       NewStatusKey('~'#24#25#26#27'~ Move', kbNoKey, 0,
  74.       NewStatusKey('~Shift-'#24#25#26#27'~ Resize', kbNoKey, 0,
  75.       NewStatusKey('~'#17#196#217'~ Done', kbNoKey, 0,
  76.       NewStatusKey('~Esc~ Cancel', kbNoKey, 0, NIL))))),
  77.     NewStatusDef(0, 999,
  78.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  79.       NIL),
  80.     NIL))));
  81. END;
  82.  
  83. { Hint displays the strings stored in the string table retrieved
  84.   from the resource }
  85. FUNCTION THintStatusLine.Hint(AHelpCtx: Word): STRING;
  86. BEGIN
  87.   Hint := '';
  88.   IF Strings = NIL THEN
  89.     Exit;
  90.   Hint := Strings^.Get(AHelpCtx+10000);
  91.   { we used an offset to make index unique }
  92. END;
  93.  
  94. VAR
  95.   VWSampleApp: TVWSampleApp;
  96.  
  97. BEGIN
  98.   { register all views needed by this application }
  99.   RegisterMenus;
  100.   RegisterDialogs;
  101.   RegisterViews;
  102.   RegisterObjects;
  103.   RegisterType(RStringList);
  104.  
  105.   { open the resource file appended to .EXE file - $40 in the open mode
  106.     is required when the resource has been appended to the .EXE file
  107.     in protected mode since RTM keeps the .EXE file open after loading }
  108.  
  109.   { RezFile.Init(New(PDosStream, Init(ParamStr(0), stOpenRead OR $40))); }
  110.  
  111.   { open the resource file stored in a separate file}
  112.   RezFile.Init(New(PDosStream, Init('VWSAMPLE.REZ', stOpenRead)));
  113.  
  114.   { load string table }
  115.   Strings := PStringList(RezFile.Get('Strings'));
  116.   VWSampleApp.Init;
  117.   VWSampleApp.Run;
  118.   VWSampleApp.Done;
  119.   IF Strings <> NIL THEN
  120.     Dispose(Strings, Done);
  121.   RezFile.Done;
  122. END.