⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 active1.cpp

📁 如题 就是 这东西 为什么非要我 说到 20个 字 呢 看看这回 够 不
💻 CPP
字号:
// Active1.cpp
//
// Copyright (c) 1999-2007 Symbian Software Ltd.  All rights reserved.
//
// $Change: 937687 $
//
// Active1 exercise

// Asynchronous keyboard processing with messenger program.
// A single CWriteKeyProcessor active object (derived from 
// class CActiveConsole) which accepts and prints keyboard
// input to a console.

// PROJECT HEADERS
#include "active1.h"
#include "eustd.h"

//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleScheduler (implementation)
//
//////////////////////////////////////////////////////////////////////////////
void CExampleScheduler::Error(TInt aError) const
    {
    _LIT(KMsgSchedErr, "CExampleScheduler-error");
    User::Panic(KMsgSchedErr, aError);
    }

//////////////////////////////////////////////////////////////////////////////
//
// -----> CActiveConsole (implementation)
//
//////////////////////////////////////////////////////////////////////////////
CActiveConsole::CActiveConsole(CConsoleBase* aConsole) 
    : CActive(CActive::EPriorityUserInput)
    {
    // Construct high-priority active object
    iConsole = aConsole;
    }

void CActiveConsole::ConstructL()
    {
    // Add to active scheduler
    CActiveScheduler::Add(this);
    }

CActiveConsole::~CActiveConsole()
    {
    // Make sure we're cancelled
    Cancel();
    }

void  CActiveConsole::DoCancel()
    {
    iConsole->ReadCancel();
    }

void  CActiveConsole::RunL()
    {
    // Handle completed request
    ProcessKeyPress(TChar(iConsole->KeyCode()));
    }

void CActiveConsole::RequestCharacter()
    {
    // A request is issued to the CConsoleBase to accept a
    // character from the keyboard.
    iConsole->Read(iStatus); 
    SetActive();
    }


//////////////////////////////////////////////////////////////////////////////
//
// -----> CWriteKeyProcessor (implementation)
//
//////////////////////////////////////////////////////////////////////////////
CWriteKeyProcessor::CWriteKeyProcessor(CConsoleBase* aConsole)
    : CActiveConsole(aConsole)
    {};

CWriteKeyProcessor* CWriteKeyProcessor::NewLC(CConsoleBase* aConsole)
    {
    CWriteKeyProcessor* self = new(ELeave) CWriteKeyProcessor(aConsole);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

CWriteKeyProcessor* CWriteKeyProcessor::NewL(CConsoleBase* aConsole)
    {
    CWriteKeyProcessor* self = NewLC(aConsole);
    CleanupStack::Pop(self);
    return self;
    }

void CWriteKeyProcessor::ProcessKeyPress(TChar aChar)
    {
    // "Esc" character prints a new line and stops the scheduler
    _LIT(KTextEsc, "\n");
    if (aChar == EKeyEscape)
        {
        iConsole->Printf(KTextEsc);
        CActiveScheduler::Stop();
        return;
        }

    // "Enter" prints a new line character
    // An alphabetic or space is printed as a character;
    // anything else is printed as an integer.
    if (aChar == EKeyEnter)
        iConsole->Printf(KTextEsc);
    else
        {
        _LIT(KFormatString2, "%c");
        _LIT(KFormatString3, "%d");
        if (aChar.IsAlphaDigit() || aChar.IsSpace())
            {
            iConsole->Printf(KFormatString2, TUint(aChar));
            }
        else
            {
            iConsole->Printf(KFormatString3, TUint(aChar));
            }
        }

    // Issue another request
    RequestCharacter();
    }


//////////////////////////////////////////////////////////////////////////////
//
// Do the example
//
//////////////////////////////////////////////////////////////////////////////
LOCAL_C void doExampleL()
    {
    // Construct and install the active scheduler
    CExampleScheduler*  exampleScheduler = new(ELeave) CExampleScheduler;

    // Push onto the cleanup stack
    CleanupStack::PushL(exampleScheduler);
     
    // Install as the active scheduler
    CActiveScheduler::Install(exampleScheduler);

    // Create a CWriteKeyProcessor active object
    _LIT(KTitleMsg, "A single CWriteKeyProcessor active object.\nIt accepts and prints \nkeyboard input to the \nconsole.\nPress ESC to end.\n\n");
    console->Printf(KTitleMsg);
    CWriteKeyProcessor* keyProcesser = CWriteKeyProcessor::NewLC(console);

    // Issue the first request
    keyProcesser->RequestCharacter();

    // Main part of program is a wait loop
    // This function completes when the scheduler stops
    CActiveScheduler::Start();

    // Remove from the cleanup stack and destroy:
    // 1. the CWriteKeyProcessor active object
    // 2. exampleScheduler
    CleanupStack::PopAndDestroy(2, exampleScheduler); 
    }

⌨️ 快捷键说明

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