Symbian OS Workshop
48 pages
English

Symbian OS Workshop

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
48 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Symbian OS – Workshop
Introduction
In this tutorial you will get to know some of the basics of developing for mobile
phones using C++. All the examples target Symbian OS and the Series 60 UI platform.
Instead of long, theoretical explanations, a more practical approach is used.
First, you will learn how to create your own mobile project. Then, you will add the
prewritten game logic of a small Arkanoid-like game called “Mopoid”. This provides an
interesting way to get to know important aspects of developing for Symbian OS,
including:
• defining and using menus,
• handling and displaying text,
• loading and showing images,
• writing and reading data to/from files,
• using a timer for periodic events,
• ... and many more smaller, but equally important topics.
You will see the results of your actions right away. Whenever some Symbian OS
specifics comes into sight (like memory handling), a short explanation will give you a
brief overview of why it is this way and how to work with it.
Of course, only the surface of all those topics can be scratched, as each of them would
easily fill a tutorial of their own of this size. However, this tutorial will give you a basic
understanding of how developing for mobile phones using C++ works, and it is a good
starting point for your own projects.
I hope that you have fun working your way through the tutorial and that you will get a
nice game out of it!
- Andreas Jakl
© 2005 Mopius Page 2/48 Symbian OS – ...

Sujets

Informations

Publié par
Nombre de lectures 109
Langue English
Poids de l'ouvrage 1 Mo

Extrait

