home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / MacCjr / MacC Jr / Alert Dialog Example / alert Dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-06  |  1.9 KB  |  88 lines  |  [TEXT/EDIT]

  1. // AlertTest.c
  2. /*
  3.   © Copyright 1987 Consulair Corp, All Rights Reserved.
  4.   
  5.   This example shows how to do alerts and  dialogs
  6.   All dialogs and alerts for this application are in the file
  7.   "Alert Dialog Resources" in this folder, and were created with
  8.   ResEdit, the resource editor.  You may use ResEdit to examine
  9.   the "Alert Dialog Resources" file.  The alertTest.link 
  10.   file shows how to include the appropriate resources.
  11.   */
  12.  
  13. #include <stdio.h>
  14. #include <macdefs.h>
  15. #include <quickdraw.h>
  16. #include <textedit.h>
  17. #include <dialog.h>
  18.  
  19. #define AlertNumber 129
  20. #define DialogNumber 130
  21. #define OKNumber 131
  22. #define CancelledNumber 132
  23.  
  24. #define okButton 1
  25. #define cancelButton 2
  26. #define TextItem 4
  27.  
  28. main()
  29.   {
  30.   short itemHit, itemNo, itemType;
  31.   Handle itemHandle;
  32.   DialogPtr dialog;
  33.   Rect rect;
  34.   Str255 text;
  35.   
  36.   // First initialize
  37.     TEInit();
  38.     InitDialogs(0);
  39.   
  40.   
  41.   // Now do an Alert
  42.     ParamText("\pThis is an Alert", "\p", "\p", "\p");
  43.     Alert(AlertNumber, 0);
  44.     
  45.   // And now some Dialogs
  46.     if ((dialog = GetNewDialog(DialogNumber, 0, -1)) != 0)
  47.       {
  48.       itemHit = 0;
  49.       InitCursor();
  50.       while (((itemHit != okButton) && (itemHit != cancelButton)))
  51.     ModalDialog(0, &itemHit);
  52.       if (itemHit == okButton)
  53.         {
  54.     GetDItem(dialog, TextItem, &itemType, &itemHandle, &rect);
  55.     GetIText(itemHandle, &text);
  56.     messageDialog(OKNumber, &text);
  57.     }
  58.       else messageDialog(CancelledNumber, 0);
  59.       DisposeDialog(dialog);
  60.       }
  61.     else noDialog(DialogNumber);
  62.   }
  63.   
  64. messageDialog(item, text)
  65.   short item;
  66.   Str255 *text;
  67.   {
  68.   DialogPtr dialog;
  69.   short itemHit;
  70.   SysBeep(3);
  71.   if ((dialog = GetNewDialog(item, 0, -1)) != 0)
  72.     {
  73.     InitCursor();
  74.     if (!text) (char *)text = "\p";
  75.     ParamText(text, "\p", "\p", "\p");
  76.     ModalDialog(0, &itemHit);
  77.     DisposeDialog(dialog);
  78.     }
  79.   else noDialog(item);
  80.   }
  81.   
  82. noDialog(item)
  83.   short item;
  84.   {
  85.   printf("\rCould Not Find Dialog #%d", item);
  86.   getchar();
  87.   }
  88.