home *** CD-ROM | disk | FTP | other *** search
- // mmwabout.cpp ABOUT BOX WITH TIMER
-
- #define Uses_TKeys
- #define Uses_TMenuBar
- #define Uses_TSubMenu
- #define Uses_TMenuItem
- #define Uses_TEvent
- #define Uses_TDialog
- #define Uses_TLabel
- #define Uses_TEvent
- #define Uses_TButton
- #define Uses_TApplication
- #define Uses_TDeskTop
- #define Uses_TProgram
-
- #include <tv.h>
- #include <time.h>
- const int cmAbout = 1000;
- class TMYAPP : public TApplication
- {
- public:
- TMYAPP();
- static TMenuBar* initMenuBar(TRect r);
- virtual void handleEvent(TEvent& event);
- void About();
- };
-
- class TTimedBox : public TDialog
- {
- public:
- TTimedBox(TRect &trect,char *header, char *message, int ttime);
- virtual void handleEvent(TEvent &event);
- protected:
- TStaticText *text;
- TButton *ok;
- time_t first, second;
- int delaytime, hcnt;
- };
-
- //*-------------------------------------------------------------------------*/
- int main()
- {
-
- TMYAPP *tapp = new TMYAPP();
-
- tapp->run();
-
- return 0;
-
- }
-
- TTimedBox::TTimedBox(TRect &trect,char *header,char *message,int ttime) :
- TDialog(trect, header),
- TWindowInit(&TTimedBox::initFrame)
- {
- //*** insert message
- TRect temp;
- temp.a.x = trect.a.x+2;
- temp.a.y = trect.a.y+2;
- temp.b.x = trect.b.x-2;
- temp.b.y = trect.b.y-2;
-
- text = new TStaticText(temp, message);
- insert(text);
-
- //** figure out correct centering for button
- temp.a.y = trect.b.y - 3;
- temp.a.x = trect.b.x / 2 - 6;
- temp.b.y = temp.a.y +2;
- temp.b.x = temp.a.x + 12;
- TButton *tb = new TButton(temp, " OK", cmCancel, bfDefault);
- insert(tb);
- options |= ofCentered;
-
- delaytime = ttime;
- first = time(NULL);
- hcnt = 0;
- }
-
- /*------------------------------------------------------------------------*/
- //*** here is where you can trap the events and cancel yourself
-
- void TTimedBox::handleEvent(TEvent &event)
- {
-
- TDialog::handleEvent(event);
-
- second = time(NULL); //*** get second time for compare
-
- if ((difftime(second,first) > delaytime) && (hcnt == 0) )
- {
- // when time is up send cancel to remove ourself
- event.what = evCommand;
- event.message.command = cmCancel;
- event.message.infoPtr = 0;
- putEvent(event);
- //hcnt was necessary to prevent more than one putEvent from occurring
- hcnt++;
- }
- //*** put other handleEvent code here.
- }
-
-
- //*-------------------------------------------------------------------------*/
- TMYAPP::TMYAPP() :
- TProgInit ( &TMYAPP::initStatusLine,
- &TMYAPP::initMenuBar,
- &TMYAPP::initDeskTop )
- {
- }
- //------------------------------------------------------------------------
- void TMYAPP::About()
- {
- int timer = 5; //** set delay to 5 seconds
- //*** create timed dialog box
- TTimedBox *aboutBox = new TTimedBox(TRect(0, 0, 32, 12), "About",
- "\003Widgit Wonders\n"
- "\003(C) Copyright 1992\n"
- "\003All Rights Reserved\n"
- "\003Widgit Wonders Corp.\n"
- "\0035 second box demo\n"
- "\003 Version 0.1", timer);
-
- deskTop->execView(aboutBox);
- destroy( aboutBox );
- }
-
- void TMYAPP::handleEvent(TEvent& event)
- {
- TApplication::handleEvent(event); // act like base!
- if( event.what == evCommand )
- {
- switch( event.message.command )
- {
- case cmAbout:
- About();
- break;
-
- default:
- return;
- }
- clearEvent( event ); // clear event after handling
- }
- }
- TMenuBar* TMYAPP::initMenuBar(TRect r)
- {
- r.b.y = r.a.y + 1;
-
- TSubMenu& sub1 =
- *new TSubMenu("~A~bout", 0) +
- *new TMenuItem( "A~b~out", cmAbout, kbNoKey);
-
- return (new TMenuBar( r, sub1 ));
- }
-