Symbian OS  Workshop
IntroductionIn this tutorial you will get to know some of the basics of developing for mobile phones using C++. All the examples target Symbian OS and the Series 60 UI platform. Instead of long, theoretical explanations, a more practical approach is used. First, you will learn how to create your own mobile project. Then, you will add the prewritten game logic of a small Arkanoid-like game called Mopoid. This provides an interesting way to get to know important aspects of developing for Symbian OS, including:  defining and using menus,  handling and displaying text,  loading and showing images,  writing and reading data to/from files,  using a timer for periodic events,  and many more smaller, but equally important topics.... You will see the results of your actions right away. Whenever some Symbian OS specifics comes into sight (like memory handling), a short explanation will give you a brief overview of why it is this way and how to work with it. Of course, only the surface of all those topics can be scratched, as each of them would easily fill a tutorial of their own of this size. However, this tutorial will give you a basic understanding of how developing for mobile phones using C++ works, and it is a good starting point for your own projects. I hope that you have fun working your way through the tutorial and that you will get a nice game out of it! - Andreas Jakl
© 2005 Mopius
Page 2/48
Symbian OS  Workshop
Contents Step 0 - Preparation ........................................................................................................... 5 Getting started ................................................................................................................ 5 Choosing an IDE ........................................................................................................... 6 Choice of the Series 60 SDK........................................................................................ 7 Step 1 - Defining the Symbian OS SDK ........................................................................ 8 Step 2 - Creating a new project ........................................................................................ 8 Step 3 - Testing the project .............................................................................................. 9 Troubleshooting: .......................................................................................................... 10 Step 4 - Defining strings ................................................................................................. 11 Step 5 - Defining the menu ............................................................................................ 12 Step 6 - Displaying the about box ................................................................................. 14 If something doesnt work... ....................................................................................... 16 Step 7 - Getting the application to the mobile phone! ............................................... 17 Step 8 - Adding the game engine to your project........................................................ 18 Unzipping the file......................................................................................................... 18 Distributing the game data.......................................................................................... 18 Adding the source files to your project..................................................................... 18 Adding additional libraries to the project definition file......................................... 19 Defining new text ......................................................................................................... 20 New game...................................................................................................................... 20 Adding graphic and sound files.................................................................................. 20 Testing............................................................................................................................ 22 Troubleshooting ........................................................................................................... 22 Step 9 - Loading images .................................................................................................. 22 C and T classes ............................................................................................................. 23 ConstructL..................................................................................................................... 23 Loading bitmaps ........................................................................................................... 24 Deleting images ............................................................................................................ 26 Step 10 - Displaying the graphics..................................................................................... 27 Handling transparency................................................................................................. 28 Drawing a bitmap ......................................................................................................... 28 Step 11 - Handling keys..................................................................................................... 29 © 2005 Mopius Page 3/48
Symbian OS  Workshop Step 12 - Displaying text ................................................................................................... 31 Setting a font ................................................................................................................. 31 Reading text from the resource file ........................................................................... 32 Formatting and displaying the text ............................................................................ 32 Aligning text .................................................................................................................. 32 Step 13 - Reading and writing files .................................................................................. 34 Preparation .................................................................................................................... 34 Setting the file name..................................................................................................... 34 Opening the file ............................................................................................................ 35 Creating the stream ...................................................................................................... 35 Writing the data ............................................................................................................ 35 Closing the file .............................................................................................................. 36 The Cleanup Stack ....................................................................................................... 36 Loading .......................................................................................................................... 37 Cleanup when your application is uninstalled .......................................................... 38 Building from the command line ............................................................................... 40 Step 14 - Setting the application icon.............................................................................. 40 Step 15 - Handling being in the background ................................................................. 42 Step 16 - Periodic Events.................................................................................................. 44 Keeping the backlight on ............................................................................................ 44 Using a timer ................................................................................................................. 45 Stopping the timer........................................................................................................ 45 Step 17 - Final notes .......................................................................................................... 46 About the author .......................................................................................................... 46 Contact........................................................................................................................... 46 Copyright ....................................................................................................................... 47 Step 18 - Exercises ............................................................................................................. 48 Alternative key handling .............................................................................................. 48 Define more levels ....................................................................................................... 48 Saving the game progress ............................................................................................ 48 
© 2005 Mopius
Page 4/48
Symbian OS  Workshop
Step 0 - Preparation Download the following components:  ActivePerl: needed by the Symbian OS tool chain to compile your project http://www.activestate.com/ Symbian OS SDK:uses the Series 60 SDK 1.2 for Symbian OS,this tutorial Nokia Edition to provide the best compatibility with older Series 60 devices  http://www.symbian.com/developer/sdks_series60.asp Microsoft Debugging Tools:needed to debug applications in the emulator through Borlands C++BuilderX  http://www.microsoft.com/whdc/devtools/debugging/ Visual C++ Toolkit:only needed if you dont have Visual Studio 6 or .net installed. Its free and needed to compile the projects for the emulator. Go to http://www.microsoft.com/downloads/and search for Visual C++ Toolkit to download it.  Borland C++BuilderX Mobile Edition (v1.5):get it for free by filling out the short survey athttp://info.borland.com/survey/cbx15_mobile_edition.htmlInstall the components in the order listed above. Allow all installations to add the programs to the systems path variable, in case they ask! Its recommended that you install the Series 60 SDK to its default location atC:\Symbian\! Getting started Should your application crash in the emulator, there is a way to make it display a more helpful error message. To activate this feature, create an empty file called ErrRd in the \s\cystsco23W\niataem\BootdnaibmyS\:CEp0\s6ieer\S.1\6 directory of your Series 60 SDK. Thats it. When you first start your copy of C++BuilderX Mobile Edition, it needs to be registered. Choose the activation file option, and locate the file that Borland sent you after you filled out its survey and registered for its development network.
© 2005 Mopius
Page 5/48
Symbian OS  Workshop
Choosing an IDE The Symbian OS build tools are actually command line-based and would work without any IDE. However, development is more comfortable if you use one. There are several choices, each with advantages and disadvantages1: Microsoft Visual C++ 6
Microsoft Visual Studio .net
Metrowerks CodeWarrior
Borland C++BuilderX Mobile Edition2
Eclipse
As you can see, there is no obvious best way to develop Symbian OS C++ applications. For this tutorial, Borlands C++BuilderX was chosen, because it is free and it takes away much of the initial complexity when starting with Symbian OS, even though the IDE itself still needs a lot of improvement. Please note:The list above is based on personal impressions. CodeWarrior could also be a very good choice, especially now that its mobile edition was bought by Nokia and will be actively improved in the future. 1 All products are trademarks of their respective owners. 2 Will be referenced as C++BuilderX in this tutorial. © 2005 Mopius
Page 6/48
Symbian OS  Workshop Choice of the Series 60 SDK The Series 60 SDK for Symbian OS is available in higher version numbers, which target newer Series 60 phones. Up to now, the devices have always been backward compatible, so an application developed for Symbian OS v6.x mobile phones (using the SDK v1.2) also works on newer Symbian OS v7.0s and v8.0 phones. While applications compiled using the SDK v2.0 (which mainly targets the Nokia 6600 with Symbian OS v7.0s) should still work on older devices, this can be a bit problematic. If the source code is compiled by even newer SDKs, the files are not backward compatible on a binary level any more. Which version of the SDK you use is entirely your choice. If you only want to develop for newer phones, or if you want to do new things that were not possible before, go with (at least) the SDK v2.0. Loading images and sounds has been specifically improved. Internet (HTTP) connections are easier to handle as well. If you want to develop a commercial application that should reach the broadest possible audience, you shouldnt exclude older Series 60 phones. By choosing to target Series 60 you already restrict your potential market. If you limit your target audience even more by making your program only compatible to the newest phones, you will have an even harder time selling it.
© 2005 Mopius
Page 7/48
Symbian OS  Workshop Step 1 - Defining the Symbian OS SDK  
Fig. 1  Defining the Symbian OS SDK in Borland's C++BuilderX. Its time to start working! Open Borlands C++BuilderX Mobile Edition. Go to ToolsConfiguration. Create a new SDK configuration, using theSymbian SDK SDK Template of the SDK you have installed, in this case: Symbian Series 60 1.x (Microsoft version). At least for the SDK v1.2, do not use the Borland SDK version, otherwise compiling the project wont work! Set the path as shown in the screenshot, and choose an appropriate name like Series 60 1.2. Step 2 - Creating a new project Create a new project: FileNew...Series 60Series 60 GUI Application.
Fig. 2  Creating a new Symbian C++ project. Enter Mopoid as its name (dont use a different name for this project, otherwise some includes of the prewritten files we will include later on wont work). Place it in the C:/Symbian/dev directory and let C++BuilderX create a project subdirectory, so that all your projects will be kept separated from each other.
© 2005 Mopius
Page 8/48
Symbian OS  Workshop
Fig. 3  Defining properties of the project (Step 1). Go to the next step. Enter the same name for the project, Mopoid. As we want to do a game, choose Full Screen as view type. The default UID3 proposed by C++BuilderX should NOT be used. Change the UID to something between 0x01000000 and 0x0FFFFFFF  Symbian reserved those IDs for testing projects. Every application installed on a phone has to have its own unique UID. Therefore, if you want to release your game to the public, send a mail to uid@symbiandevnet.comcontaining your name and how many UIDs you need (5 should be sufficient for the beginning). They will send you the UIDs as soon as possible.
Fig. 4  Defining properties of the project (Step 2).
Step 3 Testing the project -Your workspace should look similar to the screenshot in Fig. 5. Now is the time to test your project to see if everything is configured correctly. Press the Run Project button (F9).
© 2005 Mopius
Page 9/48
Symbian OS  Workshop
Fig. 5  This is what the default workspace of Borland's C++BuilderX looks like. If everything works well, the emulator will show up after some time. Deactivate the memory resident virus scanner if you have one running to make this process a bit faster. Your own application will be located at the bottom of the menu, so move down using the cursor keys to select it. If you dont want to do this every time you test your game, select it, press the left softkey (Options), choose Move and move it to the upper left position of the menu. It will stay there even if you close the emulator and start it again. When you start the Mopoid application, you will only see a white screen. This is because we chose to create a full screen application, which does not have a visible status or menu bar. When you press the left softkey, a default menu will show up. In the next steps we will adapt it to our needs.
Troubleshooting: If Microsofts VisualStudio.net or Microsofts toolkit is installed on your PC and Borland C++BuilderX uses this compiler for the Series 60 SDK v1.2, you may get this error message: LNK2019: unresolved external symbol ftol2 __ © 2005 Mopius
Page 10/48
Symbian OS  Workshop To solve this problem, open the file _, C:\Symbian\6.1\Shared\EPOC32\Tools\cl win.pm for search in a text editor the line that contains /W4 and change it to CLFLAGS = /nologo /Zp4 /W4 /QIfist (youre adding the /QIfist parameter to the options).3 Should C++BuilderX display errors like this during the build process: Can't locate E32env.pm in @INC [...] one possible solution is to put the following two paths at the beginning of your path environment variable: C:\Symbian\6.1\Shared\epoc32\gcc\bin;C:\Symbian\6.1\Shared\epoc32\to ols; If this doesnt help, make sure that Perl is installed and do a repair install of the Symbian OS SDK, basically making sure that the SDK is installed after Perl on your system. Make sure that you close the emulator window after you are finished with testing your project! If you want to compile and the emulator is still running in the background, you will get several error messages! Step 4 - Defining strings By default, the MopoidContainer.akn file should be active. If it is not, open it through the project window on the left: Mopoid.cbxSymbian project (bld.inf) Mopoid.mmpDesignsMopoidContainer.akn (double click). To make our own menu items, we first have to define the text that we want to use. On Symbian OS, text is normally defined in resource files. This makes it easier to localize applications, as mobile phones are global and you will probably want your game to be available in more than one language. Switch to the String Table designer: 3Thanks to Simon Woodside for this tip  see400//781th/:ptmis/ownoisdo.cde/womloeb20g/© 2005 Mopius Page 11/48
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents