home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <windows.h>
- #include <owl\applicat.h>
- #include <owl\button.h>
- #include <owl\framewin.h>
- #include <owl\scrollba.h>
- #include <owl\static.h>
- #include <owl\window.h>
- #include <owl\window.rh>
-
- #include "countdn.h"
-
- class TMyWindow : public TWindow
- {
- public:
- TMyWindow(TWindow *parent = 0);
-
- protected:
- virtual void SetupWindow();
-
- void EvTimerBar(UINT code);
- void CbStart();
- void CbExit();
-
- private:
- TScrollBar *timerbar;
- TStatic *status;
-
- DECLARE_RESPONSE_TABLE(TMyWindow);
- };
- DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)
- EV_CHILD_NOTIFY_ALL_CODES(IDSC_TIMER, EvTimerBar),
- EV_BN_CLICKED(IDB_START, CbStart),
- EV_BN_CLICKED(IDB_EXIT, CbExit),
- END_RESPONSE_TABLE;
-
- TMyWindow::TMyWindow(TWindow *parent)
- {
- Init(parent, 0, 0);
-
- TStatic *st = new TStatic(this, -1, "Countdown: ",
- 50, 50, 150, 30);
- if (st)
- {
- st->Attr.Style &= ~SS_LEFT;
- st->Attr.Style |= SS_RIGHT;
- }
- status = new TStatic(this, IDS_STATUS, "", 200, 50, 100, 30);
- new TButton(this, IDB_START, "Start", 50, 135, 60, 40);
- new TButton(this, IDB_EXIT, "Exit", 130, 135, 60, 40);
- timerbar = new TScrollBar(this, IDSC_TIMER,
- 300, 100, 0, 150, FALSE);
- new TStatic(this, -1, "0", 330, 100, 80, 20);
- new TStatic(this, -1, "60", 330, 230, 80, 20);
- }
-
- void TMyWindow::SetupWindow()
- {
- TWindow::SetupWindow(); // Initialize the visual element
-
- if (timerbar)
- {
- timerbar->SetRange(0, 60);
- timerbar->SetPosition(15);
- EvTimerBar(SB_THUMBPOSITION);
- }
- }
-
- void TMyWindow::EvTimerBar(UINT /*code*/)
- {
- if (status)
- {
- char text[25];
- sprintf(text, "%d", timerbar ? timerbar->GetPosition() : 0);
- status->SetText(text);
- }
- }
-
- void DelaySecs(DWORD dwSecs)
- {
- DWORD dwTime = GetTickCount() + (dwSecs * 1000L);
- while (GetTickCount() < dwTime)
- /* Just wait a while. */;
- }
-
- void TMyWindow::CbStart()
- {
- if (timerbar)
- {
- // First, let the user know that we're stopping the
- // system for a time.
- //
- ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
-
- int start = timerbar->GetPosition();
- for (int ix = start - 1; ix >= 0; --ix)
- {
- timerbar->SetPosition(ix);
- EvTimerBar(SB_THUMBPOSITION);
- DelaySecs(1);
- }
- timerbar->SetPosition(start);
- EvTimerBar(SB_THUMBPOSITION);
- }
- }
-
- void TMyWindow::CbExit()
- {
- SendMessage(WM_CLOSE);
- }
-
- class TCountDownApp : public TApplication
- {
- public:
- TCountDownApp() : TApplication()
- { nCmdShow = SW_SHOWMAXIMIZED; }
-
- void InitMainWindow()
- {
- SetMainWindow(new TFrameWindow( 0,
- "Count Down Timer",
- new TMyWindow ));
- }
- };
-
- int OwlMain(int, char *[])
- {
- return TCountDownApp().Run();
- }
-