Windows Mobile Pocket PC and Smartphone
Game Programming Tutorials


Part 1 - In the beginning aka Hello World

Sections:: Getting Started / Looking Around

 

:: Getting started

Lets compile a basic "Hello World" application to get things started.

  1. Run "Microsoft eMbedded Visual C++"
  2. Go to 'File' then 'New'
  3. In the 'Projects' tab choose "WCE Smartphone 2002 Application"
    (This will run on Windows Mobile Smartphones and Pocket PCs. You can choose
    Pocket PC instead if you want and the code should compile fine)

    For the 'Project name' put "helloworld"

    For 'CPUs' check 'WCE ARM' if you want to compile for your Windows Mobile
    device. Check 'WCE x86' if you want to run the application on an emulator.
    Check both if you want both executables. I like to test on my device not
    the emulator.

    Click OK.
  4. On the dialog that shows up, choose "A typical Hello World application"
    and click Finish.
  5. On the next dialog click OK.

    It will now generate the code for the Hello World application for us.
  6. Click 'Build' on the top menu and click 'Build helloworld.exe'
    (If you named the project something else then this name will be different)

    It should compile with no problems, after all we didn't touch anything so we
    couldn't have messed anything up! After compiling it will start the emulator
    and try to load the application onto it. I don't use the emulator so I just
    click cancel and minimize the emulator.
  7. If you're using an emulator then figure out how to load the .exe onto the
    emulator. I think it should do it automatically but I haven't used the
    emulator in years, so what do I know?
  8. If you're using a Windows Mobile Smartphone or Pocket PC then connect your
    device to your computer with ActiveSync. Copy helloworld.exe (dig through
    the helloworld project folder to find it) onto your device. Using 'File
    Explorer' on your device, find the helloworld.exe and run it.

Congratulations, you got your first Windows Mobile application running.

Next we'll look through the code and see what's going on.

:: Looking Around

The Windows Mobile (aka Windows CE) operating system is very similar to its desktop Windows (95/98/NT/2000/ME/XP) counterpart. It is an event driven, multitasking and multithreaded
environment. In fact, the Windows Mobile API can be described as a subset of the desktop
Windows API. This makes porting many desktop Windows applications to Windows Mobile a
fairly straightforward task. Anyone who has experience developing for desktop Windows will feel
at home developing for Windows Mobile.

Looking at our helloworld.cpp we see the following functions: WinMain, WndProc, InitInstance,
InitApplication. Lets briefly look at these functions and the purposes they serve.
(If you chose a Pocket PC project instead of Smartphone you may have some different functions.
This is because the Pocket PC version of Windows Mobile has some additional code to handle
the creation of menus and icons.)

  • WinMain
    • This is the main entry point for Windows Mobile programs. In fact, all software written
      for any version of Windows must have a WinMain.
    • WinMain's job is to handle the initialization and setup of the window and its message
      loop.
  • WndProc
    • WndProc is used by the OS to send events/messages/commands to your program.
    • You will receive these messages when your program needs to respond to an event
      caused by either the user or the operating system. (i.e. WM_PAINT means you need
      to repaint the contents of your window. WM_KEYDOWN means that the user pressed
      a button down.)
  • InitInstance
    • This is the function that creates the window and displays it.
  • InitApplication (aka MyRegisterClass in Windows desktop and Pocket PC)
    • This is called before InitInstance and sets up the properties of the window that is to be
      created by InitInstance.
    • It registers the window so that it can be created and receive messages.

Get the source code for this tutorial here

 

Previous: Part 0 -- Next: Part 2

Return to Tutorials Index

 

Back to Kicking Software

Copyright © 2006-2007 Kicking Software. All rights reserved.