home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / VBXCTL.PAK / VBXCTLX.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.1 KB  |  192 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/dialog.h>
  8. #include <owl/framewin.h>
  9. #if defined(BI_PLAT_WIN32)
  10. #define _HSZ_DEFINED
  11. #endif
  12. #include <owl/vbxctl.h>
  13. #include "vbxctl.h"
  14.  
  15. //#define USE_RESOURCE_DLL
  16.  
  17. //
  18. // class TTestDialog
  19. // ~~~~~ ~~~~~~~~~~~
  20. class TTestDialog : public TDialog, public TVbxEventHandler {
  21.   public:
  22.     TTestDialog(TWindow* parent, const char* name, TModule* module=0);
  23.  
  24.   protected:
  25.     void SetupWindow();
  26.  
  27.     // OWL Aliases for VBX controls in dialog
  28.     //
  29.     TVbxControl* Switch1;
  30.     TVbxControl* Switch2;
  31.     TVbxControl* Switch3;
  32.     TVbxControl* Switch4;
  33.     TVbxControl* Gauge1;
  34.     TVbxControl* Gauge2;
  35.     TVbxControl* Gauge3;
  36.     TVbxControl* Gauge4;
  37.  
  38.     void EvTimer(uint timerId);
  39.     void EvDropSrc(VBXEVENT far* event);
  40.     void EvDropDest(VBXEVENT far* event);
  41.     void UpdateGauge(TVbxControl* sw, TVbxControl* ga);
  42.  
  43.   DECLARE_RESPONSE_TABLE(TTestDialog);
  44. };
  45.  
  46. DEFINE_RESPONSE_TABLE2(TTestDialog, TDialog, TVbxEventHandler)
  47.   EV_WM_TIMER,
  48.   EV_VBXEVENTNAME(IDC_BIPICT1,"DragDrop",EvDropSrc),
  49.   EV_VBXEVENTNAME(IDC_BIPICT2,"DragDrop",EvDropSrc),
  50.   EV_VBXEVENTNAME(IDC_BIPICT3,"DragDrop",EvDropDest),
  51. END_RESPONSE_TABLE;
  52.  
  53. //
  54. //
  55. //
  56. TTestDialog::TTestDialog(TWindow* parent, const char* name, TModule* module)
  57. :
  58.   TDialog(parent, name, module)
  59. {
  60.   Switch1 = new TVbxControl(this, IDC_BISWITCH1);
  61.   Switch2 = new TVbxControl(this, IDC_BISWITCH2);
  62.   Switch3 = new TVbxControl(this, IDC_BISWITCH3);
  63.   Switch4 = new TVbxControl(this, IDC_BISWITCH4);
  64.   Gauge1  = new TVbxControl(this, IDC_BIGAUGE1);
  65.   Gauge2  = new TVbxControl(this, IDC_BIGAUGE2);
  66.   Gauge3  = new TVbxControl(this, IDC_BIGAUGE3);
  67.   Gauge4  = new TVbxControl(this, IDC_BIGAUGE4);
  68. }
  69.  
  70. //
  71. //
  72. //
  73. void
  74. TTestDialog::SetupWindow()
  75. {
  76.   TDialog::SetupWindow();
  77.   SetTimer(1, 1);  // As fast as possible
  78. }
  79.  
  80. //
  81. //
  82. //
  83. void
  84. TTestDialog::EvTimer(uint /*timerId*/)
  85. {
  86.   UpdateGauge(Switch1, Gauge1);
  87.   UpdateGauge(Switch2, Gauge2);
  88.   UpdateGauge(Switch3, Gauge3);
  89.   UpdateGauge(Switch4, Gauge4);
  90. }
  91.  
  92. //
  93. //
  94. //
  95. void
  96. TTestDialog::UpdateGauge(TVbxControl* sw, TVbxControl* ga)
  97. {
  98.   int on = false;
  99.   if (sw->GetProp("On", on) && on) {
  100.     int val = 0;
  101.     if (ga->GetProp("Value", val))
  102.       ga->SetProp("Value",  (val + 5) % 100);
  103.   }
  104. }
  105.  
  106.  
  107. //
  108. //
  109. //
  110. void
  111. TTestDialog::EvDropSrc(VBXEVENT far* /*event*/)
  112. {
  113.   MessageBeep(0);
  114. }
  115.  
  116.  
  117. //
  118. //
  119. //
  120. void
  121. TTestDialog::EvDropDest(VBXEVENT far* event)
  122. {
  123.   long pic;
  124.   if (VBXGetPropByName(VBX_EVENTARGNUM(event,HCTL,0), "Picture", &pic))
  125.     VBXSetPropByName(event->Control, "Picture", pic);
  126. }
  127.  
  128. //----------------------------------------------------------------------------
  129.  
  130. //
  131. // class TTestApp
  132. // ~~~~~ ~~~~~~~~
  133. class TTestApp : public TApplication {
  134.   public:
  135.     TTestApp()
  136.     :
  137.       TApplication()
  138.     {
  139.     }
  140.  
  141.    ~TTestApp()
  142.     {
  143.       delete ResModule;
  144.     }
  145.  
  146.   protected:
  147.     void InitMainWindow()
  148.     {
  149.       MainWindow = new TFrameWindow(0, "Dialog Tester", 0);
  150.       MainWindow->AssignMenu(IDM_COMMANDS);
  151. #if defined(USE_RESOURCE_DLL)
  152.       ResModule = new TModule("resource.dll");
  153. # if 1
  154.       VBXEnableDLL(*this, *ResModule);
  155. # else
  156.       WNDCLASS wc;
  157.       GetClassInfo("VBCONTROL", &wc);
  158.       wc.hInstance = *ResModule;
  159.       RegisterClass(&wc);
  160. # endif
  161. #else
  162.       ResModule = 0;
  163. #endif
  164.     }
  165.     void CmTest() {TTestDialog(MainWindow, "SAMPLES", ResModule).Execute();}
  166.  
  167.   private:
  168.     TModule* ResModule;
  169.  
  170.   DECLARE_RESPONSE_TABLE(TTestApp);
  171. };
  172.  
  173. DEFINE_RESPONSE_TABLE(TTestApp)
  174.   EV_COMMAND(CM_TEST, CmTest),
  175. END_RESPONSE_TABLE;
  176.  
  177. //
  178. //
  179. //
  180. int
  181. OwlMain(int, char**)
  182. {
  183.   try {
  184.     TBIVbxLibrary vbxLib;     // constructing this loads & inits the library
  185.     return TTestApp().Run();
  186.   }
  187.   catch (xmsg& x) {
  188.     ::MessageBox(0, x.why().c_str(), "OWL Examples", MB_OK);
  189.     return -1;
  190.   }
  191. }
  192.