home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxcliser.zip / VXREXX.3 / SAMPLES / THREADS / THREADS.VRX < prev    next >
Text File  |  1994-12-23  |  4KB  |  200 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         Fini
  67. */
  68. Fini:
  69.     /* Destroy the window
  70.     */
  71.  
  72.     window = VRWindow()
  73.     call VRSet window, "Visible", 0
  74.     drop window
  75.  
  76.     /* Halt the remaining threads
  77.     */
  78.  
  79.     call VRMethod "Application", "ListThreads", "threads."
  80.     do i = 1 to threads.0
  81.         if( threads.i \= 1 )then do
  82.             call VRMethod "Application", "HaltThread", threads.i
  83.         end
  84.     end
  85.     if( threads.0 > 1 )then do
  86.         call SysSleep 2
  87.     end
  88. return 0
  89.  
  90. /*:VRX         Halt
  91. */
  92. Halt:
  93.     signal _VREHalt
  94. return
  95.  
  96. /*:VRX         Init
  97. */
  98. Init: procedure expose InitArgs.
  99.     /* Create the window
  100.     */
  101.  
  102.     window = VRWindow()
  103.     call VRMethod window, "CenterWindow"
  104.     call VRSet window, "Visible", 1
  105.     call VRMethod window, "Activate"
  106.  
  107.     /* Rexx call to load 'SysLoadFuncs' function.
  108.     */
  109.  
  110.     call RxFuncAdd "SysLoadFuncs", "REXXUTIL", "SysLoadFuncs"
  111.     call SysLoadFuncs
  112.  
  113.     /* InitArgs.0 is the number of parameters passed to the application.
  114.         and InitArgs.1 is the first parameter.
  115.     */
  116.  
  117.     if( InitArgs.0 = 1 ) then do
  118.         do i = 1 to InitArgs.1
  119.             call VRMethod "Application", "StartThread", "child"
  120.         end
  121.     end
  122.  
  123.     /* VREvent( "N" ) sets the 'nowait' option for VREvent.
  124.     */
  125.  
  126.     do while( VREvent( "N" ) <> "nop" )
  127.         nop
  128.     end
  129.  
  130.     call Update
  131. return
  132.  
  133. /*:VRX         LB_Threads_Click
  134. */
  135. LB_Threads_Click:
  136.     call VRSet "PB_Halt", "Enabled", 1
  137. return
  138.  
  139. /*:VRX         PB_Halt_Click
  140. */
  141. PB_Halt_Click:
  142.     /* Halt the specified thread.
  143.     */
  144.  
  145.     tid = VRGet( "LB_Threads", "SelectedString" )
  146.     call VRMethod "Application", "HaltThread", tid
  147.     call VRMethod "LB_Threads", "DeleteString", tid
  148.     call VRSet "PB_Halt", "Enabled", 0
  149.     drop tid    
  150. return
  151. /*:VRX         PB_Spawn_Click
  152. */
  153. PB_Spawn_Click:
  154.     /* Start a thread
  155.     */
  156.  
  157.     call VRMethod "Application", "StartThread", "child"
  158. return
  159.  
  160. /*:VRX         Quit
  161. */
  162. Quit:
  163.     /* Close the application
  164.     */
  165.  
  166.     window = VRWindow()
  167.     call VRSet window, "Shutdown", 1
  168.     drop window
  169. return
  170.  
  171. /*:VRX         ShowMessage
  172. */
  173. ShowMessage: procedure
  174.     /* Show message from thread.
  175.     */
  176.  
  177.     call VRMethod "LB_Messages", "Addstring", VRInfo( "Message" )
  178.     call Update
  179. return
  180.  
  181. /*:VRX         Update
  182. */
  183. Update: procedure
  184.     /* Update the 'Threads' list box.
  185.     */
  186.  
  187.     call VRMethod "Application", "ListThreads", "threads."
  188.     call VRMethod "LB_Threads", "Clear"
  189.     do i = 2 to threads.0
  190.         call VRMethod "LB_Threads", "AddString", threads.i
  191.     end
  192. return
  193.  
  194. /*:VRX         Window1_Close
  195. */
  196. Window1_Close:
  197.     call Quit
  198. return
  199.  
  200.