home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / ictbSample / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-15  |  2.0 KB  |  108 lines  |  [TEXT/CWIE]

  1. /*
  2.     main.c
  3.     
  4.     Use of ictb snippet
  5.     Albert Hui -- MacDTS
  6.     
  7.     This snippet shows the an example of ictb resource this is discussed in 
  8.     Inside Macintosh:Macintosh Toolbox Essentials, page 6-158 t0 6-164.
  9.     It is based on the Dialog Manager Q&A technote.  You can find the technote
  10.     in the latest developer CD:
  11.     
  12.         Dev.CD Jun 96 RL
  13.           Technical Documentation
  14.             Macintosh Technical Notes
  15.               Archive
  16.                 Toolbox
  17.                   tb_525.html.
  18.              
  19.     There is no Rez template for it, and no ResEdit template or editor.  This sample
  20.     ictbSample.r shows how you can do one by hand.
  21.  
  22.     The best solution is to get Resorcerer which provides an excellent ictb editor. 
  23.     With Resorcerer, it is really simple to use ictb in your dialog boxes.
  24.     
  25.     This sample is built with CW 9. 
  26. */
  27.  
  28. #include <TextEdit.h>
  29.  
  30. // constants
  31.  
  32. #define    kMyDialog        128
  33. #define kDone            1
  34. #define    kCheckOneItem    2
  35. #define    kCheckTwoItem    3
  36. #define kCheckThreeItem 4
  37. #define    kEditTextItem1    5
  38. #define    kEditTextItem2    6
  39. #define    kEditTextItem3    7
  40.  
  41. // prototypes
  42.  
  43. void main(void);
  44. void InitStuff(void);
  45. void DoDialog(void);
  46. void SetupDialog(DialogPtr theDialog);
  47. void PrepareFreeDialog(DialogPtr theDialog);
  48.  
  49.  
  50.  
  51.  
  52. /* main entry point */
  53.  
  54. void main(void)
  55. {
  56.     InitStuff();
  57.     DoDialog();
  58.     ExitToShell();
  59. }
  60.  
  61.  
  62. /* initialize the Mac managers */
  63.  
  64. void InitStuff(void)
  65. {
  66.     InitGraf(&qd.thePort);
  67.     InitFonts();
  68.     InitWindows();
  69.     InitMenus();
  70.     TEInit();
  71.     InitDialogs(nil);
  72.     InitCursor();
  73.     FlushEvents(everyEvent,0);
  74. }
  75.  
  76.  
  77. /*    display dialog, and handle pretty standard ModalDialog loop.  
  78. */
  79.  
  80. void DoDialog(void)
  81. {
  82.     DialogPtr theDialog;
  83.     short item;
  84.     ControlHandle checkBoxControl;
  85.     short iType;
  86.     Rect iRect;
  87.     
  88.     theDialog = GetNewDialog(kMyDialog,nil,(WindowPtr)-1L);
  89.         
  90.     do {
  91.         ModalDialog(NULL,&item);
  92.         switch (item) {
  93.             case kCheckOneItem:    // check boxes
  94.             case kCheckTwoItem:
  95.             case kCheckThreeItem:
  96.                 GetDItem(theDialog,item,&iType,(Handle *)&checkBoxControl,&iRect);
  97.                 SetCtlValue(checkBoxControl,!GetCtlValue(checkBoxControl));
  98.                 break;
  99.         }    
  100.     } while (item!=kDone);
  101.     
  102.     DisposeDialog(theDialog);
  103. }
  104.  
  105.  
  106.  
  107.  
  108.