home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 600-699 / ff634.lha / APIG / apig33.lzh / easyrequest4.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-22  |  4KB  |  121 lines

  1.  
  2. /* Example of EasyRequest using BuildEasyRequestArgs */
  3.  
  4. x = addlib("apig.library",0,-30,0)
  5.  
  6. call set_apig_globals()
  7.  
  8. portname = "easyreq4_port"     
  9. p = openport(portname)  
  10.  
  11. WaitForPort portname  
  12.  
  13. wintitle = "Build Easy Requester Example"
  14. winidcmp = IDCMP_CLOSEWINDOW 
  15. winflags = WFLG_CLOSEGADGET+WFLG_DRAGBAR+WFLG_SIZEGADGET+WFLG_DEPTHGADGET+WFLG_GIMMEZEROZERO
  16. win = openwindow(portname,0,0,640,200,2,4,winidcmp,winflags,wintitle,null(),0,0,0)
  17.  
  18. /* now we need to make args for BuildEasy... */
  19.  
  20. /* allocate an EasyStruct structure */
  21. easystruct = MAKESTRUCT(0,29,0,MEMF_CLEAR)  /* type 29 is an EasyStruct */
  22.                                             /* see docs                 */
  23. /* EasyStruct looks like this:
  24.                                byte offset 0  es_StructSize      ULONG
  25.                                            4  es_Flags           ULONG
  26.                                            8  es_Title           UBYTE *
  27.                                           12  es_TextFormat      UBYTE *
  28.                                           16  es_GadgetFormat    UBYTE *
  29.                                size = 20  
  30.  ---------------------------------------------------------------- */
  31.  
  32. /* make our arglist, which is owned by the easystruct */
  33. arglist = MAKEPOINTER(easystruct,0,64,MEMF_CLEAR)
  34.  
  35. call SETVALUE(arglist,0,4,'n',22)  /* I'm just stuffing some random */
  36. call SETVALUE(arglist,4,4,'n',32)  /* values into the args, nothing */
  37. call SETVALUE(arglist,8,4,'n',42)  /* special about these values    */
  38.  
  39. call SETVALUE(arglist,12,4,'n',1)  /* These are the gadget numbers  */
  40. call SETVALUE(arglist,16,4,'n',2)
  41. call SETVALUE(arglist,20,4,'n',0)
  42.  
  43. reqtitle = "This is your EasyRequester"
  44.  
  45. reqtext = "Say Buddy If You Insert or Remove a Disk ..." '0a'x '0a'x 
  46. reqtext = reqtext || "   ... I'll go away %ld %ld %ld " '0a'x '0a'x
  47. reqtext = reqtext || " YOU REALLY MUST INSERT/REMOVE A DISK !!! " '0a'x
  48.  
  49. gadtext = " %ld). OKAY | %ld). MAYBE | %ld). NOWAY "
  50.  
  51. /* make buffers for title/text/gadget, the memory allocated will be 'owned'
  52.    by easystruct */
  53.  
  54. titleptr  = MAKEPOINTER(easystruct,0,length(reqtitle)+1,MEMF_CLEAR)
  55. textptr   = MAKEPOINTER(easystruct,0,length(reqtext)+1,MEMF_CLEAR)
  56. gadgetptr = MAKEPOINTER(easystruct,0,length(gadtext)+1,MEMF_CLEAR)
  57.  
  58. call export(titleptr,reqtitle)
  59. call export(textptr,reqtext)
  60. call export(gadgetptr,gadtext)
  61.  
  62. call SETVALUE(easystruct,0,4,'n',20)         /* es->es_StructSize   */
  63. call SETVALUE(easystruct,4,4,'n',0)          /* es->es_Flags        */
  64. call SETVALUE(easystruct,8,4,'p',titleptr)   /* es->es_Title        */
  65. call SETVALUE(easystruct,12,4,'p',textptr)   /* es->es_TextFormat   */
  66. call SETVALUE(easystruct,16,4,'p',gadgetptr) /* es->es_GadgetFormat */
  67.  
  68. reqx = BUILDEASYREQUESTARGS(win,easystruct,IDCMP_DISKINSERTED+IDCMP_DISKREMOVED,arglist)
  69.  
  70.  /* idcmpptr is where IDCMP value is returned */
  71. idcmpptr = makepointer(easystruct,0,4,MEMF_CLEAR)
  72.  
  73. wearedone = 0
  74. do while wearedone = 0
  75.  
  76.    sysreqx = SYSREQHANDLER(reqx,idcmpptr,1)  /* ... and wait */
  77.  
  78.    /* sysreqx = SYSREQHANDLER(reqx,idcmpptr,0) ... if you do this then */
  79.                                         /* sysreqhandler will NOT WAIT */
  80.  
  81.    select 
  82.      when sysreqx = -2 then iterate
  83.  
  84.      when sysreqx = -1 then  /* satisfied by IDCMP, unlike EASYREQUEST() */
  85.                              /* I dont give you the negative value, you  */
  86.                              /* have to look in *idcmpptr.               */
  87.         do
  88.             idcmp = GETVALUE(idcmpptr,0,4,'n')
  89.             select 
  90.                    when idcmp = IDCMP_DISKINSERTED then 
  91.                         do
  92.                            say "I see you Inserted a DISK"
  93.                            wearedone = 1
  94.                         end
  95.                    when idcmp = IDCMP_DISKREMOVED then
  96.                         do
  97.                            say "I see you Removed a DISK"
  98.                            wearedone = 1
  99.                         end
  100.                    otherwise nop
  101.             end
  102.         end
  103.      otherwise
  104.         do
  105.             select
  106.                when sysreqx = 1 then say " 'OKAY'  ... is OKAY with me too !"
  107.                when sysreqx = 2 then say " 'MAYBE' ... not sure uh ? "
  108.                when sysreqx = 0 then say " 'NOWAY' ... I'm outta here !"
  109.                otherwise nop
  110.             end
  111.         end
  112.    end
  113.  
  114. end
  115.  
  116. call FREETHIS(easystruct) /* title/text/gadget buffers freed too! */
  117. call FREESYSREQUEST(reqx)
  118. call CLOSEWINDOW(win)
  119.  
  120. exit
  121.