home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / GAUGE.PAK / GAUGEX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.8 KB  |  117 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   10.3  $
  6. //----------------------------------------------------------------------------
  7. #include <owl/pch.h>
  8. #include <owl/applicat.h>
  9. #include <owl/framewin.h>
  10. #include <owl/slider.h>
  11. #include <owl/gauge.h>
  12. #include <owl/static.h>
  13. #include <owl/uihelper.h>
  14. #include <owl/gdiobjec.h>
  15. #include <stdio.h>
  16.  
  17. const uint16 IDC_SLIDER     = 201;
  18. const uint16 IDC_SOLIDGAUGE = 208;
  19. const uint16 IDC_LEDGAUGE   = 209;
  20.  
  21. //
  22. // class TTestWindow
  23. // ~~~~~ ~~~~~~~~~~~
  24. class TTestWindow : public TWindow {
  25.   public:
  26.     TTestWindow();
  27.  
  28.   protected:
  29.     TSlider*  Slider;
  30.     TGauge*   SolidGauge;
  31.     TGauge*   LedGauge;
  32.  
  33.     void      SetupWindow();
  34.     void      UpdateGauges(uint);
  35.  
  36.   DECLARE_RESPONSE_TABLE(TTestWindow);
  37. };
  38.  
  39. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  40.   EV_CHILD_NOTIFY_ALL_CODES(IDC_SLIDER, UpdateGauges),
  41. END_RESPONSE_TABLE;
  42.  
  43. //
  44. //
  45. //
  46. TTestWindow::TTestWindow() : TWindow(0, 0, 0)
  47. {
  48.   Attr.X = 20;
  49.   Attr.Y = 20;
  50.   Attr.W = 280;
  51.   Attr.H = 160;
  52.   Attr.Style |= WS_CLIPCHILDREN;
  53.   Attr.ExStyle |= WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW;
  54.  
  55.   SolidGauge = new TGauge(this, "%d%%", IDC_SOLIDGAUGE, 20, 20, 240, 34, true);
  56.   SolidGauge->SetRange(0, 100);
  57.   SolidGauge->SetNativeUse(nuNever);
  58.  
  59.   LedGauge = new TGauge(this, IDC_LEDGAUGE, 20, 60, 240, 40 /*24*/);
  60.   LedGauge->SetRange(0, 100);
  61.   LedGauge->SetLed(4, 80);
  62.   LedGauge->SetStep(8);
  63.  
  64.   // Construct & set initial settings for slider. The settings can be changed
  65.   // before or after the window is created
  66.   //
  67.   Slider = new THSlider(this, IDC_SLIDER, 20, 110, 240, 40);
  68.   Slider->SetRange(0, 100);
  69.   Slider->SetRuler(10, false);
  70.   Slider->SetPosition(50);
  71.  
  72.   SetBkgndColor(TColor::Sys3dFace);
  73. }
  74.  
  75. //
  76. // Use this oportunity to make sure that the gauges positions are sync'd with
  77. // the slider position
  78. //
  79. void
  80. TTestWindow::SetupWindow()
  81. {
  82.   TWindow::SetupWindow();
  83.   UpdateGauges(0);
  84. }
  85.  
  86. //
  87. // Retrieve the slider position & use it to position the gauges
  88. //
  89. void
  90. TTestWindow::UpdateGauges(uint)
  91. {
  92.   int setting = Slider->GetPosition();
  93.   SolidGauge->SetValue(setting);
  94.   LedGauge->SetValue(setting);
  95. }
  96.  
  97. //
  98. // class TTestApp
  99. // ~~~~~ ~~~~~~~~
  100. class TTestApp : public TApplication {
  101.   public:
  102.     TTestApp() : TApplication() {}
  103.     void InitMainWindow() {
  104.       TFrameWindow* frame = new TFrameWindow(0, "Gauge Display",
  105.                                              new TTestWindow, true);
  106.       frame->EnableKBHandler();
  107.       frame->Attr.Style &= ~(WS_THICKFRAME|WS_MAXIMIZEBOX);
  108.       SetMainWindow(frame);
  109.     }
  110. };
  111.  
  112. int
  113. OwlMain(int /*argc*/, char* /*argv*/ [])
  114. {
  115.   return TTestApp().Run();
  116. }
  117.