[Toc][Index]

Switch a REXX program in the foreground



Sometimes it is useful if a REXX program can switch itself in the 
foreground. To do this, you need to create an temporary WPS object for 
your REXX program and then use <SysSetObjectData inside your REXX program. 

Example: 

 
/* ------------------------------------------------------------------ */
/* FOREGROUND.CMD - example code for a REXX program that can switch   */
/*                  itself in the foreground                          */
/*                                                                    */
/*                                                                    */

                    /* load REXX util                                 */
  call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLodFuncs'
  call SysLoadFuncs

  global. = ''
                    /* the fully qualified name of this program is    */
                    /* neccessary for the SysCreateObject call below  */
  parse source . . global.__thisProg

                    /* a special parameter is neccessary to           */
                    /* distinguish between the first call and the     */
                    /* call via the WPS object                        */
  special_parameter = '$$REAL_START$$'


                    /* get and check the parameter                    */
  parse arg special_parm global.__this_objectID normal_parameter

  if special_parm <> special_parameter then
  do
                    /* this is the very first start of the program:   */
                    /* Here we only create a temporary WPS object for */
                    /* ourself and restart us using this object       */

                    /* get all parameter again for the                */
                    /* SysCreateObject call                           */
    parse arg real_parameter

                    /* get a unique string for an object ID           */
    curString = rxqueue( 'create ')
    call rxqueue curString, delete

    global.__this_objectID = '<' || curString || '>'

                    /* now create the temporary object                */
    call SysCreateObject "WPProgram"      ,,
                        global.__thisProg ,,
                       '<WP_NOWHERE>'     ,,
                       'CCVIEW=NO;NOAUTOCLOSE=NO;'|| 'PROGTYPE=WINDOWABLEVIO;EXENAME=*;PARAMETERS=' || '/c "' global.__thisProg special_parameter curString real_parameter || '";' || 'OBJECTID=' || global.__this_objectID || ';' , "Update"

                    /* open the Object (= start this program again)   */
    call SysSetObjectData global.__this_objectID, "OPEN=DEFAULT;"

                    /* put the telnet session into the foreground     */
    call SysSetObjectData global.__this_objectID, "OPEN=DEFAULT;"

                    /* that's all - exit now                          */
    exit 0
  end /* if */

                    /* this is the second start via the object        */
  global.__this_objectID = '<' || global.__this_objectID || '>'

  say ''
  say 'This is ' || global.__thisProg || ' called via the temporary object '

  say 'The object ID of our object is: "' || global.__this_objectID || '"'
  say 'The parameter for this program are : "' || normal_parameter || '"'
  say ''
  say 'Now we wait for 10 seconds and then we put ourselv into the foreground again ...'
  call SysSleep 10

  call SysSetObjectData global.__this_objectID , 'OPEN=DEFAULT;'
  say 'Now we are back in the foreground'

  say 'OK, that''s all for now '
  'pause'


                    /* delete the temporary object                    */
                    /* Note: You should add this code also to any     */
                    /*       error handler in your program!           */
  say 'Deleting the object "' || global.__this_objectID || '" ...'
  call SysDestroyObject global.__this_objectID
exit 0

  

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs