home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxdlg11.zip / rx2.c < prev    next >
Text File  |  1995-03-03  |  5KB  |  145 lines

  1. /* RX2.C (RX2.EXE)
  2.  *
  3.  * This is a Presentation Manager program that launches a REXX script and allows it to open and use a PM window
  4.  * with PM controls in order to obtain user input (as opposed to "pull"ing from a command line prompt). It takes 1 arg
  5.  * from OS/2; the name of the REXX script to launch. It uses Rexx Dialog to implement the REXX/PM interface.
  6.  */
  7.  
  8. #define INCL_WININPUT
  9. #define INCL_WINSWITCHLIST
  10. #define INCL_WINSYS
  11. #define INCL_WINFRAMEMGR
  12. #define INCL_WINWINDOWMGR
  13.  
  14. #include <os2.h>
  15. #include "rx.h"
  16.  
  17.  
  18. /* Global vars */
  19. HMQ       hmq;
  20. HWND     hwndFrame;
  21. UCHAR * ScriptName;
  22. UCHAR     myClassName[] = "My class";
  23.  
  24.  
  25.  
  26. /***************************** myClientWndProc() ****************************
  27.  * Window procedure for my client window
  28.  *************************************************************************/
  29. MRESULT EXPENTRY myClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  30. {
  31.     RECTL  rcl;
  32.     HPS      hps;
  33.  
  34.     switch (msg)
  35.     {
  36.     case WM_PAINT:
  37.         /* Fill update region with background color. There is nothing but perhaps child controls
  38.         in the window, and they will receive their own WM_PAINT subsequently */
  39.         hps = WinBeginPaint(hwnd, 0, &rcl);
  40.         WinFillRect(hps, &rcl, 15);
  41.         WinEndPaint(hps);
  42.         return(0);
  43.  
  44.     /* The following WM_HITTEST case is to support disabling the Client and
  45.         its children when the REXX script opens a MODAL window */
  46.     case WM_HITTEST:
  47.         /* Check for MODAL window handling */
  48.         return(DlgCheckModal(hwnd, mp1));
  49.  
  50.     case WM_BUTTON1DBLCLK:
  51.         /* Execute REXX script unless there is currently a script already being executed */
  52.         if (!(RexxSpec.Flags & EXECUTING)) RexxRunScript(ScriptName);
  53.         break;
  54.  
  55.     case WM_CLOSE:
  56.         /* If a REXX script is currently being executed, don't allow the app to be closed down.
  57.         Alternately, if we really wanted to close everything down, then we could just
  58.         comment out this WM_CLOSE case, and it will cause the script to
  59.         receive an RXDLG return of -99 (ie, ABORT) when it does an operation with
  60.         user interaction */
  61.         if (RexxSpec.Flags & EXECUTING) return(0);
  62.  
  63.         /* Otherwise, fall through to do the default procedure and allow close down */
  64.     }
  65.     return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  66. }
  67.  
  68.  
  69.  
  70. /********************************** main() ********************************
  71.  * 1. Initializes PM environment: obtains anchor block handle and creates msg queue
  72.  *    that all of the Rexx Dialog windows use.
  73.  * 2. Opens a Main Window on behalf of the REXX script.
  74.  * 3. Calls RexxSet() routine (init RXDLG.DLL stuff)
  75.  * 4. Executes REXX script
  76.  * 5. Frees resources
  77.  * 6. Ends program
  78.  *
  79.  * Return: 0 if successful execution, non-zero if error
  80.  *************************************************************************/
  81. int main(int argc, char *argv[], char *envp[])
  82. {
  83.     QMSG   qmsg;
  84.  
  85.     /* Obtain a PM anchor block. Store it in REXXSPEC */
  86.     if(!(RexxSpec.Hab = WinInitialize(0)))
  87.     {
  88. badinit:
  89.     DosBeep(60, 120);
  90.     return(ERRAPP);
  91.     }
  92.  
  93.     /* Obtain a PM Message Queue */
  94.     if(!(hmq = WinCreateMsgQueue(RexxSpec.Hab, 0)))
  95.     {
  96.     WinTerminate(RexxSpec.Hab);
  97.     goto badinit;
  98.     }
  99.  
  100.     /* Register my window class */
  101.     WinRegisterClass(RexxSpec.Hab, &myClassName[0], myClientWndProc, CS_HITTEST, 0);
  102.  
  103.     /* Create a standard PM Window and store client window handle in REXXSPEC Hwnd */
  104.     qmsg.reserved = FCF_TITLEBAR|FCF_SIZEBORDER|FCF_SYSMENU|FCF_MINMAX|FCF_SHELLPOSITION|FCF_TASKLIST;
  105.     if(!(hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &qmsg.reserved, &myClassName[0],
  106.          "My C App Window", 0, 0, 0, &RexxSpec.Hwnd))) goto badinit2;
  107.  
  108.     /* Is there a REXX script name specified? */
  109.     if (argc>1)
  110.     {
  111.     /* Install REXX support */
  112.     if((qmsg.reserved = RexxSet()))
  113.     {
  114.         DlgErrMsg(qmsg.reserved, qmsg.reserved+ERRINIT);
  115.     }
  116.     else
  117.     {
  118.         /* Store the REXX script name */
  119.         ScriptName = argv[1];
  120.  
  121.         /* Do a PM message loop until our app window is closed */
  122.         while (WinGetMsg(RexxSpec.Hab, &qmsg, 0, 0, 0))
  123.         WinDispatchMsg(RexxSpec.Hab, &qmsg);
  124.  
  125.         /* Uninstall REXX support */
  126.         RexxFree();
  127.     }
  128.     }
  129.     /* Print usage */
  130.     else
  131.     {
  132.     DlgMsgStr("Usage: RX2 [Rexx script filename]", 0, 0);
  133.     }
  134.  
  135.     /* Destroy the window */
  136.     WinDestroyWindow(hwndFrame);
  137.  
  138.     /* Free resources */
  139.     WinDestroyMsgQueue(hmq);
  140.     WinTerminate(RexxSpec.Hab);
  141.  
  142.     /* Return error code */
  143.     return(RexxSpec.ErrNum);
  144. }
  145.