?? index.html
字號:
3.4.1 Creating the Application object</a></h4>It is important to note that the NewApplication method is exported by the EXE. This is achieved by adding the EXPORT_C directive before this function in the <a class="el" href="helloworldbasic_8cpp-source.html">helloworldbasic.cpp</a> file. If the EXPORT_C directive is missing, the code will fail to link.<p>The framework calls the function that is exported by the application at ordinal 1 in the DLL. This means that the first function defined in the DEF-file for an application must be the NewApplication method. By default, the tool chain automatically ensures that this is the case for a Symbian OS application.<p>Note that this construction does not use the usual Symbian OS new (ELeave) method, but the C++ style new method. This is because a TRAP harness has not been created for the application at this point. If the system is unable to allocate memory for a new instance of the application, the returned instance pointer will be NULL. The framework checks for, and copes with, this possibility.<h4><a class="anchor" name="Sub342">3.4.2 Getting the application's UID</a></h4>AppDllUid which gets the application's UID must be present, or the application will fail to link.<h4><a class="anchor" name="Sub343">3.4.3 Creating the Document object</a></h4>The Application object is responsible for creating an instance of the Document object. However, it is not required to destroy it. Destruction of the Document object is performed by the framework.<h4><a class="anchor" name="Sub344">3.4.4 Creating the AppUI and View objects</a></h4>Note that creation of the AppUi object does not use the Symbian OS two phase construction sequence. Instead the C++ constructor is called, and a pointer to the created instance is returned to the framework. The framework completes construction by calling ConstructL later. Ownership of the AppUI is passed to the framework, and so the Document object is not responsible for destroying it.<h4><a class="anchor" name="Sub345">3.4.5 Redrawing the screen</a></h4>The Draw method is called by the framework when the view needs to be redrawn, and contains all the code necessary to draw the view for this application. Note that the framework only calls the Draw method in response to general system events. So, for example, the framework automatically calls Draw when the application is launched, when the Options menu disappears, and if the application regains focus.<p>The programmer cannot call the Draw method directly, as it requires the system's graphics context to be activated before it is called. Instead, if the programmer wishes to have the screen redrawn, they should call the DrawNow method.<p>Note that the Draw function cannot leave. This is because the function may be called directly by the framework, and the framework would not know how to handle any errors that might occur. Instead the Draw function must TRAP and handle any errors that might occur.<h4><a class="anchor" name="Sub346">3.4.6 Handling commands</a></h4><a class="el" href="class_c_hello_world_basic_app_ui.html#a682d228622cea7790645ce10f591242">HandleCommandL </a> is called on the AppUi object whenever the user selects a menu option. The argument aCommand indicates the command the user selected. HandleCommandL typically takes the form of a switch statement which invokes different actions according to the value of aCommand.<p><b>Handling command "Hello"</b><p><ul><li>string is loaded from the resource file with StringLoader</li><li>Information note is shown from the descriptor</li></ul><p><div align="center"><img src="information_note.png" alt="information_note.png"></div><p><b>Handling command "Hello from file"</b><p><ul><li>connection to the file server is opened with RFs</li><li>RFile is used to open "Hello.txt"-file for reading</li><li>A RFileStream object is created from the file</li><li>An HBufC descriptor is created from the RFileReadStream object</li><li>The descriptor reads from the stream both the length of the data followed by the data. After this descriptor has been read the stream will be positioned at the beginning of the data.</li><li>Information note is shown from the descriptor</li></ul><p><dl compact><dt><b>Note:</b></dt><dd>"Hello.txt"-file, which is read during the execution of this command, is actually created by the application itself during the execution of <a class="el" href="class_c_hello_world_basic_app_ui.html#9ce34ba0b947863222da3c63d0481044">CHelloWorldBasicAppUi::ConstructL</a>. In other words, it is not an exported ready-made file. The reason for this is that HelloWorld is localized to different languages; and thus during start-up the file is created and the text is written into it with the current language.</dd></dl><div align="center"><img src="japanese_hello.png" alt="japanese_hello.png"></div><p><b>Handling command "Hello from edit"</b><p><ul><li>a string is loaded from the resource file with StringLoader</li><li><a class="el" href="class_c_hello_world_query_dialog.html">CHelloWorldQueryDialog</a> is created and the loaded string is passed to it to be used as default value for input and also a descriptor is passed to store the input given by the user</li><li>no other actions are made, but the text will be displayed in the screen, when the framework calls <a class="el" href="class_c_hello_world_basic_app_view.html#67f946ca7848ec78de4961c5bcefdb72">Draw </a>.</li></ul><p><div align="center"><img src="dialog.png" alt="dialog.png"></div><h3><a class="anchor" name="Sub35">3.5 Handling key events</a></h3>If the application is required to respond to user keypresses, the AddToStackL method must be called by the AppUi object's ConstructL method, with the AppView object as an argument. This adds the AppView object to the control stack.<p>If the view is on the control stack, then whenever the user presses a key the OfferKeyEventL method is called. This has arguments that indicate the type of key event (key down, key press or key up) as well as the code of the key pressed.<p>When the AppUi object is destroyed, the AppView must be removed from the stack. This is done by calling RemoveFromStack in the AppUi object's destructor.<h3><a class="anchor" name="Sub36">3.6 Localization</a></h3>HelloWorld application is localized for English, Finnish, Chinese and Japanese. The "main" rls-file HelloWorldBasic.rls includes language specific rls-files, which all each define the same resource strings in specific language. The localized rls-files contain language id in their name (enum TLanguage in e32const.h specifies language identification values), for example: HelloWorldBasic_32.rls.<p>When localizing to languages, which do not use Western alphabets, such as Chinese or Japanese, a couple of additional steps needs to be taken. As the language cannot be written in ASCII, the language-specific rls-file has to<ul><li>be written in UTF-8 format, and</li><li>contain a line CHARACTER_SET UTF8.</li></ul><p><dl compact><dt><b>Note:</b></dt><dd>Certain editors add some "meta-bytes" into the beginning of file stored in UTF-format. Unfortunately Symbian's resource compiler RCOMP cannot deal with those additional bytes and resource file compilation will fail. It you encounter this, you have to remove those additional bytes with some other editor.</dd></dl>Furthermore, localization affects mmp- and pkg-files also:<ul><li>languages need to be defined in mmp-file. See LANG in <a class="el" href="helloworldbasic_8mmp-source.html">HelloWorldBasic.mmp</a>.</li><li>languages need to be defined in pkg-files and language dependent resource files have to be listed. In addition, most of the strings (e.g. component name) are required to be localized for each defined language. See S60 SDK Help "Package file format" for more detailed information.</li></ul><p>Additionally, HelloWorld application's pkg-files demonstrate two ways to install localized application:<ul><li>the language is determined during installation - and only the determined language is installed (the application's language does not change, even if the language in the phone is changed). <br> HelloWorldBasic_gcce.pkg is made in this fashion.</li><li>the language is determined during installation, but all the supported languages are installed. If the language in the phone changes, the language of the HelloWorld-application changes also, if it supports the new language (English otherwise). <br> HelloWorldBasic_armv5.pkg is made in this fashion. </li></ul><hr><table x-use-null-cells style="x-cell-content-align: top; width: 100%; border-spacing: 0px; border-spacing: 0px;" cellspacing=0 width=100%> <col style="width: 50%;"> <col style="width: 50%;"> <tr style="x-cell-content-align: top;" valign=top> <td style="width: 50%; padding-right: 10px; padding-left: 10px; border-right-style: None; border-left-style: None; border-top-style: None; border-bottom-style: None;" width=50%> <p style="font-family: Arial;"><small style="font-size: smaller;">
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -