首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> base >> 正文
A simple text console
作者:佚名    文章来源:不详    更新时间:2006-5-7 11:00:34

Console is a very simple application that only creates a text console and displays Hello World ! .

As you may guess, the code to do that is quite simple :

void ConsoleMainL()
{
   console->Printf(_L("Hello World!\n"));
}

There is probably not much to say about this. Just note the use of _L( ) macro that shall be used to create build independant strings (that can use 8 or 16 bits text depending on the use of Unicode or not).

Actually, most of the work is done in the console framework located in console.h. This is a strange place to put some C++ code, and it has some drawbacks if you are a serious developer. However, it allows a very simple use of the framework by just including it. Here is the code to create the console :

CConsoleBase *console;
console=Console::NewL(_L("Console"),TSize(KConsFullScreen,KConsFullScreen));

TInt Err;
TRAP(Err,ConsoleMainL());
if(Err)
   console->Printf(_L("TRAP: Error(%d)\n"),Err);

console->Printf(_L("\n[Press any key]"));
console->Getch();
delete console;

CConsoleBase and Console are not described in most Symbian documentation. A quick look at e32cons.h (in epoc/include directory) will give you clues about the available method for CConsoleBase :

  Printf()

  Getch

  SetPos(X) and SetPos(X,Y)

  WhereX() and WhereY()

Other functions are virtual and can only be used through CEikConsole class (which is not as straightforward to use due to the use of Eikon).

Console only adds to CConsoleBase the NewL() constructor and the ability to use the trap harness (the TRAP() primitive) : this construction is used to catch and report any potential errors that may occurs in the code called from ConsoleMainL.



This exemple can be reused for developping very small text application that will let you play and try some other Symbian concept without the burden of a GUI (and it should also work no matter of your graphical environment). But it is not a complete code, some important concept like the cleanup stack are missing and should be added for real development.
相关文章:
Integrating LeaveScan into Codewarrior 3.x
How to  view all descriptor types (and others) in VC6 debugger
Cmo ver todos los tipos de descriptores (y otras estructuras) en el depurador de VC6
TRAPs and Leaves
LEAVE and TRAP
Exception Handling and Cleanup Mechanism in Symbian
How to  view all descriptor types (and others) in VC6 debugger
Cmo ver todos los tipos de descriptores (y otras estructuras) en el depurador de VC6
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号