home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / YAEC / examples / appicon.e < prev    next >
Encoding:
Text File  |  2001-02-23  |  2.8 KB  |  83 lines

  1. -> appicon.e -- Show use of an AppIcon
  2.  
  3. OPT OSVERSION=37
  4.  
  5. EXTERN 'icon'   -> YAEC
  6. EXTERN 'wb'     -> YAEC
  7. MODULE 'workbench/startup'
  8. MODULE 'workbench/workbench'
  9.  
  10. ENUM ERR_NONE, ERR_APPICON, ERR_DOBJ, ERR_LIB, ERR_PORT
  11.  
  12. RAISE ERR_APPICON IF AddAppIconA()=NIL
  13. RAISE ERR_DOBJ    IF GetDefDiskObject()=NIL
  14. RAISE ERR_LIB     IF OpenLibrary()=NIL
  15. RAISE ERR_PORT    IF CreateMsgPort()=NIL
  16.  
  17. DEF iconbase, workbenchbase
  18.  
  19. PROC main()
  20.   DEF dobj=NIL:PTR TO diskobject, myport=NIL, appicon=NIL
  21.   DEF    appmsg:PTR TO appmessage, dropcount=0, x
  22.   -> Get the the right version of the Icon Library, initialise iconbase
  23.   iconbase:=OpenLibrary('icon.library', 37)
  24.   -> Get the the right version of the Workbench Library
  25.   workbenchbase:=OpenLibrary('workbench.library', 37)
  26.   -> This is the easy way to get some icon imagery
  27.   -> Real applications should use custom imagery
  28.   dobj:=GetDefDiskObject(WBDISK)
  29.   -> The type must be set to NIL for a WBAPPICON
  30.   dobj.type:=NIL
  31.  
  32.   -> The CreateMsgPort() function is in Exec version 37 and later only
  33.   myport:=CreateMsgPort()
  34.   -> Put the AppIcon up on the Workbench window
  35.   appicon:=AddAppIconA(0, 0, 'TestAppIcon', myport, NIL, dobj, NIL)
  36.   -> For the sake of this example, we allow the AppIcon to be activated
  37.   -> only five times.
  38.   WriteF('Drop files on the Workbench AppIcon\n')
  39.   WriteF('Example exits after 5 drops\n')
  40.  
  41.   WHILE dropcount<5
  42.     -> Here's the main event loop where we wait for  messages to show up
  43.     -> from the AppIcon
  44.     WaitPort(myport)
  45.  
  46.     -> Might be more than one message at the port...
  47.     WHILE appmsg:=GetMsg(myport)
  48.       IF appmsg.numargs=0
  49.         -> If numargs is 0 the AppIcon was activated directly
  50.         WriteF('User activated the AppIcon.\n')
  51.         WriteF('A Help window for the user would be good here\n')
  52.       ELSEIF appmsg.numargs>0
  53.         -> If numargs is >0 the AppIcon was activated by having one or more
  54.         -> icons dropped on top of it
  55.         WriteF('User dropped \d icons on the AppIcon\n', appmsg.numargs)
  56.         FOR x:=0 TO appmsg.numargs-1
  57.           WriteF('#\d name=\"\s\"\n', x+1, appmsg.arglist[x].name)
  58.         ENDFOR
  59.       ENDIF
  60.       -> Let Workbench know we're done with the message
  61.       ReplyMsg(appmsg)
  62.     ENDWHILE
  63.     dropcount++
  64.   ENDWHILE
  65.  
  66. EXCEPT DO
  67.   IF appicon THEN RemoveAppIcon(appicon)
  68.   IF myport
  69.     -> Clear away any messages that arrived at the last moment
  70.     WHILE appmsg:=GetMsg(myport) DO ReplyMsg(appmsg)
  71.     DeleteMsgPort(myport)
  72.   ENDIF
  73.   IF dobj THEN FreeDiskObject(dobj)
  74.   IF workbenchbase THEN CloseLibrary(workbenchbase)
  75.   IF iconbase THEN CloseLibrary(iconbase)
  76.   SELECT exception
  77.   CASE ERR_APPICON; WriteF('Error: Could not attach AppIcon to Workbench\n')
  78.   CASE ERR_DOBJ;    WriteF('Error: Could not get default icon\n')
  79.   CASE ERR_LIB;     WriteF('Error: Could not open required library\n')
  80.   CASE ERR_PORT;    WriteF('Error: Could not create port\n')
  81.   ENDSELECT
  82. ENDPROC
  83.