home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / thandl.zip / TDEMO.CPP < prev    next >
C/C++ Source or Header  |  1993-12-05  |  26KB  |  864 lines

  1. /*-----------------------------------------------------------------------*/
  2. /* filename -       tdemo.cpp                                            */
  3. /*                                                                       */
  4. /* function(s)                                                           */
  5. /*                  definitions for the TDemoDialog and TDemoApp         */
  6. /*                  classes                                              */
  7. /*                                                                       */
  8. /*                  Test module for the THandler class                   */
  9. /*                                                                       */
  10. /* author -         Michael "Mick" Newton                                */
  11. /*                                                                       */
  12. /*-----------------------------------------------------------------------*/
  13.  
  14. /*-----------------------------------------------------------------------*/
  15. /*                                                                       */
  16. /*    TDEMO.CPP                                                          */
  17. /*                                                                       */
  18. /*    THandler version 2.0                                               */
  19. /*    Copyright (C) 1992,1993 Comsoft Software                           */
  20. /*    All Rights Reserved.                                               */
  21. /*                                                                       */
  22. /*-----------------------------------------------------------------------*/
  23.  
  24. // Define Turbo Vision classes used ***************************************
  25.  
  26. #define Uses_TApplication
  27. #define Uses_TButton
  28. #define Uses_TCheckBoxes
  29. #define Uses_TCluster
  30. #define Uses_TCommandSet
  31. #define Uses_TDeskTop
  32. #define Uses_TDialog
  33. #define Uses_TDisplay
  34. #define Uses_TEvent
  35. #define Uses_TFrame
  36. #define Uses_TGroup
  37. #define Uses_TKeys
  38. #define Uses_TMenu
  39. #define Uses_TMenuBar
  40. #define Uses_TMenuItem
  41. #define Uses_TMouse
  42. #define Uses_TObject
  43. #define Uses_TPalette
  44. #define Uses_TPoint
  45. #define Uses_TProgram
  46. #define Uses_TRadioButtons
  47. #define Uses_TRect
  48. #define Uses_TScreen
  49. #define Uses_TStatusDef
  50. #define Uses_TStatusItem
  51. #define Uses_TStatusLine
  52. #define Uses_TStaticText
  53. #define Uses_TSItem
  54. #define Uses_TSubMenu
  55. #define Uses_TView
  56. #define Uses_TWindow
  57. #define Uses_MsgBox
  58. #define Uses_fpstream
  59. #define Uses_ipstream
  60. #define Uses_opstream
  61.  
  62. #include <tv.h>
  63.  
  64.  
  65.  
  66.  
  67.  
  68. // CRTL header files ******************************************************
  69.  
  70. #if !defined __STDLIB_H
  71. #include <stdlib.h>
  72. #endif
  73.  
  74. #if !defined __STDIO_H
  75. #include <stdio.h>
  76. #endif
  77.  
  78. #if !defined __CONIO_H
  79. #include <conio.h>
  80. #endif
  81.  
  82. #if !defined __STRING_H
  83. #include <string.h>
  84. #endif
  85.  
  86. #if !defined __STRSTREAM_H
  87. #include <strstrea.h>
  88. #endif
  89.  
  90. #if !defined __FSTREAM_H
  91. #include <fstream.h>
  92. #endif
  93.  
  94. #if !defined __IOMANIP_H
  95. #include <iomanip.h>
  96. #endif
  97.  
  98. #if !defined __DOS_H
  99. #include <dos.h>
  100. #endif
  101.  
  102. #if !defined __DIR_H
  103. #include <dir.h>
  104. #endif
  105.  
  106. #if !defined __ALLOC_H
  107. #include <alloc.h>
  108. #endif
  109.  
  110. #if !defined __BIOS_H
  111. #include <bios.h>
  112. #endif
  113.  
  114.  
  115.  
  116.  
  117.  
  118. // Non-CRTL header files **************************************************
  119.  
  120. #if !defined __TDEMO_HPP
  121. #include "tdemo.hpp"
  122. #endif
  123.  
  124. #if !defined __THANDLER_HPP
  125. #include "thandler.hpp"
  126. #endif
  127.  
  128.  
  129.  
  130.  
  131.  
  132. // External global variable references ************************************
  133.  
  134. extern TPoint shadowSize;
  135. extern unsigned _stklen = 8192;        // 8K stack
  136.  
  137. #if defined __OVERLAY__
  138. extern unsigned _ovrbuffer = 0x2000;
  139. #endif
  140.  
  141.  
  142.  
  143.  
  144.  
  145. // TMenuItem **************************************************************
  146.  
  147. TMenuItem& operator +(TMenuItem& item1, TMenuItem& item2)
  148. {
  149.    // For building the application menubar
  150.  
  151.    TMenuItem *p = &item1;
  152.  
  153.    while(p->next != NULL)
  154.       p = p->next;
  155.  
  156.    p->next = &item2;
  157.  
  158.    return item1;
  159. }
  160.  
  161.  
  162.  
  163.  
  164.  
  165. // TDemoDialog ************************************************************
  166.  
  167. TDemoDialog::TDemoDialog(const TRect& bounds, const char *aTitle) :
  168.              TDialog(bounds, aTitle),
  169.              TWindowInit(initFrame)
  170. {
  171. }
  172.  
  173.  
  174. void TDemoDialog::handleEvent(TEvent& event)
  175. {
  176.    TDialog::handleEvent(event);
  177.  
  178.    switch(event.what)
  179.       {
  180.       case evCommand:
  181.          switch(event.message.command)
  182.             {
  183.             case cmDriveA:        // Our commands
  184.             case cmDriveB:
  185.             case cmLPT1:
  186.             case cmLPT2:
  187.             case cmLPT3:
  188.             if((state & sfModal) != 0)
  189.                {
  190.                endModal(event.message.command);
  191.                clearEvent(event);
  192.                }
  193.             break;
  194.             }
  195.       break;
  196.       }
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203. // TDemoApp ***************************************************************
  204.  
  205. /* ┌───────────────────────────────────────────────────────────────────┐ */
  206. /* │ TDemoApp palette layout                                           │ */
  207. /* ╞═══════════════════════════════════════════════════════════════════╡ */
  208. /* │                                                                   │ */
  209. /* │ NOTE:                                                             │ */
  210. /* │ This demo program uses a larger than normal application palette   │ */
  211. /* │ to demonstrate THandlerDialog's extended palette.                 │ */
  212. /* │                                                                   │ */
  213. /* ╞═══════╤═══════╤═══════════════════════════════════════════════════╡ */
  214. /* │ Start │ End   │                                                   │ */
  215. /* │ index │ index │ Items                                             │ */
  216. /* ├───────┼───────┼───────────────────────────────────────────────────┤ */
  217. /* │       │ 1     │ Desktop background                                │ */
  218. /* │     2 │ 7     │ Menus                                             │ */
  219. /* │     8 │ 15    │ Windows (Blue)                                    │ */
  220. /* │    16 │ 23    │ Windows (Cyan)                                    │ */
  221. /* │    24 │ 31    │ Windows (Gray)                                    │ */
  222. /* │    32 │ 63    │ Dialogs                                           │ */
  223. /* │    64 │ 71    │ Help    (Not yet implemented)                     │ */
  224. /* │    72 │ 103   │ TErrorDialog                                      │ */
  225. /* └───────┴───────┴───────────────────────────────────────────────────┘ */
  226.  
  227. // Application color palette
  228. #define cpAppColor                            \
  229.    "\x13\x30\x38\x3F\x0E\x08\x0F\x48\x4E\x4E" \
  230.    "\x09\x1F\x4F\x4D\x4A\x4B\x70\x7F\x7E\x78" \
  231.    "\x71\x40\x00\x70\x7F\x7A\x13\x13\x70\x7F" \
  232.    "\x00\x78\x70\x7E\x0C\x0E\x70\x70\x7F\x7E" \
  233.    "\x17\x1E\x1F\x18\x1B\x78\x70\x7E\x7F\x03" \
  234.    "\x0C\x0A\x7B\x77\x0C\x0E\x03\x4F\x0E\x07" \
  235.    "\x0A\x00\x00\x37\x7F\x0E\x0D\x4F\x5F\x5F" \
  236.    "\x5E\x48\x4C\x4E\x4F\x78\x4F\x50\x03\x0E" \
  237.    "\x70\x74\x7A\x78\x7F\x40\x0C\x0E\x70\x7E" \
  238.    "\x4F\x7F\x0A\x2E\x0C\x7E\x5B\x4F\x58\x7F" \
  239.    "\x57\x47\x00"
  240.  
  241. // Application black and white palette
  242. #define cpAppBlackWhite                       \
  243.    "\x07\x70\x78\x7F\x0F\x08\x07\x07\x0F\x07" \
  244.    "\x70\x70\x07\x70\x00\x07\x0F\x07\x70\x70" \
  245.    "\x07\x70\x00\x70\x7F\x7F\x70\x07\x70\x07" \
  246.    "\x00\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F" \
  247.    "\x07\x0F\x0F\x78\x0F\x78\x07\x0F\x0F\x0F" \
  248.    "\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07" \
  249.    "\x07\x00\x00\x07\x70\x0F\x70\x0F\x70\x70" \
  250.    "\x7F\x78\x70\x7F\x7F\x08\x7F\x78\x7F\x0F" \
  251.    "\x07\x0F\x0F\x08\x0F\x78\x07\x0F\x07\x0F" \
  252.    "\x70\x07\x0F\x70\x70\x7F\x70\x0F\x78\x78" \
  253.    "\x07\x7F\x00"
  254.  
  255. // Application monochrome palette
  256. #define cpAppMonochrome                       \
  257.    "\x70\x07\x01\x0F\x70\x70\x01\x07\x0F\x07" \
  258.    "\x70\x70\x07\x70\x00\x07\x0F\x07\x70\x70" \
  259.    "\x07\x70\x00\x70\x70\x70\x07\x07\x70\x07" \
  260.    "\x00\x70\x70\x70\x07\x07\x70\x70\x70\x0F" \
  261.    "\x07\x07\x0F\x70\x0F\x70\x07\x0F\x0F\x07" \
  262.    "\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07" \
  263.    "\x07\x00\x00\x07\x0F\x07\x70\x70\x07\x0F" \
  264.    "\x70\x70\x70\x70\x07\x07\x70\x70\x70\x0F" \
  265.    "\x07\x07\x0F\x70\x0F\x70\x07\x0F\x0F\x07" \
  266.    "\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07" \
  267.    "\x07\x0F\x00"
  268.  
  269.  
  270. TDemoApp::TDemoApp() :
  271.           TProgInit(initStatusLine, initMenuBar, initDeskTop),
  272.           status(True)
  273. {
  274.    // Create the THandler object
  275.    // Use extended palette, sounds, and DOS handler
  276.    newHandler = new THandler("Error", True, True, True);
  277.  
  278.    // Check it's status, fail ctor if False
  279.    if(newHandler->status == False)
  280.       {
  281.       status = False;
  282.       return;
  283.       }
  284.  
  285.    // Initialize options dialog data structure
  286.    // TV handler active, use tones on error, use extended palette
  287.    optrec.use = ofUseSounds | ofExtPal | ofUseDosISR;
  288.  
  289.    // Get current video mode
  290.    switch(TDisplay::getCrtMode())
  291.       {
  292.       case TDisplay::smCO80:      // 25 lines color
  293.          optrec.video = 0;
  294.          break;
  295.       case TDisplay::smFont8x8:   // 43/50 lines color
  296.          optrec.video = 1;
  297.          break;
  298.       case TDisplay::smBW80:      // Black & white
  299.          optrec.video = 2;
  300.          break;
  301.       default:                    // Monochrome
  302.          optrec.video = 3;
  303.          break;
  304.       }
  305.  
  306.    // Redraw the application
  307.    setState(sfExposed, True);
  308.    redraw();
  309.  
  310.    // Display "about" dialog
  311.    TEvent event;
  312.    event.what = evCommand;
  313.    event.message.command = cmAbout;
  314.    putEvent(event);
  315.    clearEvent(event);
  316. }
  317.  
  318.  
  319. void TDemoApp::shutDown()
  320. {
  321.    // If Thandler is active, delete it
  322.    if(newHandler != NULL)
  323.       delete((THandler *) newHandler);
  324.  
  325.    newHandler = NULL;
  326.  
  327.    TProgram::shutDown();
  328. }
  329.  
  330.  
  331. Boolean TDemoApp::valid(ushort command)
  332. {
  333.    // Check status
  334.    if(command == cmValid && status == False)
  335.       return False;
  336.  
  337.    return TApplication::valid(command);
  338. }
  339.  
  340.  
  341. TDeskTop *TDemoApp::initDeskTop(TRect r)
  342. {
  343.    r.a.y++;
  344.    r.b.y--;
  345.  
  346.    // Stop application from drawing in default colors
  347.    TProgram::application->setState(sfExposed, False);
  348.  
  349.    return new TDeskTop(r);
  350. }
  351.  
  352.  
  353. TPalette& TDemoApp::getPalette() const
  354. {
  355.    static TPalette pal1(cpAppColor, sizeof(cpAppColor) - 1);
  356.    static TPalette pal2(cpAppBlackWhite, sizeof(cpAppBlackWhite) - 1);
  357.    static TPalette pal3(cpAppMonochrome, sizeof(cpAppMonochrome) - 1);
  358.    static TPalette *palettes[] = {&pal1, &pal2, &pal3};
  359.    return *(palettes[appPalette]);
  360. }
  361.  
  362.  
  363. TMenuBar *TDemoApp::initMenuBar(TRect r)
  364. {
  365.    r.b.y = r.a.y + 1;
  366.  
  367.    TMenuItem *sys;
  368.    sys = new TMenuItem("~\360~", kbAltSpace, new TMenu(
  369.       *new TMenuItem("~A~bout", cmAbout, kbAltA, hcNone)));
  370.  
  371.    TMenuItem *exit;
  372.    exit = new TMenuItem("E~x~it", cmQuit, kbAltX, hcNone, 0);
  373.  
  374.    TMenuItem *tests;
  375.    tests = new TMenuItem("~T~ests", cmTests, kbAltT, hcNone, 0);
  376.  
  377.    TMenuItem *opt;
  378.    opt = new TMenuItem("~O~ptions", cmOptions, kbAltO, hcNone, 0);
  379.  
  380.    TMenu *menu = new TMenu(*sys + *exit + *tests + *opt);
  381.  
  382.    TMenuBar *menubar = new TMenuBar(r, menu);
  383.  
  384.    return menubar;
  385. }
  386.  
  387.  
  388. TStatusLine *TDemoApp::initStatusLine(TRect r)
  389. {
  390.    r.a.y = r.b.y - 1;
  391.  
  392.    return new TStatusLine(r,
  393.       *new TStatusDef(0, 0xFFFF) +
  394.       *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  395.       *new TStatusItem("~F10~ Menu", kbF10, cmMenu));
  396. }
  397.  
  398.  
  399. void TDemoApp::handleEvent(TEvent& event)
  400. {
  401.    TApplication::handleEvent(event);
  402.  
  403.    if(event.what == evCommand)
  404.       {
  405.       switch(event.message.command)
  406.          {
  407.          case cmAbout:
  408.             about();
  409.             break;
  410.          case cmTests:
  411.             // Call testDevices() until user selects "Cancel"
  412.             while(testDevices() != cmCancel);
  413.             break;
  414.          case cmOptions:
  415.             options();
  416.             break;
  417.          default:
  418.             return;
  419.          }
  420.       clearEvent(event);
  421.       }
  422. }
  423.  
  424.  
  425. void TDemoApp::about()
  426. {
  427.    // Displays a dialog containing information about this program
  428.  
  429.    TDialog *dialog = new TDialog(TRect(14, 3, 66, 20), "About");
  430.  
  431.    if(dialog == NULL)
  432.       return;
  433.  
  434.    dialog->options |= ofCentered;
  435.  
  436.    TStaticText *t;
  437.    t = new TStaticText(TRect(21, 2, 30, 3), "TDEMO.EXE");
  438.    t->options |= ofCenterX;
  439.    dialog->insert(t);
  440.  
  441.    t = new TStaticText(TRect(9, 3, 43, 4),
  442.                        "Demonstrates the THandler hardware");
  443.    t->options |= ofCenterX;
  444.    dialog->insert(t);
  445.  
  446.    t = new TStaticText(TRect(12, 4, 40, 5),
  447.                        "error handler class library.");
  448.    t->options |= ofCenterX;
  449.    dialog->insert(t);
  450.  
  451.    char ver[32];
  452.    ostrstream os(ver, sizeof ver);
  453.  
  454.    os << "THandler shareware version "
  455.       << handlerVerStr
  456.       << ends;
  457.  
  458.    t = new TStaticText(TRect(11, 6, 41, 7), ver);
  459.    t->options |= ofCenterX;
  460.    dialog->insert(t);
  461.  
  462.    t = new TStaticText(TRect(6, 7, 46, 8),
  463.                        "(C) Copyright 1992,1993 Comsoft Software");
  464.    t->options |= ofCenterX;
  465.    dialog->insert(t);
  466.  
  467.    t = new TStaticText(TRect(16, 8, 36, 9), "All rights reserved.");
  468.    t->options |= ofCenterX;
  469.    dialog->insert(t);
  470.  
  471.    t = new TStaticText(TRect(1, 11, 51, 12),
  472.                        "\003Created by Michael Newton for"
  473.                        " Comsoft Software");
  474.    t->options |= ofFramed | ofCenterX;
  475.    dialog->insert(t);
  476.  
  477.    TButton *b;
  478.    b = new TButton(TRect(11, 14, 41, 16), "~O~k", cmOK, bfDefault);
  479.    b->options |= ofCenterX;
  480.    dialog->insert(b);
  481.  
  482.    if(validView(dialog))
  483.       {
  484.       deskTop->execView(dialog);
  485.       TObject::destroy((TDialog *) dialog);
  486.       }
  487. }
  488.  
  489.  
  490. void TDemoApp::options()
  491. {
  492.    // Executes a dialog which allows user to select program options
  493.  
  494.    TDialog *dialog;
  495.    dialog = new TDialog(TRect(17, 3, 63, 20), "Options");
  496.  
  497.    if(dialog == NULL)
  498.       return;
  499.  
  500.    dialog->options |= ofCentered;
  501.  
  502.    TStaticText *t;
  503.    t = new TStaticText(TRect(2, 2, 20, 3), "\003THandler options");
  504.    dialog->insert(t);
  505.  
  506.    t = new TStaticText(TRect(2, 9, 14, 10), "\003Video mode");
  507.    dialog->insert(t);
  508.  
  509.    TCheckBoxes *cb;
  510.    cb = new TCheckBoxes(TRect(2, 3, 44, 7),
  511.            new TSItem("~U~se sounds on errors",
  512.            new TSItem("Use ~e~xtended palette",
  513.            new TSItem("~S~uspend TV when accessing devices",
  514.            new TSItem("Use ~D~OS ISR when TV suspended", 0)))));
  515.    cb->options |= ofFramed | ofCenterX;
  516.    dialog->insert(cb);
  517.  
  518.    TRadioButtons *rb;
  519.    rb = new TRadioButtons(TRect(2, 10, 44, 12),
  520.            new TSItem("~2~5 lines color",
  521.            new TSItem("~4~3/50 lines color",
  522.            new TSItem("~B~lack & white",
  523.            new TSItem("~M~onochrome", 0)))));
  524.    rb->options |= ofFramed | ofCenterX;
  525.    dialog->insert(rb);
  526.  
  527.    TButton *b;
  528.    b = new TButton(TRect(4, 14, 22, 16), "~C~ancel", cmCancel, bfNormal);
  529.    dialog->insert(b);
  530.  
  531.    b = new TButton(TRect(24, 14, 42, 16), "~O~k", cmOK, bfDefault);
  532.    dialog->insert(b);
  533.  
  534.    dialog->selectNext(False);
  535.  
  536.    // Execute the dialog box
  537.    if(validView(dialog))
  538.       {
  539.       ushort oldmode = optrec.video;   // Save current video mode
  540.       dialog->setData(&optrec);        // Set dialog's data
  541.       ushort result = deskTop->execView(dialog);
  542.       if(result != cmCancel)
  543.          {
  544.          dialog->getData(&optrec);     // Get dialog's data
  545.          // Set THandler's sounds flag
  546.          newHandler->setSounds((optrec.use & ofUseSounds) ? True : False);
  547.          // Set THandler's extended palette flag
  548.          newHandler->setExtPalette((optrec.use & ofExtPal) ? True : False);
  549.          // Set THandler's DOS ISR flag
  550.          newHandler->setDOSHandler(
  551.             (optrec.use & ofUseDosISR) ? True : False);
  552.          // Set new video mode if user changed video radio buttons
  553.          if(optrec.video != oldmode)
  554.             {
  555.             ushort vidmode;
  556.             switch(optrec.video)
  557.                {
  558.                case 0:
  559.                   vidmode = TDisplay::smCO80;
  560.                   break;
  561.                case 1:
  562.                   vidmode = TDisplay::smFont8x8;
  563.                   break;
  564.                case 2:
  565.                   vidmode = TDisplay::smBW80;
  566.                   break;
  567.                default:
  568.                   vidmode = TDisplay::smMono;
  569.                   break;
  570.                }
  571.             if((vidmode & TDisplay::smFont8x8) != 0)
  572.                shadowSize.x = 1;
  573.             else
  574.                shadowSize.x = 2;
  575.             // Set the new video mode
  576.             setScreenMode(vidmode);
  577.             // Because of a bug in Turbo Vision's TScreen class we need
  578.             // to reset the mouse ranges if the new mode is 43/50 lines
  579.             // color
  580.             if((vidmode & TDisplay::smFont8x8) != 0)
  581.                TMouse::setRange(TDisplay::getCols() - 1,
  582.                                 TDisplay::getRows() - 1);
  583.             // Force the application to redraw
  584.             setState(sfExposed, False);
  585.             setState(sfExposed, True);
  586.             redraw();
  587.             }
  588.          }
  589.       TObject::destroy((TDialog *) dialog);
  590.       }
  591. }
  592.  
  593.  
  594. ushort TDemoApp::testDevices()
  595. {
  596.    // Displays a TDemoDialog which allows the user to select a hardware
  597.    // device to access. If "Suspend TV" was checked in the options dialog,
  598.    // THandler's suspend function will be called prior to accessing any
  599.    // device then THandler's resume function will be called
  600.  
  601.    TDemoDialog *dialog;
  602.    dialog = new TDemoDialog(TRect(13, 3, 67, 19),
  603.                             "Select a device to access");
  604.  
  605.    if(dialog == NULL)
  606.       return cmCancel;
  607.  
  608.    dialog->options |= ofCentered;
  609.  
  610.    // Frames around button groups
  611.    TView *box;
  612.    box = new TView(TRect(1, 1, 53, 6));
  613.    box->options |= ofFramed | ofCenterX;
  614.    dialog->insert(box);
  615.  
  616.    box = new TView(TRect(1, 7, 53, 12));
  617.    box->options |= ofFramed | ofCenterX;
  618.    dialog->insert(box);
  619.  
  620.    // Information text
  621.    TStaticText *t;
  622.    t = new TStaticText(TRect(4, 4, 50, 5),
  623.                        "Make sure there is no floppy disk in the drive");
  624.    t->options |= ofCenterX;
  625.    dialog->insert(t);
  626.  
  627.    t = new TStaticText(TRect(12, 5, 42, 6),
  628.                        "or the disk is write protected");
  629.    t->options |= ofCenterX;
  630.    dialog->insert(t);
  631.  
  632.    t = new TStaticText(TRect(7, 10, 47, 11),
  633.                        "Make sure the selected printer is either");
  634.    t->options |= ofCenterX;
  635.    dialog->insert(t);
  636.  
  637.    t = new TStaticText(TRect(12, 11, 41, 12),
  638.                        "turned off or is out of paper");
  639.    t->options |= ofCenterX;
  640.    dialog->insert(t);
  641.  
  642.    // Floppy drive buttons
  643.    TButton *b;
  644.    b = new TButton(TRect(4, 2, 26, 4), "Drive ~A~:", cmDriveA, bfNormal);
  645.    dialog->insert(b);
  646.  
  647.    b = new TButton(TRect(28, 2, 50, 4), "Drive ~B~:", cmDriveB, bfNormal);
  648.    dialog->insert(b);
  649.  
  650.    // Parallel printer buttons
  651.    b = new TButton(TRect(2, 8, 18, 10), "LPT ~1~", cmLPT1, bfNormal);
  652.    dialog->insert(b);
  653.  
  654.    b = new TButton(TRect(19, 8, 35, 10), "LPT ~2~", cmLPT2, bfNormal);
  655.    dialog->insert(b);
  656.  
  657.    b = new TButton(TRect(36, 8, 52, 10), "LPT ~3~", cmLPT3, bfNormal);
  658.    dialog->insert(b);
  659.  
  660.    // Done button
  661.    b = new TButton(TRect(12, 13, 42, 15), "~D~one", cmCancel, bfDefault);
  662.    b->options |= ofCenterX;
  663.    dialog->insert(b);
  664.  
  665.    // Get the number of parallel printers installed
  666.    int equip = biosequip();
  667.    int prncnt = (equip & 0xC000) >> 14;
  668.  
  669.    // Disable any printer selection buttons that aren't available
  670.    TCommandSet prncmds;
  671.  
  672.    if(prncnt < 3)
  673.       prncmds += cmLPT3;
  674.  
  675.    if(prncnt < 2)
  676.       prncmds += cmLPT2;
  677.  
  678.    if(prncnt < 1)
  679.       prncmds += cmLPT1;
  680.  
  681.    disableCommands(prncmds);
  682.  
  683.    fstream *f;
  684.    ushort result = cmCancel;
  685.  
  686.    // Execute the dialog
  687.    if(validView(dialog))
  688.       {
  689.       result = deskTop->execView(dialog);
  690.       if(result != cmCancel)
  691.          {
  692.          switch(result)
  693.             {
  694.             case cmDriveA:
  695.                if(optrec.use & ofSuspendTV)     // If ofSuspendTV set...
  696.                   {
  697.                   newHandler->suspend();        // call suspend
  698.                   if(optrec.use & ofUseDosISR)  // If ofUseDosISR set...
  699.                      displayMessage();          // display message
  700.                   }
  701.                // Access floppy drive A:
  702.                f = new fstream("a:\\nosuchf.ile", ios::in);
  703.                if(f != 0)
  704.                   delete((fstream *) f);
  705.                if(optrec.use & ofSuspendTV)     // If TV suspended...
  706.                   newHandler->resume();         // call resume
  707.                break;
  708.             case cmDriveB:
  709.                if(optrec.use & ofSuspendTV)     // If ofSuspendTV set...
  710.                   {
  711.                   newHandler->suspend();        // call suspend
  712.                   if(optrec.use & ofUseDosISR)  // If ofUseDosISR set...
  713.                      displayMessage();          // display message
  714.                   }
  715.                // Access floppy drive B:
  716.                f = new fstream("b:\\nosuchf.ile", ios::in);
  717.                if(f != 0)
  718.                   delete((fstream *) f);
  719.                if(optrec.use & ofSuspendTV)     // If TV suspended...
  720.                   newHandler->resume();         // call resume
  721.                break;
  722.             case cmLPT1:
  723.                if(optrec.use & ofSuspendTV)     // If ofSuspendTV set...
  724.                   {
  725.                   newHandler->suspend();        // call suspend
  726.                   if(optrec.use & ofUseDosISR)  // If ofUseDosISR set...
  727.                      displayMessage();          // display message
  728.                   }
  729.                // Access LPT1
  730.                ofstream lpt1;
  731.                lpt1.open("lpt1");
  732.                lpt1 << "This is a test of lpt1\n";
  733.                lpt1.close();
  734.                if(optrec.use & ofSuspendTV)     // If TV suspended...
  735.                   newHandler->resume();         // call resume
  736.                break;
  737.             case cmLPT2:
  738.                if(optrec.use & ofSuspendTV)     // If ofSuspendTV set...
  739.                   {
  740.                   newHandler->suspend();        // call suspend
  741.                   if(optrec.use & ofUseDosISR)  // If ofUseDosISR set...
  742.                      displayMessage();          // display message
  743.                   }
  744.                // Access LPT2
  745.                ofstream lpt2;
  746.                lpt2.open("lpt2");
  747.                lpt2 << "This is a test of lpt2\n";
  748.                lpt2.close();
  749.                if(optrec.use & ofSuspendTV)     // If TV suspended...
  750.                   newHandler->resume();         // call resume
  751.                break;
  752.             case cmLPT3:
  753.                if(optrec.use & ofSuspendTV)     // If ofSuspendTV set...
  754.                   {
  755.                   newHandler->suspend();        // call suspend
  756.                   if(optrec.use & ofUseDosISR)  // If ofUseDosISR set...
  757.                      displayMessage();          // display message
  758.                   }
  759.                // Access LPT3
  760.                ofstream lpt3;
  761.                lpt3.open("lpt3");
  762.                lpt3 << "This is a test of lpt3\n";
  763.                lpt3.close();
  764.                if(optrec.use & ofSuspendTV)     // If TV suspended...
  765.                   newHandler->resume();         // call resume
  766.                break;
  767.             }
  768.          }
  769.       TObject::destroy((TDemoDialog *) dialog);
  770.       }
  771.  
  772.    // Re-enable any disabled commands
  773.    enableCommands(prncmds);
  774.  
  775.    return(result);
  776. }
  777.  
  778.  
  779.  
  780.  
  781.  
  782. // Non-member functions ***************************************************
  783.  
  784. void displayMessage()
  785. {
  786.    char *msg[] =
  787.       {
  788.       "   This is a test of the THandler hardware error handler library. Thandler",
  789.       "is a replacement error handler class for Borland's Turbo Vision library.",
  790.       "When linked with your Turbo Vision applications and a hardware error occurs,",
  791.       "THandler displays a dialog containing information about the error and lets",
  792.       "the user select an appropriate action.",
  793.       "   At the moment Turbo Vision itself is suspended, so if an error were to",
  794.       "occur right now, Thandler would not be able to display it's normal error",
  795.       "dialog. Therefor, THandler actually has two hardware error handlers. One to",
  796.       "be used when Turbo Vision is active, and one for when Turbo Vision has been",
  797.       "suspended.",
  798.       "   I'm about to cause a hardware error while Turbo Vision is inactive. This",
  799.       "should cause THandler to display it's DOS error dialog. THandler's DOS error",
  800.       "dialog is slightly different from it's normal Turbo Vision dialog. It does",
  801.       "not have buttons for the user to select an action, rather it prompts the user",
  802.       "to press a key to select an action.",
  803.       " ",
  804.       "   Press any key now to generate the hardware error..."
  805.       };
  806.  
  807.    clrscr();
  808.  
  809.    cout << endl;
  810.  
  811.    for(short ctr = 0; ctr < 17; ctr++)
  812.       cout << msg[ctr] << endl;
  813.  
  814.    cout << endl;
  815.  
  816.    if(kbhit())
  817.       (void) getch();
  818.    (void) getch();
  819. }
  820.  
  821.  
  822. void exitfunc(void)
  823. {
  824.    // Prints an exit message
  825.  
  826.    cout << endl
  827.         << endl
  828.         << "┌────────────────────────────────────────────┐" << endl
  829.         << "│  Thank you for testing THandler!           │" << endl
  830.         << "├────────────────────────────────────────────┤" << endl
  831.         << "│  THandler shareware version "
  832.         << handlerVerStr
  833.         << "            │" << endl
  834.         << "│  Copyright (C) 1992,1993 Comsoft Software  │" << endl
  835.         << "│  All rights reserved.                      │" << endl
  836.         << "└────────────────────────────────────────────┘" << endl
  837.         << ends;
  838. }
  839.  
  840.  
  841.  
  842. #pragma exit exitfunc 31          // Register exitfunc
  843.  
  844.  
  845. int main()
  846. {
  847.    TDemoApp *program = new TDemoApp();
  848.  
  849.    if(!program->valid(cmValid))
  850.       {
  851.       TObject::destroy((TDemoApp *) program);
  852.       return 2;
  853.       }
  854.  
  855.    program->run();
  856.    TObject::destroy((TDemoApp *) program);
  857.  
  858.     return 0;
  859. }
  860.  
  861.  
  862. //                                End of TDEMO.CPP
  863.  
  864.