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

📄 descriptordemo.cpp

📁 Symbian descriptors sample
💻 CPP
字号:
/*
============================================================================
 Name        : DescriptorDemo.cpp
 Author      : Mopius
 Copyright   : (c) Mopius, www.mopius.com
 Description : Exe source file
============================================================================
*/

//  Include Files  

#include "DescriptorDemo.h"
#include <e32base.h>
#include <e32std.h>
#include <e32cons.h>            // Console


//  Constants

_LIT(KTextConsoleTitle, "Console");
_LIT(KTextFailed, " failed, leave code = %d");
_LIT(KTextPressAnyKey, " [press any key]\n");


//  Global Variables

LOCAL_D CConsoleBase* console;  // write all messages to this


//  Local Functions

LOCAL_C void MainL()
    {
    //
    // add your program code here, example code below
    //
    
    // Edit 1: Create literal KString1 with text "My Text"
    _LIT(KString1, "My Text");
    // Edit 2: Create literal KString2 with text "Your Text"
    _LIT(KString2, "Your Text");
    // Edit 2: Create literal KString3 with text "His Test" (teSt instead of teXt!!)
    _LIT(KString3, "His Test");
    
    // Edit 3: Create TBuf str1 with maximum length of 20, 
    // initialize with contents of KString1
    TBuf<20> str1(KString1);
    // Edit 4: Create TBuf str2 with maximum length of 20,
    // initialize with contents of KString2
    TBuf<20> str2(KString2);
    
    // Result variable that will save temp. results
    TInt result = 0;
    
    // ------------------------------------------------------------------
    // COMPARE
    // ------------------------------------------------------------------
    // Note: Result of Compare() is the same as strcmp() in C
    // Find help in S60 SDK help: Search for TDesC16
    
    // Edit 5: Compare str1 and str2
    result = str1.Compare(str2);
    // Format output and print it to the console
    _LIT(KFormatCompare1, "Compare() using str1 and str2 = %d\n");
    console->Printf(KFormatCompare1, result);
    
    // Edit 6: Compare str1 and KString1 and print the output to the console
    result = str1.Compare(KString1);
    _LIT(KFormatCompare2, "Compare() using str1 and KString1 = %d\n");
    console->Printf(KFormatCompare2, result);
    
    // ------------------------------------------------------------------
    // FIND
    // ------------------------------------------------------------------
    _LIT(KFind1, "Text");
    
    // Edit 7: Find KFind1 in str1
    result = str1.Find(KFind1);
    _LIT(KFormatFind1, "Find KFind1 in str1 = %d\n");
    console->Printf(KFormatFind1, result);
    
    // ------------------------------------------------------------------
    // MATCH
    // ------------------------------------------------------------------
    // Match allows to use wildcards:
    // * represents a sequence of characters
    // ? represents an occurence of any single character
    _LIT(KMatch1, "* Text");
    
    // Edit 8: Match str1 with KMatch1
    result = str1.Match(KMatch1);
    _LIT(KFormatMatch1, "Match str1 and KMatch1 = %d\n");
    console->Printf(KFormatMatch1, result);
    
    // ------------------------------------------------------------------
    // COPY
    // ------------------------------------------------------------------
    // Edit 9: Copy data from str1 to str2 (thus replacing the data
    // currently stored in str2) and make it uppercase
    // Hint: User CopyUC()
    str2.CopyUC(str1);
    // Print contents of str2
    _LIT(KFormatCopy1, "Copy + uppercase str1 into str2 = %S\n");
    // Edit 10: Uncomment the following line to print the results
    //console->Printf(KFormatCopy1, &str2);
    
    // ------------------------------------------------------------------
    // APPEND
    // ------------------------------------------------------------------
    // Edit 11: Append str1 to str2 and print contents of str2
    str2.Append(str1);
    _LIT(KFormatAppend1, "Append str1 to str2 = %S\n");
    console->Printf(KFormatAppend1, &str2);
    
    // ------------------------------------------------------------------
    // DELETE
    // ------------------------------------------------------------------
    // Edit 12: Delete data in str2 starting at position 3 with a length of 7
    // and print the results
    str2.Delete(3, 7);
    _LIT(KFormatDelete1, "Delete chars from str2 = %S\n");
    console->Printf(KFormatDelete1, &str2);
    
    }


LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    MainL();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }


//  Global Functions

GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
        return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    if (mainError)
        console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();
    
    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }



⌨️ 快捷键说明

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