home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PMABOUT.ZIP / PMABOUT.CBL < prev    next >
Text File  |  1992-12-01  |  16KB  |  352 lines

  1.       *==============================================================*
  2.        IDENTIFICATION DIVISION.
  3.       *==============================================================*
  4.        Program-ID.    PMABOUT.
  5.        Author.        Chris Fierros.
  6.        Installation.  OS/2 AAC.
  7.        Date-Written.  August 1, 1992.
  8.        Date-Compiled. August 1, 1992.
  9.        Security.      Public.
  10.       *==============================================================*
  11.        ENVIRONMENT DIVISION.
  12.       *==============================================================*
  13.       *--------------------------------------------------------------*
  14.        CONFIGURATION SECTION.
  15.       *--------------------------------------------------------------*
  16.         Source-Computer.  IBM-PS2.
  17.         Object-Computer.  IBM-PS2.
  18.         Special-Names.    Call-Convention 3 is OS2API.
  19.       *--------------------------------------------------------------*
  20.        WORKING-STORAGE SECTION.
  21.       *--------------------------------------------------------------*
  22.         COPY 'PMABOUT.CPY'.
  23.  
  24.       *--------------------------------------------------------------*
  25.        LOCAL-STORAGE SECTION.
  26.       *--------------------------------------------------------------*
  27.        01 hps                       pic s9(9) Comp-5.
  28.        01 Mresult                   pic x(4)  Comp-5.
  29.        01 Rectl.
  30.           05 xLeft                  pic s9(4) Comp-5.
  31.           05 yBottom                pic s9(4) Comp-5.
  32.           05 xRight                 pic s9(4) Comp-5.
  33.           05 yTop                   pic s9(4) Comp-5.
  34.        01 SizeWide                  pic s9(9) Comp-5.
  35.        01 SizeTall                  pic s9(9) Comp-5.
  36.        01 Color                     pic s9(9) Comp-5.
  37.       *--------------------------------------------------------------*
  38.        LINKAGE SECTION.
  39.       *--------------------------------------------------------------*
  40.        01 hwnd                      pic 9(9) Comp-5.
  41.        01 Msg                       pic 9(4) Comp-5.
  42.        01 MsgParm1                  pic 9(9) Comp-5.
  43.        01 Redefines MsgParm1.
  44.           05 MsgParm1w1             pic 9(4) Comp-5.
  45.           05 MsgParm1w2             pic 9(4) Comp-5.
  46.        01 MsgParm2                  pic 9(9) Comp-5.
  47.        01 Redefines MsgParm2.
  48.           05 MsgParm2w1             pic 9(4) Comp-5.
  49.           05 MsgParm2w2             pic 9(4) Comp-5.
  50.        01 MsgTime                   pic 9(9) Comp-5.
  51.        01 MsgXPoint                 pic 9(9) Comp-5.
  52.        01 MsgYPoint                 pic 9(9) Comp-5.
  53.       
  54.       *==============================================================*
  55.        PROCEDURE DIVISION OS2API.
  56.       *==============================================================*
  57.       *  Initialization Routine.
  58.       *  WinInitialize tells OS/2 this program will be using PM calls
  59.       *  WinCreateMsgQue creates the applications message queque
  60.       *  Set WindowProc... sets the procedure pointer to the programs
  61.       *      MainWndProc Entry point defined in the Procedure Division
  62.       *  WinRegisterClass registers the applications main window and
  63.       *      associates the MainWndProc with it.
  64.       *  WinCreateStdWindow creates the application main window
  65.       ****************************************************************
  66.            Call OS2API '__WinInitialize' 
  67.                  using  by value UShortNull
  68.                  returning hab
  69.  
  70.            Call OS2API '__WinCreateMsgQueue' 
  71.                  using  by value hab
  72.                         by value ShortNull
  73.                  returning hmq.
  74.  
  75.            Set WindowProc to ENTRY 'MainWndProc'.
  76.            Compute MainWndStyle = CS-SizeRedraw
  77.                                 + CS-ClipChildren.
  78.  
  79.            Call OS2API '__WinRegisterClass' 
  80.                  using  by value hab
  81.                         by reference MainWndClass
  82.                         by value WindowProc
  83.                         by value MainWndStyle
  84.                         by value 0 size 2
  85.                  returning ReturnData.
  86.  
  87.            If ReturnTrue
  88.               Compute MainWndControls = FCF-TITLEBAR
  89.                        + FCF-SYSMENU  + FCF-SIZEBORDER
  90.                        + FCF-MINMAX   + FCF-SHELLPOSITION
  91.                        + FCF-TASKLIST + FCF-MENU + FCF-ICON.
  92.  
  93.            Call OS2API '__WinCreateStdWindow' 
  94.                  using  by value HWND-DESKTOP
  95.                         by value ULongNull
  96.                         by reference MainWndControls
  97.                         by reference MainWndClass
  98.                         by reference MainWndTitle
  99.                         by value ULongNull
  100.                         by value UShortNull
  101.                         by value Wnd-MainWnd
  102.                         by reference hwndClient
  103.                  returning hwndFrame.
  104.  
  105.       ****************************************************************
  106.       *  Center Window.
  107.       *  The following APIs query the sysem for the width and height
  108.       *  of the display.  These values are then used to center the
  109.       *  main window on the Desktop via the WinSetWindowPos API.
  110.       ****************************************************************
  111.            Call OS2API '__WinQuerySysValue' 
  112.                  using  by value HWND-DESKTOP
  113.                         by value SV-CXSCREEN
  114.                  returning SizeWide.
  115.       
  116.            Call OS2API '__WinQuerySysValue' 
  117.                  using  by value HWND-DESKTOP
  118.                         by value SV-CYSCREEN
  119.                  returning SizeTall.
  120.  
  121.            Compute YTop    = SizeTall * .5.
  122.            Compute XRight  = sizeWide * .6.
  123.            Compute XLeft   = (SizeWide - XRight) / 2.
  124.            Compute YBottom = (SizeTall - YTop) / 2.
  125.  
  126.            Compute MainWndPosition = SWP-SIZE     
  127.                         + SWP-MOVE + SWP-ZORDER
  128.                         + SWP-SHOW + SWP-ACTIVATE.
  129.  
  130.            Call OS2API '__WinSetWindowPos' 
  131.                  using  by value hwndFrame
  132.                         by value HWND-TOP
  133.                         by value XLeft
  134.                         by value YBottom
  135.                         by value XRight
  136.                         by value YTop
  137.                         by value MainWndPosition
  138.                  returning ReturnData.
  139.  
  140.       ****************************************************************
  141.       *  Main Message Routine.
  142.       *  If the handle to the windows frame is valid then the program
  143.       *  begins the Main Message loop of retrieving messages from it
  144.       *  message queue one by one via the WinGetMsg API until it
  145.       *  receives a message of WM-Quit.  WinDispatchMsg is used to
  146.       *  send the message to the appropriate procedure.
  147.       ****************************************************************
  148.            If hwndFrame not = 0
  149.                Perform until EndFlagYes 
  150.                  Call OS2API '__WinGetMsg' 
  151.                        using  by value hab
  152.                               by reference QMSG
  153.                               by value ULongNull
  154.                               by value UShortNull
  155.                               by value UShortNull
  156.                        returning ReturnData
  157.               
  158.                  If (QMSG-MSGID = WM-QUIT)
  159.                      Set EndFlagYes to true
  160.                  Else
  161.                      Call OS2API '__WinDispatchMsg' 
  162.                            using  by value hab
  163.                                   by reference QMSG
  164.                            returning ReturnData
  165.                  End-If
  166.                End-perform
  167.            End-If.
  168.  
  169.       ****************************************************************
  170.       *  Termination Routine
  171.       *  WinDestroyWindow kills the applications main window
  172.       *  WinDestroyMsgQueue kills the applications message que
  173.       *  WinTerminate tells OS/2 that PM services are not longer needed
  174.       ****************************************************************
  175.  
  176.            Call OS2API '__WinDestroyWindow'  
  177.                  using  by value hwndFrame.
  178.            Call OS2API '__WinDestroyMsgQueue' 
  179.                  using  by value hmq.
  180.            Call OS2API '__WinTerminate' 
  181.                  using by value hab.
  182.            STOP RUN.
  183.       
  184.       *==============================================================*
  185.        MainWndProc section.
  186.       *==============================================================*
  187.       *  The Entry 'MainWndProc'... statement defines this procedures
  188.       *  entry point.  Messages are passed to this procedure via the
  189.       *  Msg, MsgParm1, and MsgParm2 parameters.  All procedures will
  190.       *  receive, evaluate, and act on messages.
  191.       *  This procedure is looking for a WM-Command, WM-Close, and
  192.       *  a WM-Paint messages.  If a WM-Command message is received
  193.       *  further evaluation as to what specific WM-Command message
  194.       *  is performed.  If a AB-About message is received (meaning the
  195.       *  user has selected "About" form the Action Bar pull down) then
  196.       *  the DialogProc entry point is set and the WinDlgBox API
  197.       *  loads the About Dialog box.
  198.       *  If a message is not acted on via WHEN then it is a WHEN OTHER
  199.       *  and the WinDEfWindowProc API tells PM to perform default
  200.       *  processing on the message or discard it.
  201.       ****************************************************************
  202.            Entry 'MainWndProc' using by value hwnd
  203.                                      by value Msg
  204.                                      by value MsgParm1
  205.                                      by value MsgParm2.
  206.            Move 0 to Mresult.
  207.  
  208.            Evaluate Msg
  209.                When WM-Command
  210.                     Evaluate MsgParm1
  211.                         When AB-About
  212.                              Set DialogProc to ENTRY 'AboutDlgProc'
  213.                              Call OS2API '__WinDlgBox'
  214.                                    using by value hwnd-DeskTop
  215.                                          by value hWnd
  216.                                          by value DialogProc
  217.                                          by value UShortNull
  218.                                          by value Dlg-About
  219.                                          by value LongNull
  220.                                    returning ReturnData
  221.                         When AB-Exit
  222.                              Perform ExitProgram
  223.                     End-Evaluate
  224.  
  225.                When WM-CLOSE
  226.                     Perform ExitProgram
  227.  
  228.                When WM-PAINT
  229.                     Perform PaintWindow
  230.  
  231.                When Other
  232.                     Call OS2API '__WinDefWindowProc'
  233.                           using by value  hwnd
  234.                                 by value  Msg
  235.                                 by value  MsgParm1
  236.                                 by value  MsgParm2
  237.                           returning Mresult
  238.            End-Evaluate.
  239.            Exit program returning Mresult.
  240.  
  241.       *--------------------------------------------------------------*
  242.        PaintWindow Section.
  243.       *--------------------------------------------------------------*
  244.       *  This routine performs the necessary API calls to re-paint
  245.       *  the client window area.  This seciton is performed only
  246.       *  when a WM-Pain message is received from the applications
  247.       *  message queue.  PM sends a WM-Paint message anytime the
  248.       *  window is moved, sizeds, maximized, minimized, restored, ect.
  249.       ****************************************************************
  250.            Move 0 to XLeft, YBottom, XRight, Ytop.
  251.            Call OS2API '__WinBeginPaint'
  252.                  using  by value hwnd
  253.                         by value LongNull
  254.                         by reference Rectl
  255.                  returning hps.
  256.  
  257.            Call OS2API '__WinFillRect' 
  258.                  using  by value hps
  259.                         by reference Rectl
  260.                         by value MainWndColor
  261.                  returning ReturnData.
  262.       
  263.            Call OS2API '__WinEndPaint' 
  264.                  using  by value hps
  265.                  returning ReturnData.
  266.  
  267.       *--------------------------------------------------------------*
  268.        ExitProgram Section.
  269.       *--------------------------------------------------------------*
  270.       *  This routine displays a message box which asks the user
  271.       *  to confirm the request to exit the application.
  272.       *  The MsgBoxControls define the attibutes of the message box 
  273.       *  such as push buttons and icons. MsgBoxMsg is defined in the 
  274.       *  copy book as the text displayed. MsgBoxTitle is defined in the
  275.       *  copy book as the title text.
  276.       *  MsgBoxButton is returned after the user selects a button from
  277.       *  the message box.  If the user select 'Yes' from the message
  278.       *  box the the WHEN MB-Yes is true and a call to post the WM-QUIT
  279.       *  message is executed.  This message is retrieved from the
  280.       *  Main Message Routine and causes the program to terminate.
  281.       ****************************************************************
  282.             Compute MsgBoxControls = MB-YESNO + MB-ICONQUESTION
  283.                                    + MB-APPLMODAL + MB-MOVEABLE.
  284.  
  285.             Call OS2API '__WinMessageBox'
  286.                   using  by value HWND-DESKTOP
  287.                          by value hwndClient
  288.                          by reference MsgBoxMsg
  289.                          by reference MsgBoxTitle
  290.                          by value UShortNull
  291.                          by value MsgBoxControls
  292.                   returning MsgBoxButton.
  293.  
  294.             Evaluate MsgBoxButton
  295.                 When MBID-YES
  296.                      Call OS2API '__WinPostMsg'
  297.                            using by Value hwndFrame
  298.                                  by Value WM-Quit size 2
  299.                                  by Value LongNull
  300.                                  by Value LongNull
  301.                            returning ReturnData
  302.                 When Other
  303.                      Continue
  304.             End-Evaluate.
  305.  
  306.       *==============================================================*
  307.        AboutDlgProc Section.
  308.       *==============================================================*
  309.       *  The About Dialog Procedure routine demonstrated how to process
  310.       *  dialogs.  This procedure is looking for a WM-Command message
  311.       *  with the first message parameter (MsgParm1) equal to Did-Ok
  312.       *  or a WM-Close message.   The WM-Close message is sent to the
  313.       *  application when the use selects "Close" from the windows
  314.       *  system menu.
  315.       ****************************************************************
  316.        Entry 'AboutDlgProc' using by value hwnd
  317.                                   by value Msg
  318.                                   by value MsgParm1
  319.                                   by value MsgParm2.
  320.        Move 0 to Mresult
  321.  
  322.        Evaluate Msg
  323.            When WM-COMMAND
  324.                 Evaluate MsgParm1
  325.                     When DID-OK
  326.                          Call OS2API '__WinDismissDlg'
  327.                                using by value Hwnd
  328.                                      by value UShortNull
  329.                     When Other
  330.                          Continue
  331.                 End-Evaluate
  332.  
  333.           When WM-CLOSE
  334.                Call OS2API '__WinDismissDlg'
  335.                      using by value Hwnd
  336.                            by value UShortNull
  337.           When Other
  338.                Call OS2API '__WinDefDlgProc'
  339.                      using by value hwnd
  340.                            by value Msg
  341.                            by value MsgParm1
  342.                            by value MsgParm2
  343.                      returning Mresult
  344.        End-Evaluate.
  345.        Exit Program Returning Mresult.
  346.  
  347.       *==============================================================*
  348.       *  END OF CODE MARKER: This marks the end of all code for this
  349.       *  program.  Any code executing after this marker has done so
  350.       *  without the knowledge or consent of the author.
  351.       *==============================================================*
  352.