Chinaunix首页 | 论坛 | 博客
  • 博客访问: 523902
  • 博文数量: 118
  • 博客积分: 10028
  • 博客等级: 上将
  • 技术积分: 1820
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-07 18:46
文章分类

全部博文(118)

文章存档

2009年(12)

2008年(106)

我的朋友

分类: 嵌入式

2009-08-23 00:49:04



1、新建一个console工程,我取名testconsole
  生成后的cpp文件只有一个,如下:

/*
 ============================================================================
 Name        : consoletest.cpp
 Author     : william
 Copyright : another hello
 Description : Exe source file
 ============================================================================
 */

// Include Files
#include "consoletest.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
    //
    console->Write(_L("Hello, world!\n"));
}

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;
}



2、修改代码
    其实只需要修改MainL()函数就行了,修改后的MainL()如下:

LOCAL_C void MainL()
{
    // add your program code here, example code below
    //console->Write(_L("Hello, world!\n"));
    TTime tm;
    tm.HomeTime();
    
    TBuf<256> timestr;
    _LIT(KTime,"%D%M%Y%/0%1%/1%2%/2%3%/3 %H:%T:%S \n");
    tm.FormatL(timestr,KTime);
    
    console->Write(timestr);
}


3、讲解
  ①E32Main()->console->DoStartL()->MainL()
  ②其实也没什么好讲的,主要是想看下输出系统时间如何实现,需要查看下TTime的SDK文档,不过文档写的很不详细,哎~
  ③应该还有其他方式输出吧?比如像linux下的time + ctime那么方便,这里的格式化有点繁琐了...
阅读(1224) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

zuii2009-11-11 14:44:43

我突然想到一个问题,TTIME获取的是手机上的时间,所以说用户设置多少,得到的就是多少,而根本不需要转换时区.... 脑筋一下没转过弯