![](http://album.hi.csdn.net/app_uploads/moonson/20090103/002916165.p.jpg?d=20090103012157044)
![](http://album.hi.csdn.net/app_uploads/moonson/20090103/002917634.p.jpg?d=20090103012252276)
3. Key Concept
将App,Doc, Ui, View类的基类的官方mi摘录如下。
CAknApplication:
Base class for a Series 60 application. S60的官方介绍真够简单的
CEikApplication
The base of all Uikon applications.
CEikApplication builds on CApaApplication
, providing a basis for applications working within the framework provided by Uikon. It also contains an interface to the resource file and the document object belonging to the application.
Each Uikon class is derived from CEikApplication. Application writers must provide at least an implementation of the pure virtual function CreateDocumentL()
.
The application's resource file can be changed from the default by overriding ResourceFileName()
.
CreateDocumentL()
Creates a new document.
This function is called by the application DLL framework during application startup to create a new instance of the document associated with this application. This implementation of the function makes a record of the CApaProcess
argument, and returns a document created by the un-parameterised, private, overload.
这个函数在CHelloworldBasicApp中实现了。这个函数创建并返回了一个指向CHelloworldbasic对象的指针。但是当时我不明白,这个虚函数在何时会被调用?这段解释说地也不是很清楚,application DLL framework是什么概念,可以理解为是application server 吗?
ResourceFileName()
Gets the localized name of the resource file used by this application.
By default, this file has an extension of .rsc and uses the same name as the application file located in the same directory. Language variants are supported through BaflUtils::NearestLanguageFile()
.
每一个application都户默认的与其同名的rss文件相关联,在rss文件中定义了application的UI。
CAknDocument
Base class for a Series 60 application document. 等于没说
CEikDocument
In file-based applications, the document represents the data that relates to a
particular instance of the application, and should handle storing and restoring
it. In all applications, whether file-based or not, the document is used to create
the application UI.
A class derived from CEikDocument must be defined by each GUI application, and minimally
it must implement CreateAppUiL(). Note that UIs may implement their own document base class,
derived from CEikDocument, which applications may need to derive from instead.
The document is created by the application's CreateDocumentL() function.
CEikDocument负责两件事情1.应用程序相关的文件操作 2.实现CreateAppUiL()函数
CreateAppUiL()
Constructs the application UI.
This function is called by the UI framework during application start-up. It should only carry out first phase construction of the app UI, in other words, using new(ELeave). It should not call the app UI's ConstructL(), because the UI framework is responsible for this. Note also that the UI framework takes ownership of the app UI, so the document does not need to destroy it.
这个函数什么时候调用,被谁调用?文中提到在应用程序启动时被UI framework调用,这也是一个比较模糊的回答。
另外提到CreateAppUiL不负责进行Ui的construct,这个ConstructL函数被谁调用呢?估计也是UI framework
CAknAppUi
Abstract Avkon application UI class. 简单
CAknAppUiBase
Abstract Avkon application UI base class
CEikAppUi
Handles application-wide aspects of the application's user interface such
as the menu bar, toolbar pop-up menus, opening and closing files and exiting the
application cleanly.
Every GUI application should use its own class derived from CEikAppUi.
An app UI's main role is to handle commands, in its HandleCommandL() function.
These may be invoked using the menu bar, toolbar, or hotkeys; the commands
that an app UI handles are specified in the application's resource file.
In addition, the app UI normally needs to respond to other kinds of events, by
providing suitable implementations of the following virtual functions, all
inherited from CCoeAppUi:
- HandleKeyEventL(): Key events.
- HandleForegroundEventL(): Application switched to foreground.
- HandleSwitchOnEventL(): Machine switched on.
- HandleSystemEventL(): System events.
- HandleApplicationSpecificEventL(): Application-specific events.
说得比较明白了,虽然对于底层的消息调用机制仍然是透明的。
CCoeControl
Control base class from which all other controls are derived.
4.1 main
- GLDEF_C TInt E32Main()
- {
- return EikStart::RunApplication( NewApplication );
- }
- LOCAL_C CApaApplication* NewApplication()
- {
- return new CHelloWorldBasicApplication;
- }
4.2 CHelloworldBasicApp
- CApaDocument* CHelloWorldBasicApplication::CreateDocumentL()
- {
- // Create an HelloWorldBasic document, and return a pointer to it
- return (static_cast<CApaDocument*>
- ( CHelloWorldBasicDocument::NewL( *this ) ) );
- }
- TUid CHelloWorldBasicApplication::AppDllUid() const
- {
- // Return the UID for the HelloWorldBasic application
- return KUidHelloWorldBasicApp;
- }
这个类的NewL,NewLC,ConstructL都是常规实现,无须赘述。
- CHelloWorldBasicDocument::CHelloWorldBasicDocument( CEikApplication& aApp )
- : CAknDocument( aApp )
- {
- // No implementation required
- }
- CEikAppUi* CHelloWorldBasicDocument::CreateAppUiL()
- {
- // Create the application user interface, and return a pointer to it;
- // the framework takes ownership of this object
- return ( static_cast <CEikAppUi*> ( new ( ELeave )
- CHelloWorldBasicAppUi ) );
- }
CHelloworldBasicUi中重点实现了两个函数ConstructL以及HandleCommand
ConstructL首先调用了BasicConstructL函数,然后创建了一个hello.txt文件。
HandleCommand 和Windows的消息处理函数类似,一堆的switch case
5. Notes