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) |