home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / gauge.pak / GAUGEX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  3.5 KB  |  155 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\framewin.h>
  7. #include <owl\slider.h>
  8. #include <owl\gauge.h>
  9. #include <owl\static.h>
  10. #include <owl\gdiobjec.h>
  11. #include <stdio.h>
  12.  
  13. const WORD ID_SLIDER = 201;
  14. const WORD ID_SOLIDGAUGE = 208;
  15. const WORD ID_LEDGAUGE = 209;
  16.  
  17.  
  18. class TTestWindow : public TWindow {
  19.   public:
  20.     TTestWindow();
  21.     
  22.   protected:
  23.     TSlider*  Slider;
  24.     TGauge*   SolidGauge;
  25.     TGauge*   LedGauge;
  26.     TBrush*   BkBrush;
  27.     
  28.     int       Setting;
  29.  
  30.     void    SetupWindow();
  31.  
  32.     void    UpdateGauges(UINT);
  33.     
  34.     BOOL    EvEraseBkgnd(HDC);
  35.     HBRUSH  EvCtlColor(HDC, HWND hWndChild, UINT ctlType);
  36.     void    EvSysColorChange();
  37.     void    EvTimer(UINT timerId);
  38.  
  39.   DECLARE_RESPONSE_TABLE(TTestWindow);
  40. };
  41.  
  42. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  43.   EV_WM_ERASEBKGND,
  44.   EV_WM_CTLCOLOR,
  45.   EV_WM_SYSCOLORCHANGE,
  46.   EV_CHILD_NOTIFY_ALL_CODES(ID_SLIDER, UpdateGauges),
  47. END_RESPONSE_TABLE;
  48.  
  49. TTestWindow::TTestWindow()
  50.   : TWindow(0, 0, 0)
  51. {
  52.   Attr.X = 20;
  53.   Attr.Y = 20;
  54.   Attr.W = 280;
  55.   Attr.H = 160;
  56.  
  57.   SolidGauge = new TGauge(this, "%d%%", ID_SOLIDGAUGE, 20, 20, 240, 34, TRUE, 2);
  58.   LedGauge = new TGauge(this, "", ID_LEDGAUGE, 20, 60, 240, 24, TRUE, 2);
  59.  
  60.   Slider = new THSlider(this, ID_SLIDER, 20, 110, 240, 40);
  61.  
  62.   BkBrush = new TBrush(::GetSysColor(COLOR_BTNFACE));
  63.  
  64.   Setting = 50;
  65. }
  66.  
  67. void
  68. TTestWindow::SetupWindow()
  69. {
  70.   TWindow::SetupWindow();
  71.  
  72.   Slider->SetRange(0, 100);
  73.   Slider->SetRuler(10, FALSE);
  74.   Slider->SetPosition(50);
  75.   
  76.   SolidGauge->SetRange(0, 100);
  77.   LedGauge->SetRange(0, 100);
  78.   LedGauge->SetLed(4, 80);
  79.   
  80.   UpdateGauges(0);
  81. }
  82.  
  83. void
  84. TTestWindow::UpdateGauges(UINT)
  85. {
  86.   Setting = Slider->GetPosition();
  87.   SolidGauge->SetValue(Setting);
  88.   LedGauge->SetValue(Setting);
  89. }
  90.  
  91. //
  92. // Paint a raised, grey, background
  93. //
  94. BOOL
  95. TTestWindow::EvEraseBkgnd(HDC hDC)
  96. {
  97.   TDC dc(hDC);
  98.  
  99.   // SysColors that are bkgnds for text are never dithered & can use TextRect
  100.   //
  101.   dc.TextRect(GetClientRect(), ::GetSysColor(COLOR_BTNFACE));
  102.  
  103.   // These sysColors might be dithered. PaBlt is an easy way to paint these
  104.   //
  105.   TBrush highlight(::GetSysColor(COLOR_BTNHIGHLIGHT));
  106.   dc.SelectObject(highlight);
  107.   dc.PatBlt(0, 0, Attr.W, 2);
  108.   dc.PatBlt(0, 2, 2, Attr.H-2);
  109.  
  110.   TBrush shadow(::GetSysColor(COLOR_BTNSHADOW));
  111.   dc.SelectObject(shadow);
  112.   dc.PatBlt(1, Attr.H-2, Attr.W-1, 2);
  113.   dc.PatBlt(Attr.W-2, 1, 2, Attr.H-2-1);  
  114.  
  115.   return TRUE;
  116. }
  117.  
  118. //
  119. // Provide a background color & brush for child controls to use
  120. //
  121. HBRUSH
  122. TTestWindow::EvCtlColor(HDC hDC, HWND /*hWndChild*/, UINT /*ctlType*/)
  123. {
  124.   ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
  125.   return *BkBrush;
  126. }
  127.  
  128. //
  129. // Colors have changed. Rebuild the background brush.
  130. //
  131. void
  132. TTestWindow::EvSysColorChange()
  133. {
  134.   delete BkBrush;
  135.   BkBrush = new TBrush(::GetSysColor(COLOR_BTNFACE));
  136. }
  137.  
  138. //----------------------------------------------------------------------------
  139.  
  140. class TTestApp : public TApplication {
  141.   public:
  142.     TTestApp() : TApplication() {}
  143.     void InitMainWindow() {
  144.       MainWindow = new TFrameWindow(0, "Gauge Display", new TTestWindow, TRUE);
  145.       MainWindow->EnableKBHandler();
  146.       MainWindow->Attr.Style &= ~WS_THICKFRAME;
  147.     }
  148. };
  149.  
  150. int
  151. OwlMain(int /*argc*/, char* /*argv*/ [])
  152. {
  153.   return TTestApp().Run();
  154. }
  155.