home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxdemo.zip / THREADS.$$$ / WINDOW1.VRX < prev    next >
Text File  |  1993-10-22  |  4KB  |  193 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         active_list_Click
  67. */
  68. active_list_Click:
  69.     call VRSet "Halt", "Enabled", 1
  70. return
  71.  
  72. /*:VRX         DeleteThread
  73. */
  74. DeleteThread:
  75.     tid = arg( 1 )
  76.     index = VRMethod( "active_list", "FindString", tid )
  77.     if index \= 0 then do
  78.         call VRMethod "active_list", "Delete", index
  79.     end
  80. return
  81.  
  82. /*:VRX         Fini
  83. */
  84. Fini:
  85.     window = VRWindow()
  86.     call VRSet window, "Visible", 0
  87.     drop window
  88.  
  89.     call VRMethod "Application", "ListThreads", "threads."
  90.     do i = 1 to threads.0
  91.         if( threads.i \= 1 )then do
  92.             call VRMethod "Application", "HaltThread", threads.i
  93.         end
  94.     end
  95.     if( threads.0 > 1 )then do
  96.         call SysSleep 2
  97.     end
  98. return 0
  99.  
  100. /*:VRX         Halt
  101. */
  102. Halt:
  103.     signal _VREHalt
  104. return
  105.  
  106. /*:VRX         Halt_Click
  107. */
  108. Halt_Click:
  109.     id = VRGet( "active_list", "SelectedString" )
  110.     if id = "" then return
  111.  
  112.     ok = 0
  113.  
  114.     if( VRMethod( "Application", "GetThreadID" ) \= id )then do
  115.         ok = VRMethod( "Application", "HaltThread", id )
  116.         call DeleteThread id
  117.     end
  118.  
  119.     if ok = 0 then do
  120.         call VRMessage "Halt",,
  121.              "Thread" id "cannot be halted.",,
  122.              "Halt thread"
  123.     end
  124.  
  125. return
  126. /*:VRX         Init
  127. */
  128. Init:
  129.     window = VRWindow()
  130.     call VRMethod window, "CenterWindow"
  131.     call VRSet window, "Visible", 1
  132.     call VRMethod window, "Activate"
  133.     drop window
  134.  
  135.     call RXFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  136.     call SysLoadFuncs
  137.  
  138.     if( InitArgs.0 = 1 & InitArgs.1 \= '' )then do
  139.         do i = 1 to InitArgs.1
  140.             call Spawn_Click
  141.         end
  142.     end
  143.  
  144.     do while( vrevent( 'n' ) \= "nop" )
  145.         nop
  146.     end
  147.  
  148.     call UpdateThreadList
  149. return
  150.  
  151. /*:VRX         Quit
  152. */
  153. Quit:
  154.     window = VRWindow()
  155.     call VRSet window, "Shutdown", 1
  156.     drop window
  157. return
  158.  
  159. /*:VRX         ShowMessage
  160. */
  161. ShowMessage:
  162.     text = VRInfo( "message" )
  163.     call VRMethod "message_list", "Addstring", text
  164.     call UpdateThreadList
  165. return
  166.  
  167. /*:VRX         Spawn_Click
  168. */
  169. Spawn_Click:
  170.     id = VRMethod( "Application", "GetThreadID" )
  171.     call VRMethod "Application", "StartThread", "window2", id
  172.     if result = 0 then do
  173.         call VRMessage VRWindow(),,
  174.              "Could not spawn thread",,
  175.              "Spawn Error"
  176.     end
  177. return
  178.  
  179. /*:VRX         UpdateThreadList
  180. */
  181. UpdateThreadList:
  182.     call VRMethod "Application", "ListThreads", "threads."
  183.     call VRMethod "active_list", "Clear"
  184.     call VRMethod "active_list", "AddStringList", "threads."
  185. return
  186.  
  187. /*:VRX         Window1_Close
  188. */
  189. Window1_Close:
  190.     call Quit
  191. return
  192.  
  193.