home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MENDOW21.ZIP / MENDOWS.DOC < prev    next >
Encoding:
Text File  |  1986-11-14  |  17.6 KB  |  365 lines

  1. MENDOW21.INC (Window & Menuing Routines for TURBO PASCAL)
  2. Written By Amram Elye Dworkin
  3.            Lead PC Programmer
  4.            Potomac ADP.
  5.            (301) 984-5533 (voice)
  6.            10-01-86
  7.  
  8. The MENDOW21.INC Routines Allow A User To Easily Create WINDOWS & MENUS.
  9. Both The Windows & the Menus have a pleasing double line border around them.
  10. MENDOW21 also allows Windowed Data Entry Screen Generation, but that feature
  11. is not fully implemented as of this writing. Heres How You Use MENDOW21.INC:
  12.  
  13.          1) Include the MENDOW21.INC file in your system. IT SHOULD BE GLOBAL.
  14.          2) Place call for Procedure DetermineDisplay at beginning of your
  15.             code.
  16.  
  17.          e.g.   BEGIN
  18.                    DetermineDisplay;
  19.                    ;
  20.                    ;  your program goes here
  21.                    ;
  22.                 END.
  23. ==============================================================================
  24.          3) If you want MENUS:
  25.  
  26.             a) Define a variable in your program as type 'WindowPtr'
  27.  
  28.             e.g   VAR
  29.                      MyWindow : WindowPtr;
  30.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  31.              b) Define a variable in your program as type 'INTEGER'
  32.  
  33.              e.g. VAR
  34.                      MyMenuOption : INTEGER;
  35.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  36.             c) Define a variable in your program as type 'DrawRec'
  37.  
  38.             e.g.  VAR
  39.                      MyMenu : DrawRec;
  40.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  41.             d) Define the following fields in the menu variable:
  42.                   Count   = Number Of Menu Options                (2..50)
  43.                   Default = The Default Menu Options              (1..Count)
  44.                   Title   = Title Of Menu                      ( STRING[74] )
  45.                   DrawRecAr[1].Col = Top Left Column Of Menu      (1..77)
  46.                   DrawRecAr[1].Row = Top Left Row Of Menu         (1.22)
  47.                   DrawRecAr[2].Col = Bottom Right Column of Menu  (3..80)
  48.                   DrawRecAr[2].Row = Bottom Right Row Of Menu     (3..24)
  49.                   DrawRecAr[n].DrawDat = Each Item To Be Listed In The Menu
  50.                                          n = Item Number
  51.  
  52.             e.g.  MyMenu.Count                := 3;
  53.                   MyMenu.Default              := 1;
  54.                   MyMenu.Title                := 'My Favorite Menu';
  55.                   MyMenu.DrawRecAr[1].Col     := 3;
  56.                   MyMenu.DrawRecAr[1].Row     := 4;
  57.                   MyMenu.DrawRecAr[2].Col     := 50;
  58.                   MyMenu.DrawRecAr[2].Row     := 8;
  59.                   MyMenu.DrawRecAr[1].DrawDat := 'Option 1 To List';
  60.                   MyMenu.DrawRecAr[2].DrawDat := 'Option 2 To List';
  61.                   MyMenu.DrawRecAr[3].DrawDat := 'Option 3 To List';
  62.             OR
  63.                   WITH MyMenu DO
  64.                   BEGIN
  65.                      Count   := 3;
  66.                      Default := 1;
  67.                      Title   := 'My Favorite Menu';
  68.                      DrawRecAr[1].Col     := 3;
  69.                      DrawRecAr[1].Row     := 4;
  70.                      DrawRecAr[2].Col     := 50;
  71.                      DrawRecAr[2].Row     := 8;
  72.                      DrawRecAr[1].DrawDat := 'Option 1 To List';
  73.                      DrawRecAr[2].DrawDat := 'Option 2 To List';
  74.                      DrawRecAr[3].DrawDat := 'Option 3 To List';
  75.                   END;
  76.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  77.             e) To Call The Menu Up use the Function Make_Menu;
  78.                The Function Has 3 Paramaters.  They are:
  79.                      Menu Record          ( type DrawRec )
  80.                      Window Pointer       ( type WindowPtr )
  81.                      Clear menu Flag      ( type Boolean   )
  82.                  NOTE1: On Exit From Function Make_Menu the Integer Variable
  83.                         to the left of the := sign will contain the number of
  84.                         the option chosen.  The rest is UP TO YOU.
  85.                  NOTE2: The Clear Menu Flag determines whether the menu is
  86.                         cleared off the screen after an option is chosen
  87.                  NOTE3: The WindowPtr Variable Must be present but is only used
  88.                         if the Clear Menu Flag is set to FALSE.
  89.                  NOTE4: Since the addition of Moving Menus the Menu Record var
  90.                         may be changed on exit from Make_Menu the.  The Draw
  91.                         RecAr[1..2].Row & DrawRecAr[1..2].Col vars will be
  92.                         changed to the new menu positions if the menu has been
  93.                         moved.
  94.  
  95.             e.g   MyMenuOption := Make_Menu(MyMenu,MyWindow,TRUE);
  96.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  97.             f) If you chose FALSE for the Clear Menu Flag, you may delete the
  98.                window from within you program by the Procedure DRestoreWindow;
  99.                This procedure has 3 paramteres.  They are:
  100.                      Window Pointer          ( type WindowPtr )
  101.                      Top Column Offset       (Always use 0)
  102.                      Top Row Offset          (Always use 0)
  103.  
  104.             e.g. DRestoreWindow(MyWindow,0,0);
  105.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  106.                           COMPLETE MENU EXAMPLE
  107.                           ---------------------
  108.  
  109.          PROGRAM MenuDemo;
  110.  
  111. (*$IMENOWS.INC *)
  112.          VAR
  113.             MyMenu       : DrawRec;
  114.             MyWindow     : WindowPtr;
  115.             MyMenuOption : INTEGER;
  116.  
  117.          BEGIN
  118.             DetermineDisplay;
  119.             WITH MyMenu DO
  120.             BEGIN
  121.                Count                := 3;
  122.                Default              := 1;
  123.                Title                := MyFavoriteMenu;
  124.                DrawRecAr[1].Col     := 3;
  125.                DrawRecAr[1].Row     := 4;
  126.                DrawRecAr[2].Col     := 50;
  127.                DrawRecAr[2].Row     := 8;
  128.                DrawRecAr[1].DrawDat := 'Option 1 To List';
  129.                DrawRecAr[2].DrawDat := 'Option 2 To List';
  130.                DrawRecAr[2].DrawDat := 'Option 3 To List';
  131.             END; { WITH MyMenu }
  132.  
  133.             MyMenuOption := Make_Menu(MyMenu,MyWindow,TRUE);
  134.             CASE MyMenuOption OF
  135.                0 : WRITELN('<ESC> Pressed. No Option Chosen');
  136.                1 : WRITELN('Option 1 Chosen');
  137.                2 : WRITELN('Option 2 Chosen');
  138.                3 : WRITELN('Option 3 Chosen');
  139.                ELSE
  140.                    WRITELN('This Should Never Happen');
  141.             END; { CASE MyMenuOption }
  142.          END. { MenuDemo }
  143. ==============================================================================
  144.          3) If You Want Windows:
  145.  
  146.              a) Define a variable in you program as type 'BOOLEAN'
  147.  
  148.              e.g   MyErrCode : BOOLEAN;
  149.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  150.              b) Define a variable in your program as type 'WindowPtr'
  151.  
  152.              e.g.  MyWindow : WindowPtr;
  153.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  154.              c) Create a window by calling the Function Make_Window.  This
  155.                 function has 7 parameters.  They are:
  156.                      Top Column           (1..74)
  157.                      Top Row              (1..22)
  158.                      Bottom Column        (3..80)
  159.                      Bottom Row           (4..25)
  160.                      Window Title         ( STRING[74] )
  161.                      Window Pointer       ( type WindowPtr )
  162.                      Clear Window Flag    ( type Boolean   )
  163.  
  164.              NOTE1: The Title MUST present even if it is just ''.
  165.              NOTE2: The Clear Window Flag determines whether the screen INSIDE
  166.                     the window is to be cleared.
  167.              NOTE3: The BOOLEAN value returned will be TRUE if an error was
  168.                     encountered on creation of the window and FALSE if no
  169.                     error was found.
  170.  
  171.  
  172.              e.g.   MyErrCode := Make_Window(4,4,50,12,'My Test Window',
  173.                                              MyWindow,TRUE);
  174.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  175.              d) Once the window is in place you may use it just like it was
  176.                 a mini-screen.  GOTOXY()'s will work as if the top right
  177.                 corner of the window is (0,0). CLRSCR's will clear only the
  178.                 window, etc..
  179.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  180.              e) To delete the window from the screen you must use the Function
  181.                 DRestoreWindow.  This funciton has 3 parameters.  They are:
  182.                      Window Pointer          ( type WindowPtr )
  183.                      Top Column Offset       (Always use 0)
  184.                      Top Row Offset          (Always use 0)
  185.               NOTE1: If you use parameters other than '0' for the offsets the
  186.                      old screen will be restored onto a different part of the
  187.                      screen.  (Might be useful to you but I've never used that
  188.                      feature.)
  189.  
  190.               e.g. DRestoreWindow(MyWindow,0,0);
  191.          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  192.                                 COMPLETE WINDOW EXAMPLE
  193.                                 -----------------------
  194.  
  195.          PROGRAM WindowDemo;
  196.  
  197. (*$IMENDOW21.INC *)
  198.  
  199.          VAR
  200.             MyWindow  : WindowPtr;
  201.             MyErrCode : BOOLEAN;
  202.  
  203.          BEGIN
  204.             DetermineDisplay;
  205.             MyErrCode := Make_Window(10,8,55,12,'My Test Window',
  206.                                      MyWindow,TRUE);
  207.             GOTOXY(1,1);
  208.             WRITELN('This is the top of the WINDOW');
  209.             READLN;
  210.             CLRSCR; { This will clear only the WINDOW }
  211.             WRITELN('Hit <RETURN> To Exit Window');
  212.             READLN;
  213.             DRestoreWindow(MyWindow,0,0);
  214.          END. { WindowDemo }
  215.  
  216.  
  217. ==============================================================================
  218.  
  219. NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES NOTES
  220.  
  221. 1) When using the Make_Menu Option the Up & Down cursor control Arrow keys
  222.    will move the highlighted bar up and down the options.  The bar will wrap
  223.    around (from last option to first option & vice versa).  To select an
  224.    menu option simply press the <RETURN> key when the bar is on the high-
  225.    lighted option.  To exit menu without choosing an option press the <ESC>
  226.    key.
  227.  
  228. 2) When in the Make_Menu Option, the system will automatically check the first
  229.    character of your options.  If they are non repeating then simply pressing
  230.    that character is the same as moving the highlighted bar to that option and
  231.    pressing <RETURN>.  If the characters are repeated then you must use the
  232.    space bar.
  233.       e.g.         Read A Record    } since none of these options starts with
  234.                    Write A Record   } the same letter you could simply type
  235.                    Clear A Record   } 'R','W', or 'C' for desired action.
  236.  
  237.                    Read A Record    } Since 'Concat' & 'Clear' both start with
  238.                    Concat A Record  } 'C' you would have to use the cursor to
  239.                    Clear A Record   } move highlight bar to desired action.
  240.  
  241. 3) You can, if you wish, put more than one window up on the screen at once
  242.    simply by calling the Make_Window function multiple times in you program.
  243.    If you do this you must use the RestoreWindow (rather than the DRestore.
  244.    Window) procedure to restore all but the first window you opened.  The
  245.    first window must be restored using the DRestoreWindow procedure.  This is
  246.    because the Make_Window & Make_Menu functions use the heap to save the old
  247.    screens and the DRestoreWindow procedure frees up the space that was being
  248.    used.  This means if you don't clear your windows in the order you created
  249.    them AND you use DRestoreWindow rather that RestoreWindow you will screw
  250.    things up in a big way.  However, if you do not use the DRestoreWindow
  251.    procedure to clear the first window you called, the heap will never be
  252.    cleared and a lot of good memory will be wasted.
  253.  
  254. 4) Along the same lines as Note 3 is the observation that if you put variables
  255.    on the heap then use the DRestoreWindow procedure your variables will be
  256.    lost as the heap pointer is restored to its position before the creation of
  257.    the window.  WATCH OUT FOR THIS AS IT IS A BITCH TO FIND WHILE DEBUGGING !
  258.  
  259. 5) The MENDOW21.INC File has some other relatively interesting functions and
  260.    procedures that might be worth looking at if you have the time and energy.
  261.    I find, however, that I do not usually need anything except the Make_Menu
  262.    & Make_Window fuctions to make my life complete (Oh. And A Bad Woman, of
  263.    course.)
  264.  
  265. 6) Much as I would like to say I wrote all of these routines myself the truth
  266.    is that I based them on a set of rather mundane (but brilliant) primitives
  267.    that someone (who shall remain nameless until he/she calls me at
  268.    (301)984-5533) wrote & put out onto the the BBS's.  To him/her I tip my
  269.    hat and say between the two of us we make beautiful music.
  270.  
  271. 7) These routines & my descriptions look like they are a bitch but in reality
  272.    this stuff is beyond simple to use.  LOOK AT THE EXAMPLES AT THE END OF
  273.    EACH MAJOR SECTION for an idea on their ease of use.
  274.  
  275. 8) I would like to hear from you on how to improve these routines.  If you
  276.    have a good idea (or if you improve them yourself) drop me a note, or the
  277.    updated programs on the COLOSSUS II Bulletin board (301)428-9044. Leave
  278.    the message to AMI DWORKIN or call me on my voice line (301)984-5533 from
  279.    9:30-5:00 M-F. (The Name is Pronounced Ah-Mee not Ay-Mee. Yes I am male.)
  280.  
  281. NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW
  282.  
  283. 1) The Menu Positions must now be defined in the MenuRec variable (they were
  284.    explicitly stated in the Make_Menu Call in version 1.0).  This change is
  285.    to allow for the new MOVABLE MENUs feature.
  286.  
  287. 2) The MOVABLE MENUs feature allows you to move a menu around the screen in
  288.    order to see what was underneath.  To do so a new set of keys have been
  289.    added to the accepted menu keys.  The 'Up Arrow, Down Arrow, ESC, &
  290.    Carriage Return' set have been expanded to allow the use of the 'INSERT'
  291.    key.  The insert key puts the user in the MOVE MENU mode.
  292.  
  293. 3) When in the MOVE MENUs mode there are 16 keys available to the user.  These
  294.    are:
  295.              Up Arrow    : Moves the menu up a row
  296.              Down Arrow  : Moves the menu down a row
  297.              Left Arrow  : Moves the menu left a column
  298.              Right Arrow : Moves the menu right a column
  299.              Pg Up       : Moves the menu to the top of the screen at the
  300.                            current column position
  301.              Pg Down     : Moves the menu to the bottom of the screen at the
  302.                            current column position
  303.              '1'..'9'    : Changes the movement factor to number of row/cols
  304.                            specified (if you typed '9' the arrow keys would
  305.                                       move the menu 9 spaces in their re-
  306.                                       pective directions)
  307.              Ins         : Exits user from MOVE MENU mode back into SELECT
  308.                            MENU OPTION mode
  309.  
  310. 4) I have gotten a few comments that an example file might be nice so I
  311.    have added the EXMENDOW.PAS file for this purpose.
  312.  
  313. END NEW-END NEW-END NEW-END NEW-END NEW-END NEW-END NEW-END NEW-END NEW
  314.  
  315.  
  316.  
  317. Revision History
  318.  
  319.    MENDOWS : 11-01-85
  320.       Original Menu/Window driving primitives
  321.  
  322.    MENDOW10 : 4-01-86
  323.       Program specified menuing
  324.       Multiple windowing
  325.       Letter triggered menu options
  326.       Heap Management trimmed down (transparent to user)
  327.  
  328.    MENDOW20 : 9-01-86 (not released into PD)
  329.       Bug preventing use of single letter menu option 'P' fixed
  330.       Row/Column Specs Moved to within menu record
  331.       Simple 4 arrow Cursror controlled menu movement added/tested
  332.       New Keyboard Read Routines Added (transparent to user)
  333.  
  334.    MENDOW21 : 10-01-86 (released to PD)
  335.       Minor Bugs in Movable Menus fixed
  336.       Pg Up, Pg Dn, '1'..'9' features added to Movable Menus
  337.       Row Column Specs set to new menu positions if Menu Move used
  338.       Executable Example Added to the MENDOWnn.ARC
  339.       Bug causing windows to be drawn 1 line to long and Restored without the
  340.          bottom line fixed
  341.  
  342.  
  343.    FUTURE THOUGHTS
  344.       Some time soon (when I have the time) I hope to:
  345.          Complete Windowed Data Entry Screen Generation
  346.          Add MOVE WINDOWS Option
  347.          Allow Option on Window Framing (i.e. Single/Double/No Line Borders)
  348.          Allow Multi Columned Menus (don't hold you breath on this one)
  349.  
  350. ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY ENJOY
  351.  
  352. Acknowledgements: I would like to thank
  353. The unknown author of WINDOS.PAS on who's Window Generation primitives I have
  354.    based this whole include system.
  355. The equally unknown author (I wish these guys/gals would leave their names on
  356.    the software they make PD) of RDIBMKBD.PAS who's Keyboard Read routine I
  357.    have used to replace mine.
  358. THANKS Y'ALL.  You write a mean PD Include.
  359.  
  360. And most of all to David Bryant without who's help this would have been em-
  361.    inently possible (he didn't help a bit) but who happens to be one HEAVY
  362.    DUTY professional and my best friend.
  363.  
  364. Amram E. Dworkin - Programmer At Large
  365.