home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / workbench / appicon.e next >
Text File  |  1977-12-31  |  3KB  |  80 lines

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