/**********************************************************************/
/*                  BWCIMALT.cpp by Bob Bourbonnais                   */
/*              released to the public domain 2/02/92                 */
/*          This program shows how to switch to different             */
/*            routines based on the button pressed using              */
/*              Dynamic Dispatched Virtual Tables, DDVT               */
/*      It also shows how to use pointers to BWCC check boxes         */
/*           to show the ON/OFF status of the check boxes             */
/**********************************************************************/
#include <owl.h>
#include <dialog.h>
#include "bwcc.h"                        // needed for BWCC
#include "bchkbox.h"                     // needed for BWCC checkboxs
#include "BWCIMALT.H"                    // equates for checkboxes

class TMyDialog : public TDialog
  {
  public:
    TBCheckBox *pcbRadar12, *pcbConfabulator12;  // pointers to check boxes

    TMyDialog(LPSTR lpDialogName)          // constructor calls
      : TDialog(NULL,lpDialogName)         // base class constructor
      {
      BWCCGetVersion();    // activate Borland Windows Custom Controls

      pcbRadar12 = new TBCheckBox(this,IDB_RADAR12,NULL);    //links up
      pcbConfabulator12 = new TBCheckBox(this,               //pointers
					 IDB_CONFABULATOR12, //to check boxes
					 NULL);              //That were made
      }                                                      //via the .RC

    virtual void HandleRadar12(RTMessage Msg)  // these DDVT toggles
      = [ID_FIRST + IDB_RADAR12];              // activate immediately
    virtual void HandleConfabulator12(RTMessage Msg) // like regular
      = [ID_FIRST + IDB_CONFABULATOR12];             // buttons

    virtual void DefChildProc(RTMessage Msg); // default button handler
  };

void TMyDialog::HandleRadar12(RTMessage)
  {
  if (pcbRadar12->GetCheck()==BF_CHECKED)           // find out the ON/OFF
    {                                               // status of the checkbox
						    // using a pointer to the
						    // checkbox
    MessageBeep(0);                                 // if we turned it on
    BWCCMessageBox(HWindow,"Radar Unit 12 Activated", // beep and display
			   "ACTIVATION!",MB_OK);      // message box
    }
  else                                              // if we turned it off
    {
    MessageBeep(0);                                 // beep and display a
    BWCCMessageBox(HWindow,"Radar Unit 12 OFF",     // different message
			   "SHUTDOWN!",MB_OK);
    }
  }

void TMyDialog::HandleConfabulator12(RTMessage)     // Same for second
  {                                                 // Item
  if (pcbConfabulator12->GetCheck()==BF_CHECKED)
    {
    MessageBeep(0);
    BWCCMessageBox(HWindow,"Confabulator on Unit 12 Activated",
			   "ACTIVATION!",MB_OK);
    }
  else
    {
    MessageBeep(0);
    BWCCMessageBox(HWindow,"Confabulator on Unit 12 OFF",
			   "SHUTDOWN!",MB_OK);
    }
  }

void TMyDialog::DefChildProc(RTMessage Msg)   // default button handler
  {
  MessageBeep(0);                             // make sound and display
  BWCCMessageBox(HWindow,"Not Implemented",   // a BWCC message box
		 "Feature",MB_OK);
  TDialog::DefChildProc(Msg);                 // pass messages along
  }                                           // to base class handler

class TDialog1App : public TApplication  // Application Class to contain
  {                                      // the application
  public:
    TDialog1App(LPSTR lpName, HANDLE hInstance,  // constructor calls the
		HANDLE hPrevInstance,            // base class constructor
		LPSTR lpCmdLine, int nCmdShow)
		:TApplication(lpName, hInstance,
			      hPrevInstance,
			      lpCmdLine, nCmdShow) {};

    virtual void InitMainWindow(); // overrides base class InitMainWindow
  };

void TDialog1App::InitMainWindow() // to initialize a dialog box
  {                                // as the main window
  MainWindow = new TMyDialog("MAINWINDOWDIALOG");
  }

int PASCAL WinMain(HANDLE hInstance,              // main entry point from
		   HANDLE hPrevInstance,          // windows to this program
		   LPSTR lpCmdLine , int nCmdShow)
  {
  TDialog1App Dialog1("Dialog Tester",hInstance,  // create instance of
		       hPrevInstance,             // the dialog application
		       lpCmdLine,nCmdShow);
  Dialog1.Run();                                  // run it
  return (Dialog1.Status);                        // exit
  }
/**********************************************************************/
