home *** CD-ROM | disk | FTP | other *** search
- //
- // LED.CPP - LEDWindows Demo Program
- //
-
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <windows.h>
- #include <owl.h>
- #include <bwcc.h>
-
- #include "ledwind.cpp"
-
- class LEDDemo : public TApplication
- {
-
- public:
-
- LEDDemo(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
-
- virtual void InitMainWindow();
- virtual void InitInstance();
- virtual void IdleAction();
- LEDWindow *LargeLED;
- LEDWindow *TimerLED;
- LEDWindow *ClockLED;
- LEDWindow *Clock2LED;
-
- };
-
- class LEDDemoWindow : public TWindow
- {
- public:
- LEDDemoWindow(PTWindowsObject AParent, LPSTR ATitle);
- virtual void GetWindowClass(WNDCLASS& AWndClass);
- virtual void Paint(HDC PaintDC, PAINTSTRUCT&);
- };
-
- LEDDemoWindow::LEDDemoWindow
- (PTWindowsObject AParent, LPSTR ATitle) :
- TWindow(AParent, ATitle)
- {
- Attr.X = 150;
- Attr.Y = 150;
- Attr.W = 250;
- Attr.H = 195;
- Attr.Style = WS_BORDER | WS_MINIMIZEBOX | WS_SYSMENU;
- }
-
- void LEDDemoWindow::GetWindowClass(WNDCLASS& AWndClass)
- {
- HBRUSH LtGreyBrush;
-
- TWindow::GetWindowClass(AWndClass);
- LtGreyBrush = GetStockObject(LTGRAY_BRUSH);
- AWndClass.hbrBackground = LtGreyBrush;
- AWndClass.hIcon = LoadIcon(GetApplication()->hInstance,"LEDICON");
- }
-
-
- void LEDDemoWindow::Paint(HDC PaintDC, PAINTSTRUCT&)
- {
- BOOL MadeDC;
-
- // Secure the device context
- if ( PaintDC == 0 )
- {
- PaintDC = GetDC( HWindow );
- MadeDC = TRUE;
- }
- else
- MadeDC = FALSE;
-
- // Label the Demo LEDs
- SetBkColor(PaintDC, RGB(192, 192, 192));
- TextOut(PaintDC, 160, 20, "LONG Num.", 9);
- TextOut(PaintDC, 70, 60, "Seconds Timer", 13);
- TextOut(PaintDC, 135, 100, "Time of Day", 11);
- TextOut(PaintDC, 135, 140, "Internal Clock", 14);
-
- if ( MadeDC )
- ReleaseDC( HWindow, PaintDC );
-
- }
-
-
- void LEDDemo::InitMainWindow()
- {
- BWCCGetVersion();
- MainWindow = new LEDDemoWindow(NULL,Name);
- LargeLED = new LEDWindow(MainWindow, 15, 15, 10, TRUE, FALSE, 1234567890l);
- TimerLED = new LEDWindow(MainWindow, 55, 15, 3, TRUE, FALSE, 0);
- ClockLED = new LEDWindow(MainWindow, 95, 15, 0, TRUE, TRUE, time(NULL));
- Clock2LED = new LEDWindow(MainWindow, 135, 15, 0, TRUE, TRUE, 3600);
- }
-
- void LEDDemo::InitInstance()
- {
- // Start TimerLED Timer (timer must be associated with an HWindow,
- // which does not exist before InitInstance MakeWindow call).
- TApplication::InitInstance(); // perform usual init stuff
- TimerLED->StartTimer(1); // Update TimerLED every second
- ClockLED->StartTimer(1); // Update ClockLED every second
- }
-
- void LEDDemo::IdleAction()
- {
- if(TimerLED->lLEDValue==20) // 20 seconds after invoke
- {
- Clock2LED->StartTimer(1); // Update Clock2LED every second
- LargeLED->DisplayNumber(1111111111l); // Change LargeLED value
- }
- if(TimerLED->lLEDValue==30) // 30 seconds after invoke
- {
- LargeLED->DisplayNumber(987654321l); // Change LargeLED value
- }
- if(TimerLED->lLEDValue==82) // 82 seconds after invoke
- {
- TimerLED->StopTimer(); // Stop TimerLED at 061
- TimerLED->DisplayNumber(1999); // Move 1999 to TimerLED
- // (only 3 digits: 999 displayed)
- Clock2LED->StopTimer(); // Stop Clock2LED at 01:01:01
- }
- }
-
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- LEDDemo LEDApp("LED Demo", hInstance, hPrevInstance, lpCmdLine, nCmdShow);
- LEDApp.Run();
- return LEDApp.Status;
- }
-