countdown.cpp

来自「symbian下的几个小例子。。很值得学习」· C++ 代码 · 共 92 行

CPP
92
字号
// countdown.cpp
//
// Copyright (c) Symbian Software Ltd 1999 - 2007.  All rights reserved.
//

#include "simpleex.h"
#include "countdown.h"

/*============================================================================
      CCountdown active object
      Displays a countdown from 10 after which it displays an alert dialog.
==============================================================================*/

CCountdown* CCountdown::NewL(CSimpleExAppView *aAppView)
	{
    CCountdown* self = new(ELeave) CCountdown;
    CleanupStack::PushL(self);
    self->ConstructL(aAppView);
    CleanupStack::Pop(self);
    return self;
	}

CCountdown::CCountdown() 
	: CActive(CActive::EPriorityUserInput)
	  // Construct high-priority active object
{}

void CCountdown::ConstructL(CSimpleExAppView* aAppView)
	{
    iCount=0;
    iAppView = aAppView;
    User::LeaveIfError(iTimer.CreateLocal());

    iInterval = 1000000;  // 1 second interval
	  // Add to active scheduler
	CActiveScheduler::Add(this);
	}


void CCountdown::StartCountdown()
	{
// This method is invoked when user selects the start menu item to start
// the countdown.
     
    if (iCount == 0)
    	{
        iCount=10;
        iTimer.After(iStatus,iInterval);
        SetActive();
    	}
	}

CCountdown::~CCountdown()
	{
	// Make sure we're cancelled
	Cancel();
    iTimer.Close();
	}

void CCountdown::RunL()
	{
    TBuf<50> buff;
	_LIT(KFormatString,"-%d-");
    buff.Format(KFormatString,iCount);
    iAppView->UpdateScreenText(buff);

    if (iCount)
    	{
        iTimer.After(iStatus,iInterval);
        SetActive();
        --iCount;
    	} 
    else
    	{
        iAppView->UpdateScreenText(KSimpleExText);
		_LIT(KMessage,"Start Selected!");
        CEikonEnv::Static()->AlertWin(KMessage);
    	}     
	}

void CCountdown::Stop()
	{
    iCount=0;
    iAppView->UpdateScreenText(KSimpleExText);
    Cancel();
	}

void CCountdown::DoCancel()
	{
    iTimer.Cancel();
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?