//------------------------------------------- // Project Saie // Jyvaskylan Yliopisto // Copyright © 1996. All Rights Reserved. // // SUBSYSTEM: Saie Application // FILE: saiedemo.cpp // AUTHOR: Vesa Lappalainen // // OVERVIEW // ~~~~~~~~ // Source file for TFormSaieDemo (TDialog). // Ks. saiedemo.h // //------------------------------------------- #include #include "saiedemo.h" #define ALKU_ID 3000 //------------------------------------------- // cLaskuri ================================= //------------------------------------------- //------------------------------------------- void cLaskuri::count() { n++; if ( n % PAIVITYS == 0 ) { char s[30]; wsprintf(s,"%d",n); Text->SetWindowText(s); } } //------------------------------------------- int cLaskuri::Run() // Tämä suorittaa varsinaisen säikeen // toimenpiteet. Kun tämä metodi loppuu, // pysähtyy säie. { char *mes=""; while ( n < raja ) { if ( ShouldTerminate() ) { mes = "T"; break; } count(); } char s[30]; wsprintf(s,"%d%s",n,mes); Text->SetWindowText(s); return 0; } //------------------------------------------- // TFormSaieDemo ============================ //------------------------------------------- //------------------------------------------- DEFINE_RESPONSE_TABLE1(TFormSaieDemo,TDialog) //{{TFormSaieDemoRSP_TBL_BEGIN}} EV_BN_CLICKED(IDKAYNNISTA, BNKaynnistaClicked), //{{TFormSaieDemoRSP_TBL_END}} END_RESPONSE_TABLE; //{{TFormSaieDemo Implementation}} //------------------------------------------- TFormSaieDemo::TFormSaieDemo(TWindow* parent, TResId resId, TModule* module) : TDialog(parent, resId, module) { } //------------------------------------------- TFormSaieDemo::~TFormSaieDemo() { Destroy(); } //------------------------------------------- static bool Clear(cLaskuri * &saie) // Tämä funktio tarkistaa onko säie jo // siivottu, eli se on tuhottu. // Mikäli säie ei ole tuhottu, mutta se // on valmis, tuhotaan säie. { if ( saie == NULL ) return true; if ( saie->GetStatus() != TThread::Finished ) return false; delete saie; saie = NULL; return true; } //------------------------------------------- void TFormSaieDemo::BNKaynnistaClicked() { for (int i=0; iStart(); } saikeet[0]->SetPriority( THREAD_PRIORITY_ABOVE_NORMAL); } //------------------------------------------- TResult TFormSaieDemo::EvCommand(uint id, THandle hWndCtl, uint notifyCode) // Jos laskuria klik., "tapetaan vast.säie" { TResult result=TDialog::EvCommand(id, hWndCtl,notifyCode); int i = id-ALKU_ID; if ( 0 <= i && i < SAIKEITA ) if ( !Clear(saikeet[i]) ) saikeet[i]->Terminate(); return result; } //------------------------------------------- bool TFormSaieDemo::Create() // Luodaan laskurit alekkain näytölle { bool result; int y = 10, dy = 20; for (int i=0; iGetWindowRect(); rc.top = 0; rc.bottom = rc.top + y + 50; this->MoveWindow(rc,TRUE); return result; } bool TFormSaieDemo::CanClose() { bool result = TDialog::CanClose(); for (int i=0; iTerminate(); } return result; }