home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file18 / bldrsc.cpp next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  10.1 KB  |  330 lines

  1. // Program : BLDRSC.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Wed 08/25/93 13:54:55
  4. // Note    : Copyright 1993, Eric Woodruff, All rights reserved
  5. // Compiler: Borland C++ 3.1
  6. //
  7. // This program is a generic resource file builder.  Plug in the
  8. // builder functions and declarations then compile.
  9. //
  10.  
  11. #define RSC_FILENAME    "EXPDEMO.RSC"      // File to create.
  12.  
  13. #define WriteResource(a,b,c) \
  14.     cout << c << endl; \
  15.     a = b(); \
  16.     if( a == 0 ) \
  17.     { \
  18.         strcpy(endString, RSC_FILENAME ": Creation failure\n"); \
  19.         TObject::destroy(rsc); \
  20.         exit(1); \
  21.     } \
  22.     rsc->put(a,c); \
  23.     TObject::destroy(a)
  24.  
  25. #define WriteObject(a,c) \
  26.     cout << c << endl; \
  27.     if(a == 0) \
  28.     { \
  29.         strcpy(endString, RSC_FILENAME ": Creation failure\n"); \
  30.         TObject::destroy(rsc); \
  31.         exit(1); \
  32.     } \
  33.     rsc->put(a,c); \
  34.     TObject::destroy(a)
  35.  
  36. #include <conio.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40.  
  41. #define Uses_TApplication
  42. #define Uses_TButton
  43. #define Uses_TCheckBoxes
  44. #define Uses_TDeskTop
  45. #define Uses_TDialog
  46. #define Uses_TInputLine
  47. #define Uses_TKeys
  48. #define Uses_TLabel
  49. #define Uses_TMenuBar
  50. #define Uses_TMenuItem
  51. #define Uses_TProgram
  52. #define Uses_TRadioButtons
  53. #define Uses_TRect
  54. #define Uses_TResourceFile
  55. #define Uses_TSItem
  56. #define Uses_TStaticText
  57. #define Uses_TStatusDef
  58. #define Uses_TStatusItem
  59. #define Uses_TStatusLine
  60. #define Uses_TSubMenu
  61. #define Uses_TView
  62. #define Uses_fpstream
  63. #include <tv.h>
  64.  
  65. __link(RButton)
  66. __link(RCheckBoxes)
  67. __link(RCluster )
  68. __link(RInputLine)
  69. __link(RLabel)
  70. __link(RMenuBar)
  71. __link(RRadioButtons)
  72. __link(RResourceCollection)
  73. __link(RStaticText)
  74. __link(RStatusLine)
  75.  
  76. #define Uses_TExplodeWindow
  77. #define Uses_TExplodeDialog
  78. #include <texplode.h>
  79.  
  80. // NOTE: Always be sure to include these two lines somewhere in your
  81. //       program if you are using streamed TExplodeWindow and/or
  82. //       TExplodeDialog objects (i.e. loading them from a resource file)!
  83. __link(RExplodeWindow)
  84. __link(RExplodeDialog)
  85.  
  86. #include <expdemo.h>
  87.  
  88. // ============================================================================
  89. TDialog *AboutBox(void);
  90. TMenuBar *initMenuBar(void);
  91. TStatusLine *initStatusLine(void);
  92.  
  93. Boolean createDemo3Window(void);
  94. TDialog *createDemo4Dialog(void);
  95.  
  96. // ============================================================================
  97.  
  98. fpstream *s;
  99. TResourceFile* rsc;
  100. char endString[255] = "";
  101.  
  102. // ============================================================================
  103.  
  104. void exitfunc(void)
  105. {
  106.    cout << endl << endString << endl;
  107. }
  108.  
  109. #pragma exit exitfunc 31
  110.  
  111. void main(void)
  112. {
  113.     TDialog *dlg;
  114.     TMenuBar *menuBar;
  115.     TStatusLine *statusLine;
  116.  
  117.     cout << "Creating " RSC_FILENAME << endl;
  118.  
  119.     // Construct stream and resource.
  120.     s = new fpstream (RSC_FILENAME, ios::trunc | ios::binary);
  121.     rsc = new TResourceFile(s);
  122.  
  123.     // Create all of the necessary dialogs for the program.
  124.     WriteResource(dlg, AboutBox, "AboutBox");
  125.  
  126.     if(!createDemo3Window())        // Writes directly to the stream.
  127.     {
  128.         cout << RSC_FILENAME << ": Creation failure" << endl; \
  129.         TObject::destroy(rsc); \
  130.         exit(1); \
  131.     }
  132.     WriteResource(dlg, createDemo4Dialog, "Demo4");
  133.  
  134.     // Create the menus and status line.
  135.     WriteResource(menuBar, initMenuBar, "MenuBar");
  136.     WriteResource(statusLine, initStatusLine, "StatusLine");
  137.  
  138.     TObject::destroy(rsc);
  139.     strcpy(endString, RSC_FILENAME " creation completed.");
  140. }
  141.  
  142. // ============================================================================
  143.  
  144. TDialog *AboutBox(void)
  145. {
  146.     TExplodeDialog *aboutBox = new TExplodeDialog(TRect(0, 0, 46, 11),
  147.          "About");
  148.     aboutBox->options |= ofCentered;
  149.     aboutBox->MakeItExplode(30);        // Change explode/implode rate.
  150.  
  151.     aboutBox->insert(new TStaticText(TRect(2, 2, 45, 7),
  152.             "\003TExplodeWindow/TExplodeDialog Class Demo\n"
  153.             "\003Streamable Versions\n\003\n"
  154.             "\003by Eric Woodruff\n\003CIS ID: 72134,1150\n"));
  155.  
  156.     TButton *b = new TButton(TRect(11,8,23,10), "O~K~", cmOK, bfDefault);
  157.     b->options |= ofCenterX;
  158.     aboutBox->insert(b);
  159.  
  160.     return aboutBox;
  161. }
  162.  
  163. TMenuBar *initMenuBar(void)
  164. {
  165.     TSubMenu& MiscMenu = *new TSubMenu( "~\xF0~", 0 ) +
  166.         *new TMenuItem( "~A~bout...", cmAboutCmd, kbNoKey) +
  167.          newLine() +
  168.         *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt+X" );
  169.  
  170.     TSubMenu& DemoMenu = *new TSubMenu("~E~xplode Demos", 0) +
  171.         *new TMenuItem("~T~ExplodeWindow demo", cmDemo1, kbF2,
  172.                         hcNoContext, "F2") +
  173.         *new TMenuItem("T~E~xplodeDialog demo", cmDemo2, kbF3,
  174.                         hcNoContext, "F3") +
  175.         *new TMenuItem("~G~et TExplodeWindow from stream", cmDemo3, kbF7,
  176.                         hcNoContext, "F7") +
  177.         *new TMenuItem("Get TE~x~plodeDialog from stream", cmDemo4, kbF8,
  178.                         hcNoContext, "F8");
  179.  
  180.     TSubMenu& WindowMenu = *new TSubMenu( "~W~indows", 0 ) +
  181.         *new TMenuItem( "~S~ize/move", cmResize, kbCtrlF5, hcNoContext, "Ctrl+F5" ) +
  182.         *new TMenuItem( "~Z~oom", cmZoom, kbF5, hcNoContext, "F5" ) +
  183.         *new TMenuItem( "~N~ext", cmNext, kbF6, hcNoContext, "F6" ) +
  184.         *new TMenuItem( "~P~revious", cmPrev, kbShiftF6, hcNoContext, "Shift+F6" ) +
  185.         *new TMenuItem( "~C~lose", cmClose, kbAltF3, hcNoContext, "Alt+F3" ) +
  186.          newLine() +
  187.         *new TMenuItem( "T~o~ggle screen size", cmScreenSize, kbNoKey) +
  188.         *new TMenuItem( "C~l~ose all tileable windows", cmCloseTileable, kbNoKey) +
  189.         *new TMenuItem( "~T~ile", cmTile, kbNoKey) +
  190.         *new TMenuItem( "C~a~scade", cmCascade, kbNoKey);
  191.  
  192.     return new TMenuBar( TRect(0, 0, 80, 1), MiscMenu + DemoMenu +
  193.         WindowMenu);
  194. }
  195.  
  196. TStatusLine *initStatusLine(void)
  197. {
  198.     return new TStatusLine( TRect(0, 24, 80, 25),
  199.       *new TStatusDef( 0, 0xFFFF ) +
  200.         *new TStatusItem( NULL, kbF10, cmMenu ) +
  201.         *new TStatusItem( "~Alt+X~ Exit", kbAltX, cmQuit ) +
  202.         *new TStatusItem( "~Alt+F3~ Close", kbAltF3, cmClose ) +
  203.         *new TStatusItem( "~F2~ Window", kbF2, cmDemo1 ) +
  204.         *new TStatusItem( "~F3~ Dialog", kbF3, cmDemo2 ) +
  205.         *new TStatusItem( "~F7~ Get Window", kbF7, cmDemo3 ) +
  206.         *new TStatusItem( "~F8~ Get Dialog", kbF8, cmDemo4 ));
  207. }
  208.  
  209. Boolean createDemo3Window(void)
  210. {
  211.     TExplodeWindow *xw = new TExplodeWindow(TRect(0,0,80,23),
  212.          "Resource File Exploding Window Demo", 0);
  213.  
  214.     if(!xw)
  215.         return False;
  216.  
  217.     xw->MakeItExplode(0);           // Explode it as fast as possible.
  218.     xw->options |= ofTileable;
  219.     xw->growMode = gfGrowAll | gfGrowRel;
  220.  
  221.     TRect r = xw->getExtent();
  222.     r.grow(-1, -1);
  223.  
  224.     TStaticText *s = new TStaticText(r, "This is a streamed test.");
  225.     s->growMode = gfGrowHiX | gfGrowHiY;
  226.     xw->insert(s);
  227.  
  228.     WriteObject(xw,  "Demo3");
  229.  
  230.     return True;        // Successful.
  231. }
  232.  
  233. TDialog *createDemo4Dialog(void)
  234. {
  235.     TExplodeDialog *xd = new TExplodeDialog(TRect(0,0,80,23),
  236.         "Resource File Exploding Dialog Box Demo");
  237.  
  238.     if(!xd)
  239.         return NULL;
  240.  
  241.     xd->options |= ofCentered;
  242.     xd->MakeItExplode(0);        // Make it explode as fast as possible.
  243.  
  244.     TRadioButtons *r = new TRadioButtons(TRect(3,2,26,21),
  245.       new TSItem("Radio Button #1",
  246.       new TSItem("Radio Button #2",
  247.       new TSItem("Radio Button #3",
  248.       new TSItem("Radio Button #4",
  249.       new TSItem("Radio Button #5",
  250.       new TSItem("Radio Button #6",
  251.       new TSItem("Radio Button #7",
  252.       new TSItem("Radio Button #8",
  253.       new TSItem("Radio Button #9",
  254.       new TSItem("Radio Button #10",
  255.       new TSItem("Radio Button #11",
  256.       new TSItem("Radio Button #12",
  257.       new TSItem("Radio Button #13",
  258.       new TSItem("Radio Button #14",
  259.       new TSItem("Radio Button #15",
  260.       new TSItem("Radio Button #16",
  261.       new TSItem("Radio Button #17",
  262.       new TSItem("Radio Button #18",
  263.       new TSItem("Radio Button #19", 0))))))))))))))))))));
  264.     xd->insert(r);
  265.     xd->insert(new TLabel(TRect(2,1,23,2), "~R~adio Buttons", r));
  266.  
  267.     TCheckBoxes *c = new TCheckBoxes(TRect(28,2,51,21),
  268.       new TSItem("Checkbox #1",
  269.       new TSItem("Checkbox #2",
  270.       new TSItem("Checkbox #3",
  271.       new TSItem("Checkbox #4",
  272.       new TSItem("Checkbox #5",
  273.       new TSItem("Checkbox #6",
  274.       new TSItem("Checkbox #7",
  275.       new TSItem("Checkbox #8",
  276.       new TSItem("Checkbox #9",
  277.       new TSItem("Checkbox #10",
  278.       new TSItem("Checkbox #11",
  279.       new TSItem("Checkbox #12",
  280.       new TSItem("Checkbox #13",
  281.       new TSItem("Checkbox #14",
  282.       new TSItem("Checkbox #15",
  283.       new TSItem("Checkbox #16",
  284.       new TSItem("Checkbox #17",
  285.       new TSItem("Checkbox #18",
  286.       new TSItem("Checkbox #19", 0))))))))))))))))))));
  287.     xd->insert(c);
  288.     xd->insert(new TLabel(TRect(27,1,48,2), "~C~heckboxes", c));
  289.  
  290.     c = new TCheckBoxes(TRect(53,3,77,9),
  291.         new TSItem("Test #1",
  292.         new TSItem("Test #2",
  293.         new TSItem("Test #3",
  294.         new TSItem("Test #4",
  295.         new TSItem("Test #5",
  296.         new TSItem("Test #6", 0)))))));
  297.     xd->insert(c);
  298.     xd->insert(new TLabel(TRect(52,2,72,3), "~M~ore checkboxes", c));
  299.  
  300.     TInputLine *i = new TInputLine(TRect(53,10,77,11), 50);
  301.     xd->insert(i);
  302.     xd->insert(new TLabel(TRect(52,9,63,10), "Input #~1~", i));
  303.  
  304.     i = new TInputLine(TRect(53,12,77,13), 50);
  305.     xd->insert(i);
  306.     xd->insert(new TLabel(TRect(52,11,63,12), "Input #~2~", i));
  307.  
  308.     i = new TInputLine(TRect(53,15,63,16), 50);
  309.     xd->insert(i);
  310.     xd->insert(new TLabel(TRect(52,14,63,15), "Input #~3~", i));
  311.  
  312.     i = new TInputLine(TRect(53,18,63,19), 50);
  313.     xd->insert(i);
  314.     xd->insert(new TLabel(TRect(52,17,63,18), "Input #~4~", i));
  315.  
  316.     i = new TInputLine(TRect(66,18,74,19), 50);
  317.     xd->insert(i);
  318.     xd->insert(new TLabel(TRect(65,17,74,18), "Input #~5~", i));
  319.  
  320.     TButton *btn = new TButton(TRect(53,20,63,22), "O~K~", cmOK, bfDefault);
  321.     xd->insert(btn);
  322.  
  323.     btn = new TButton(TRect(67,20,77,22), "Cancel", cmCancel, bfNormal);
  324.     xd->insert(btn);
  325.  
  326.     xd->selectNext(False);
  327.  
  328.     return xd;
  329. }
  330.