home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 21.ddi / VBXCTL.PAK / VBXCTLX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.3 KB  |  130 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\dialog.h>
  7. #include <owl\framewin.h>
  8. #include <owl\vbxctl.h>
  9. #include "vbxctlx.h"
  10.  
  11. class TTestDialog : public TDialog, public TVbxEventHandler {
  12.   public:
  13.     TTestDialog(TWindow* parent, const char* name);
  14.  
  15.   protected:
  16.     void SetupWindow();
  17.  
  18.     // OWL Aliases for VBX controls in dialog
  19.     //
  20.     TVbxControl* Switch1;
  21.     TVbxControl* Switch2;
  22.     TVbxControl* Switch3;
  23.     TVbxControl* Switch4;
  24.     TVbxControl* Gauge1;
  25.     TVbxControl* Gauge2;
  26.     TVbxControl* Gauge3;
  27.     TVbxControl* Gauge4;
  28.  
  29.     void EvTimer(UINT timerId);
  30.     void EvDropSrc(VBXEVENT far* event);
  31.     void EvDropDest(VBXEVENT far* event);
  32.     void UpdateGauge(TVbxControl* sw, TVbxControl* ga);
  33.  
  34.   DECLARE_RESPONSE_TABLE(TTestDialog);
  35. };
  36.  
  37. DEFINE_RESPONSE_TABLE2(TTestDialog, TDialog, TVbxEventHandler)
  38.   EV_WM_TIMER,
  39.   EV_VBXEVENTNAME(IDC_BIPICT1,"DragDrop",EvDropSrc),
  40.   EV_VBXEVENTNAME(IDC_BIPICT2,"DragDrop",EvDropSrc),
  41.   EV_VBXEVENTNAME(IDC_BIPICT3,"DragDrop",EvDropDest),
  42. END_RESPONSE_TABLE;
  43.  
  44. TTestDialog::TTestDialog(TWindow* parent, const char* name)
  45.   : TDialog(parent, name), TWindow(parent)
  46. {
  47.   Switch1 = new TVbxControl(this, IDC_BISWITCH1);
  48.   Switch2 = new TVbxControl(this, IDC_BISWITCH2);
  49.   Switch3 = new TVbxControl(this, IDC_BISWITCH3);
  50.   Switch4 = new TVbxControl(this, IDC_BISWITCH4);
  51.   Gauge1  = new TVbxControl(this, IDC_BIGAUGE1);
  52.   Gauge2  = new TVbxControl(this, IDC_BIGAUGE2);
  53.   Gauge3  = new TVbxControl(this, IDC_BIGAUGE3);
  54.   Gauge4  = new TVbxControl(this, IDC_BIGAUGE4);
  55. }
  56.  
  57. void
  58. TTestDialog::SetupWindow()
  59. {
  60.   TDialog::SetupWindow();
  61.   SetTimer(1, 1);  // As fast as possible
  62. }
  63.  
  64. void
  65. TTestDialog::EvTimer(UINT /*timerId*/)
  66. {
  67.   UpdateGauge(Switch1, Gauge1);
  68.   UpdateGauge(Switch2, Gauge2);
  69.   UpdateGauge(Switch3, Gauge3);
  70.   UpdateGauge(Switch4, Gauge4);
  71. }
  72.  
  73. void
  74. TTestDialog::UpdateGauge(TVbxControl *sw, TVbxControl* ga)
  75. {
  76.   BOOL on=FALSE;
  77.   int val=0;
  78.   if( sw->GetProp("On", on) && on )
  79.     if( ga->GetProp("Value", val) )
  80.       ga->SetProp("Value",  (val + 5)  % 100);
  81. }
  82.  
  83. void
  84. TTestDialog::EvDropSrc(VBXEVENT far * /*event*/)
  85. {
  86.   MessageBeep(0);
  87. }
  88.  
  89. void
  90. TTestDialog::EvDropDest(VBXEVENT far * event)
  91. {
  92.   long pic;
  93.   if (VBXGetPropByName(VBX_EVENTARGNUM(event,HCTL,0), "Picture", &pic))
  94.     VBXSetPropByName(event->Control, "Picture", pic);
  95. }
  96.  
  97. //----------------------------------------------------------------------------
  98.  
  99. class TTestApp : public TApplication {
  100.   public:
  101.     TTestApp() : TApplication() {}
  102.  
  103.   protected:
  104.     void InitMainWindow() {
  105.       MainWindow = new TFrameWindow(0, "Dialog Tester", 0);
  106.       MainWindow->AssignMenu("COMMANDS");
  107.     }
  108.     void CmTest() {TTestDialog(MainWindow, "SAMPLES").Execute();}
  109.  
  110.   DECLARE_RESPONSE_TABLE(TTestApp);
  111. };
  112.  
  113. DEFINE_RESPONSE_TABLE(TTestApp)
  114.   EV_COMMAND(CM_TEST, CmTest),
  115. END_RESPONSE_TABLE;
  116.  
  117. int
  118. OwlMain(int, char**)
  119. {
  120. #if defined(__WIN32__)
  121.   ::MessageBox(0, "This is not a 32 bit example", "OWL Examples", MB_OK);
  122.   return 0;
  123.  
  124. #else
  125.   TBIVbxLibrary vbxLib;     // constructing this loads & inits the library
  126.   return TTestApp().Run();
  127.  
  128. #endif
  129. }
  130.