home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / LED / LED.CPP next >
Encoding:
C/C++ Source or Header  |  1991-11-10  |  3.5 KB  |  135 lines

  1. //
  2. // LED.CPP - LEDWindows Demo Program
  3. //
  4.  
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <math.h>
  8. #include <windows.h>
  9. #include <owl.h>
  10. #include <bwcc.h>
  11.  
  12. #include "ledwind.cpp"
  13.  
  14. class LEDDemo : public TApplication
  15. {
  16.  
  17. public:
  18.  
  19.   LEDDemo(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
  20.        LPSTR lpCmdLine, int nCmdShow)
  21.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow)  {};
  22.  
  23.   virtual void InitMainWindow();
  24.   virtual void InitInstance();
  25.   virtual void IdleAction();
  26.   LEDWindow *LargeLED;
  27.   LEDWindow *TimerLED;
  28.   LEDWindow *ClockLED;
  29.   LEDWindow *Clock2LED;
  30.  
  31. };
  32.  
  33. class LEDDemoWindow : public TWindow
  34. {
  35. public:
  36.   LEDDemoWindow(PTWindowsObject AParent, LPSTR ATitle);
  37.   virtual void GetWindowClass(WNDCLASS& AWndClass);
  38.   virtual void Paint(HDC PaintDC, PAINTSTRUCT&);
  39. };
  40.  
  41. LEDDemoWindow::LEDDemoWindow
  42. (PTWindowsObject AParent, LPSTR ATitle) :
  43.     TWindow(AParent, ATitle)
  44. {
  45.   Attr.X = 150;
  46.   Attr.Y = 150;
  47.   Attr.W = 250;
  48.   Attr.H = 195;
  49.   Attr.Style = WS_BORDER | WS_MINIMIZEBOX | WS_SYSMENU;
  50. }
  51.  
  52. void LEDDemoWindow::GetWindowClass(WNDCLASS& AWndClass)
  53. {
  54.   HBRUSH LtGreyBrush;
  55.  
  56.   TWindow::GetWindowClass(AWndClass);
  57.   LtGreyBrush = GetStockObject(LTGRAY_BRUSH);
  58.   AWndClass.hbrBackground = LtGreyBrush;
  59.   AWndClass.hIcon = LoadIcon(GetApplication()->hInstance,"LEDICON");
  60. }
  61.  
  62.  
  63. void LEDDemoWindow::Paint(HDC PaintDC, PAINTSTRUCT&)
  64. {
  65.   BOOL MadeDC;
  66.  
  67.   // Secure the device context
  68.   if ( PaintDC == 0 )
  69.   {
  70.     PaintDC = GetDC( HWindow );
  71.     MadeDC = TRUE;
  72.   }
  73.   else
  74.     MadeDC = FALSE;
  75.  
  76.   // Label the Demo LEDs
  77.   SetBkColor(PaintDC, RGB(192, 192, 192));
  78.   TextOut(PaintDC, 160, 20, "LONG Num.", 9);
  79.   TextOut(PaintDC, 70, 60, "Seconds Timer", 13);
  80.   TextOut(PaintDC, 135, 100, "Time of Day", 11);
  81.   TextOut(PaintDC, 135, 140, "Internal Clock", 14);
  82.  
  83.   if ( MadeDC )
  84.     ReleaseDC( HWindow, PaintDC );
  85.  
  86. }
  87.  
  88.  
  89. void LEDDemo::InitMainWindow()
  90. {
  91.   BWCCGetVersion();
  92.   MainWindow = new LEDDemoWindow(NULL,Name);
  93.   LargeLED = new LEDWindow(MainWindow, 15, 15, 10, TRUE, FALSE, 1234567890l);
  94.   TimerLED = new LEDWindow(MainWindow, 55, 15, 3, TRUE, FALSE, 0);
  95.   ClockLED = new LEDWindow(MainWindow, 95, 15, 0, TRUE, TRUE, time(NULL));
  96.   Clock2LED = new LEDWindow(MainWindow, 135, 15, 0, TRUE, TRUE, 3600);
  97. }
  98.  
  99. void LEDDemo::InitInstance()
  100. {
  101.   // Start TimerLED Timer (timer must be associated with an HWindow,
  102.   // which does not exist before InitInstance MakeWindow call).
  103.   TApplication::InitInstance();       // perform usual init stuff
  104.   TimerLED->StartTimer(1);           // Update TimerLED every second
  105.   ClockLED->StartTimer(1);        // Update ClockLED every second
  106. }
  107.  
  108. void LEDDemo::IdleAction()
  109. {
  110.   if(TimerLED->lLEDValue==20)        // 20 seconds after invoke
  111.   {
  112.     Clock2LED->StartTimer(1);        // Update Clock2LED every second
  113.     LargeLED->DisplayNumber(1111111111l);    // Change LargeLED value
  114.   }
  115.   if(TimerLED->lLEDValue==30)        // 30 seconds after invoke
  116.   {
  117.     LargeLED->DisplayNumber(987654321l);     // Change LargeLED value
  118.   }
  119.   if(TimerLED->lLEDValue==82)        // 82 seconds after invoke
  120.   {
  121.     TimerLED->StopTimer();        // Stop TimerLED at 061
  122.     TimerLED->DisplayNumber(1999);    // Move 1999 to TimerLED
  123.                     // (only 3 digits: 999 displayed)
  124.     Clock2LED->StopTimer();             // Stop Clock2LED at 01:01:01
  125.   }
  126. }
  127.  
  128. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  129.            LPSTR lpCmdLine, int nCmdShow)
  130. {
  131.   LEDDemo LEDApp("LED Demo", hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  132.   LEDApp.Run();
  133.   return LEDApp.Status;
  134. }
  135.