home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-59 / appwindow.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  168 lines

  1. ;/* AppWindow.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=NEAR IGNORE=73 AppWindow.c
  3. slink FROM LIB:c.o,AppWindow.o TO AppWindow LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <exec/memory.h>
  32. #include <intuition/intuition.h>
  33. #include <workbench/startup.h>
  34. #include <workbench/workbench.h>
  35.  
  36. #ifdef LATTICE
  37. #include <stdio.h>
  38.  
  39. /* disable SAS/C CTRL-C handing */
  40. int
  41. CXBRK(void)
  42. {
  43.     return (0);
  44. }
  45. int
  46. chkabort(void)
  47. {
  48.     return (0);
  49. }
  50.  
  51. #include <clib/exec_protos.h>
  52. #include <clib/intuition_protos.h>
  53. #include <clib/icon_protos.h>
  54. #include <clib/wb_protos.h>
  55. #endif
  56.  
  57. struct IntuitionBase *IntuitionBase;
  58. struct WorkbenchBase *WorkbenchBase;
  59.  
  60. void            main(void);
  61.  
  62. void
  63. main(void)
  64. {
  65.     struct MsgPort *msgport;
  66.     struct Window  *window;
  67.     struct AppWindow *appwindow;
  68.     struct IntuiMessage *imsg;
  69.     struct AppMessage *appmsg;
  70.     struct WBArg   *argptr;
  71.  
  72.     ULONG           id = 1, userdata = 0;
  73.     BOOL            ABORT = FALSE;
  74.     UCOUNT          i;
  75.  
  76.     /* Open Intuition.library & Workbench.library. Fail silently if < 36 */
  77.     if (IntuitionBase = OpenLibrary("intuition.library", 36))
  78.     {
  79.         if (WorkbenchBase = OpenLibrary("workbench.library", 36))
  80.         {
  81.             /* Create the message port to which Workbench can send messages */
  82.             if (msgport = CreateMsgPort())
  83.             {
  84.                 if (window =
  85.                     OpenWindowTags(NULL, WA_Left, 0, WA_Top, 1, WA_Width, 160,
  86.                                    WA_Height, 50, WA_IDCMP, CLOSEWINDOW,
  87.                                    WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  88.                                    WA_Title, "AppWindow", TAG_END))
  89.                 {
  90.  
  91.                     /*
  92.                      * Turn the window we opened into an AppWindow. Provide an
  93.                      * ID so you can tell possible more AppWindows apart.
  94.                      */
  95.                     if (appwindow = AddAppWindow(id, userdata, window, msgport, NULL))
  96.                     {
  97.                         do
  98.                         {
  99.                             /* Wait for either a CLOSEWINDOW or an AppMessage */
  100.                             Wait(1 << window->UserPort->mp_SigBit |
  101.                                 1 << msgport->mp_SigBit);
  102.                             while (imsg = (struct IntuiMessage *)
  103.                                 GetMsg(window->UserPort))
  104.                             {
  105.                                 if (imsg->Class = CLOSEWINDOW)
  106.                                     ABORT = TRUE;
  107.                                 ReplyMsg((struct Message *) imsg);
  108.                             }
  109.                             while (appmsg = (struct AppMessage *) GetMsg(msgport))
  110.                             {
  111.  
  112.                                 /*
  113.                                  * The AppMessage type will be MTYPE_APPWINDOW,
  114.                                  * the ID & userdata are what we supplied when
  115.                                  * the window was designed as an AppWindow.
  116.                                  * NumArgs allows us to process the Workbench
  117.                                  * arguments properly.
  118.                                  */
  119.                                 printf(
  120.                        "aw: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n",
  121.                                        appmsg, appmsg->am_Type, appmsg->am_ID,
  122.                                        appmsg->am_UserData, appmsg->am_NumArgs);
  123.  
  124.                                 /*
  125.                                  * Get a pointer to the start of the Workbench
  126.                                  * argument list.
  127.                                  */
  128.                                 argptr = appmsg->am_ArgList;
  129.                                 for (i = 0; i < appmsg->am_NumArgs; i++)
  130.                                 {
  131.  
  132.                                     /*
  133.                                      * The lock will be on the directory in
  134.                                      * which the file resides. If there is no
  135.                                      * filename, either a volume or window was
  136.                                      * dropped on us.
  137.                                      */
  138.                                     printf("\targ(%ld): Name='%s', Lock=%lx\n",
  139.                                            i, argptr->wa_Name, argptr->wa_Lock);
  140.                                     /* Point to next argument */
  141.                                     argptr++;
  142.                                 }
  143.                                 ReplyMsg((struct Message *) appmsg);
  144.                             }
  145.                         } while (ABORT == FALSE);
  146.                         /* remove the appwindow status and close down */
  147.                         RemoveAppWindow(appwindow);
  148.                     }
  149.                     else
  150.                         printf("Couldn't AddAppWindow\n");
  151.                     CloseWindow(window);
  152.                 }
  153.                 else
  154.                     printf("Couldn't open window\n");
  155.                 DeleteMsgPort(msgport);
  156.             }
  157.             else
  158.                 printf("Coulnd't create messageport\n");
  159.             CloseLibrary(WorkbenchBase);
  160.         }
  161.         else
  162.             printf("Couldn't open workbench.library\n");
  163.         CloseLibrary(IntuitionBase);
  164.     }
  165.     else
  166.         printf("Couldn't open intuition.library\n");
  167. }
  168.