home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / applic.wxc < prev    next >
Encoding:
Text File  |  1996-08-23  |  7.7 KB  |  288 lines

  1. Save Format v1.3
  2. @begin ClassFile "ApplicationClass"
  3.  Exported 0;
  4.  
  5. @begin-code BaseClassList
  6.  
  7. public WExeApplication
  8.  
  9. @end-code;
  10.  
  11.  @begin UserFunction "ApplicationClass()"
  12.   Compiler 1;
  13.   GencodeFunction 1;
  14.   GencodeSrcLine 16;
  15.   FunctionName "ApplicationClass::ApplicationClass()";
  16.  @end;
  17.  
  18.  @begin UserFunction "~ApplicationClass()"
  19.   Compiler 1;
  20.   GencodeFunction 1;
  21.   GencodeSrcLine 33;
  22.   FunctionName "ApplicationClass::~ApplicationClass()";
  23.  @end;
  24.  
  25.  @begin UserFunction "__DefaultStartHandler( WObject *, WStartEventData *event )"
  26.   Compiler 1;
  27.   GencodeFunction 1;
  28.   GencodeSrcLine 36;
  29.   FunctionName "ApplicationClass::__DefaultStartHandler( WObject *, WStartEventData *event )";
  30.  @end;
  31.  
  32.  @begin UserFunction "__DefaultRunHandler( WObject *, WRunEventData *event )"
  33.   Compiler 1;
  34.   GencodeFunction 1;
  35.   GencodeSrcLine 49;
  36.   FunctionName "ApplicationClass::__DefaultRunHandler( WObject *, WRunEventData *event )";
  37.  @end;
  38.  
  39.  @begin UserFunction "__DefaultEndHandler( WObject *, WEndEventData *event )"
  40.   Compiler 1;
  41.   GencodeFunction 1;
  42.   GencodeSrcLine 54;
  43.   FunctionName "ApplicationClass::__DefaultEndHandler( WObject *, WEndEventData *event )";
  44.  @end;
  45.  
  46.  @begin UserFunction "StartHandler( WObject *, WStartEventData *event )"
  47.   Compiler 1;
  48.   GencodeSrcLine 63;
  49.   FunctionName "ApplicationClass::StartHandler( WObject *, WStartEventData *event )";
  50.  @end;
  51.  
  52.  @begin UserFunction "RunHandler( WObject *, WRunEventData *event )"
  53.   Compiler 1;
  54.   GencodeSrcLine 140;
  55.   FunctionName "ApplicationClass::RunHandler( WObject *, WRunEventData *event )";
  56.  @end;
  57.  
  58.  @begin UserFunction "EndHandler( WObject *, WEndEventData *event )"
  59.   Compiler 1;
  60.   GencodeSrcLine 144;
  61.   FunctionName "ApplicationClass::EndHandler( WObject *, WEndEventData *event )";
  62.  @end;
  63.  
  64.  @begin HPPPrefixBlock
  65. @begin-code HPPPrefix
  66.  
  67. class Form1;
  68.  
  69. @end-code;
  70.   GencodeSrcLine 11;
  71.  @end;
  72.  
  73.  @begin CPPPrefixBlock
  74. @begin-code CPPPrefix
  75.  
  76. // Code added here will be included at the top of the .CPP file
  77. #include "ODBCAdmin.hpp"
  78.  
  79. //  Include definitions for resources.
  80. #include "WRes.h"
  81.  
  82. @end-code;
  83.   GencodeSrcLine 11;
  84.  @end;
  85.  
  86.  @begin ClassContentsBlock
  87. @begin-code ClassContents
  88.  
  89.     public:
  90.         // add your public instance data here
  91.     private:
  92.         // add your private instance data here
  93.     protected:
  94.         // add your protected instance data here
  95.  
  96. @end-code;
  97.   GencodeSrcLine 24;
  98.  @end;
  99.  
  100. @begin-code GeneratedClassContents
  101.  
  102.         ApplicationClass();
  103.         ~ApplicationClass();
  104.         WBool __DefaultStartHandler( WObject *, WStartEventData *event );
  105.         WBool __DefaultRunHandler( WObject *, WRunEventData *event );
  106.         WBool __DefaultEndHandler( WObject *, WEndEventData *event );
  107.         WBool StartHandler( WObject *, WStartEventData *event );
  108.         WBool RunHandler( WObject *, WRunEventData *event );
  109.         WBool EndHandler( WObject *, WEndEventData *event );
  110.         WBool __DefaultStartHandler( WObject *, WStartEventData *event );
  111.         WBool __DefaultRunHandler( WObject *, WRunEventData *event );
  112.         WBool __DefaultEndHandler( WObject *, WEndEventData *event );
  113.  
  114. @end-code;
  115.  
  116. @begin-code Code "ApplicationClass::ApplicationClass()"
  117.  
  118. @@CLASSNAME@::@CLASSNAME@()
  119. {
  120.     SetEventHandler( WStartEvent, this,
  121.         (WEventHandler) __DefaultStartHandler );
  122.     SetEventHandler( WStartEvent, this,
  123.         (WEventHandler) StartHandler );
  124.  
  125.     SetEventHandler( WRunEvent, this,
  126.         (WEventHandler) __DefaultRunHandler );
  127.     SetEventHandler( WRunEvent, this,
  128.         (WEventHandler) RunHandler );
  129.  
  130.     SetEventHandler( WEndEvent, this,
  131.         (WEventHandler) __DefaultEndHandler );
  132.     SetEventHandler( WEndEvent, this,
  133.         (WEventHandler) EndHandler );
  134. }
  135.  
  136. @end-code;
  137.  
  138. @begin-code Code "ApplicationClass::~ApplicationClass()"
  139.  
  140. @@CLASSNAME@::~@CLASSNAME@()
  141. {
  142. }
  143.  
  144. @end-code;
  145.  
  146. @begin-code Code "ApplicationClass::__DefaultStartHandler( WObject *, WStartEventData *event )"
  147.  
  148. WBool @CLASSNAME@::__DefaultStartHandler( WObject *, WStartEventData *event )
  149. {
  150.     extern WForm *__MainForm;
  151.     class Form1;
  152.     extern WForm *_CreateForm1(void);
  153.  
  154.     __MainForm = _CreateForm1();
  155.     if( __MainForm == NULL ) {
  156.         event->abortRun = TRUE;
  157.         event->exitCode = -1;
  158.     }
  159.     return TRUE;
  160. }
  161.  
  162. @end-code;
  163.  
  164. @begin-code Code "ApplicationClass::__DefaultRunHandler( WObject *, WRunEventData *event )"
  165.  
  166. WBool @CLASSNAME@::__DefaultRunHandler( WObject *, WRunEventData *event )
  167. {
  168.     WCurrentThread::ProcessMessages();
  169.     return TRUE;
  170. }
  171.  
  172. @end-code;
  173.  
  174. @begin-code Code "ApplicationClass::__DefaultEndHandler( WObject *, WEndEventData *event )"
  175.  
  176. WBool @CLASSNAME@::__DefaultEndHandler( WObject *, WEndEventData *event )
  177. {
  178.     extern WForm *__MainForm;
  179.     extern void _DeleteForm1( WForm *);
  180.  
  181.     _DeleteForm1( __MainForm );
  182.     __MainForm = NULL;
  183.     return TRUE;
  184. }
  185.  
  186. @end-code;
  187.  
  188. @begin-code Code "ApplicationClass::StartHandler( WObject *, WStartEventData *event )"
  189.  
  190. static WChar Driver[] = WTEXT("Microsoft Access Driver (*.mdb)");
  191. static WChar Datasource[] = WTEXT("Microsoft Access 7.0 Sample");
  192. static WChar DBFile[] = WTEXT("Northwind.mdb");
  193.  
  194. static WChar* keyValues[] = {
  195.     WTEXT("DriverId"),WTEXT("25"),
  196.     WTEXT("FIL"),WTEXT("MS Access"),
  197.     WTEXT("UID"),WTEXT("admin"), 
  198.     NULL
  199. };
  200.     
  201.  
  202. WBool @CLASSNAME@::StartHandler( WObject *, WStartEventData *event )
  203. {
  204.  
  205.     WString             driver_dll;
  206.     WStringArray        keys;
  207.     WString             db_file;
  208.     WFilePath           path;
  209.     WString             dir;
  210.     WString             pathKey;
  211.     
  212.     WRegistryKey        regKey; 
  213.     WInt                i;
  214.  
  215.     //
  216.     // So that the user can go into the Sample and read the programming tips.
  217.     //
  218.     event->abortRun = FALSE;    
  219.     
  220.     if( !ODBCAdmin::DriverExists( Driver, driver_dll ) ) {
  221.         WMessageBox::Messagef( NULL, WMBLevelError, WMBButtonOk, "Driver Error",
  222.                 "The ODBC Driver '%s' is not installed. Data source cannot "\
  223.                 "be created.  "\
  224.                 "Please read the programming tips in this sample on instructions to install the driver",
  225.                  Driver );
  226.         return FALSE;
  227.     }
  228.  
  229.     for ( i=0; keyValues[i]; i++ );
  230.     keys.SetCount(i+4);
  231.     for ( i=0; keyValues[i]; i++ ) {
  232.         keys[i] = keyValues[i];
  233.     }
  234.     keys[i] = WTEXT( "Driver" );
  235.     keys[i+1] = driver_dll;
  236.     keys[i+2] = WTEXT( "DBQ" );
  237.    
  238.     pathKey = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\MSACCESS.EXE";
  239.     if ( regKey.Open( WRKeyLocalMachine, pathKey ) ) {
  240.          path = regKey.GetStringValue("Path");
  241.          path += "Samples\\";
  242.          regKey.Close();
  243.     } else {
  244.         return FALSE;
  245.     }
  246.     
  247.     path.SetFileName( DBFile );
  248.     if( !path.Exists() ) {
  249.         WMessageBox::Messagef(NULL, WMBLevelError, WMBButtonOk, "Data source Error",
  250.                 "The data file '%s' could not be found", path.GetText() );
  251.                         
  252.         return( FALSE );
  253.     }
  254.     keys[i+3] = path;
  255.  
  256.     if( !ODBCAdmin::AddDataSource( Datasource, Driver, keys ) ) {
  257.         WMessageBox::Messagef( NULL, WMBLevelError, WMBButtonOk, "Data source Error",
  258.                 "The ODBC Datasource '%s' could not be installed", Datasource );
  259.         return( FALSE );
  260.     }
  261.  
  262.  
  263.  
  264.     event->exitCode = 0;
  265.     return FALSE;
  266. }
  267.  
  268. @end-code;
  269.  
  270. @begin-code Code "ApplicationClass::RunHandler( WObject *, WRunEventData *event )"
  271.  
  272. WBool @CLASSNAME@::RunHandler( WObject *, WRunEventData *event )
  273. {
  274.     return FALSE;
  275. }
  276.  
  277. @end-code;
  278.  
  279. @begin-code Code "ApplicationClass::EndHandler( WObject *, WEndEventData *event )"
  280.  
  281. WBool @CLASSNAME@::EndHandler( WObject *, WEndEventData *event )
  282. {
  283.     return FALSE;
  284. }
  285.  
  286. @end-code;
  287. @end;
  288.