home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / winpubscreen.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-21  |  2.8 KB  |  102 lines

  1. ;/* winpubscreen.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 winpubscreen.c
  3. Blink FROM LIB:c.o,winpubscreen.o TO winpubscreen LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. **
  6. ** winpubscreen.c
  7. ** open a window on the default public screen (usually the Workbench screen)
  8. */
  9.  
  10. #define INTUI_V36_NAMES_ONLY
  11.  
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #ifdef LATTICE
  19. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  20. int chkabort(void) { return(0); }  /* really */
  21. #endif
  22.  
  23. struct Library *IntuitionBase;
  24.  
  25. /* our function prototypes */
  26. VOID handle_window_events(struct Window *win);
  27.  
  28.  
  29. /*
  30. ** Open a simple window on the default public screen,
  31. ** then leave it open until the user selects the close gadget.
  32. */
  33. VOID main(int argc, char **argv)
  34. {
  35. struct Window *test_window = NULL;
  36. struct Screen *test_screen = NULL;
  37.  
  38. IntuitionBase = OpenLibrary("intuition.library",37);
  39. if (IntuitionBase)
  40.     {
  41.     /* get a lock on the default public screen */
  42.     if (test_screen = LockPubScreen(NULL))
  43.             {
  44.             /* open the window on the public screen */
  45.             test_window = OpenWindowTags(NULL,
  46.                     WA_Left,  10,    WA_Top,    20,
  47.                     WA_Width, 300,   WA_Height, 100,
  48.                     WA_DragBar,         TRUE,
  49.                     WA_CloseGadget,     TRUE,
  50.                     WA_SmartRefresh,    TRUE,
  51.                     WA_NoCareRefresh,   TRUE,
  52.                     WA_IDCMP,           IDCMP_CLOSEWINDOW,
  53.                     WA_Title,           "Window Title",
  54.                     WA_PubScreen,       test_screen,
  55.                     TAG_END);
  56.  
  57.             /* Unlock the screen.  The window now acts as a lock on
  58.             ** the screen, and we do not need the screen after the
  59.             ** window has been closed.
  60.             */
  61.             UnlockPubScreen(NULL, test_screen);
  62.  
  63.             /* if we have a valid window open, run the rest of the
  64.             ** program, then clean up when done.
  65.             */
  66.             if (test_window)
  67.                 {
  68.                 handle_window_events(test_window);
  69.                 CloseWindow(test_window);
  70.                 }
  71.             }
  72.     CloseLibrary(IntuitionBase);
  73.     }
  74. }
  75.  
  76. /*
  77. ** Wait for the user to select the close gadget.
  78. */
  79. VOID handle_window_events(struct Window *win)
  80. {
  81. struct IntuiMessage *msg;
  82. BOOL done = FALSE;
  83.  
  84. while (! done)
  85.     {
  86.     /* We have no other ports of signals to wait on,
  87.     ** so we'll just use WaitPort() instead of Wait()
  88.     */
  89.     WaitPort(win->UserPort);
  90.  
  91.     while ( (! done) &&
  92.             (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  93.         {
  94.         /* use a switch statement if looking for multiple event types */
  95.         if (msg->Class == IDCMP_CLOSEWINDOW)
  96.             done = TRUE;
  97.  
  98.         ReplyMsg((struct Message *)msg);
  99.         }
  100.     }
  101. }
  102.