[ Win32 CE API Programming for Smartphone HOME | TrajectoryLabs ]

The Simplest Win32 CE Program


Introduction

Keeping with tradition, your first program on the Windows Mobile Smartphone will be a  "Hello World" program.  Console programming is not supported on the Smartphone, so this will be a true Windows GUI based application.

Make a project

Create a new Pelles C empty WinCE Smartphone Program (EXE)  project. Paste the following code into an empty source code page and add it to your project. Compile then execute the code on your device.  
#include <windows.h>


int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow)
{

MessageBox (NULL, TEXT ("Hello World"), TEXT ("Hello"), MB_OKCANCEL | MB_ICONEXCLAMATION);
return 0;
}

messagebox

Your first Windows CE application running on the Motorola Q Smartphone.


Code review

#include "windows.h"
A master include file which contain other Windows header files that are necessary to use the Windows API. 
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow)

WinMain()
is the windows equivalent of the C standard  main(). This is the main entry point of your program.

PASCAL specifies the calling convention. PASCAL is an older term for Windows default calling convention (from the 16-bit days), also used by almost all Windows API  functions. Today it's probably more common to see STDCALL or WINAPI, but the result will be the same.

The parameters are as follows:
HINSTANCE hInstance
Identifies the specific instance of the program to other programs and the system.

HINSTANCE hPrevInstance
Left over from the old Win16 API. Always NULL for Win32 programs and can be ignored.

LPWSTR lpCmdLine
Used for command line parameters when launching the program.

int nCmdShow
Specifies how the window is to be shown. This parameter in Windows CE can be one of the following values:
SW_SHOW Normal.
SW_HIDE Hidden.
SW_SHOWNOACTIVATE Show without activate.


MessageBox (NULL, TEXT ("Hello World"), TEXT ("Hello"), MB_OKCANCEL | MB_ICONEXCLAMATION);
The MessageBox() functon is used to display simple message windows and retrieve basic input. This function is highly configurable with many different styles.


return 0;
Finally the program ends with return(0).




Copyright © Christopher Hill (Trajecto). All rights reserved.