Chapter 1 Buiding a PocketC App
Chapter 2 A few examples
Chapter 3 Language Description
Chapter 4 Creating User Controls
Chapter 5 Function Library Reference --> http://www.orbworks.com/cedocs/ceindex.html
Chapter 6 Underconstruction ...
Building a PocketC Application
Split a program into multiple files
<--Next Chapter--> <--Back to Top-->
PocketC's development has received many people's help.
Some of their sample source code, and custom API are included as part of our manual.
Grahpic user interface controls
<--Next Chapter--> <--Back to Top-->
sayhello1() { putsl("Hello World"); showconsole(); }sayhello2() { text(50,50,"Hello World"); }
sayhello3() { alert("Hello World"); }
main(){sayhello1(); sayhello2(); sayhello3();}
Method 1: write it out in the console window, and show console window
Method 2: write it on the main window, through text() function.
Method 3: pop an alert box with Hello World as the message.
Splite a large file into multiple smaller files
For example:
main() {
string myname; int myage; int userage;
myname = "Kevin Cao"; myage = 22;
showconsole();
puts("Welcome to PocketC "); /* puts will not add a newline at the end */
putsl(" , " +" Written by " + myname); /* putsl will add a newline at the end */
userage = (int) gets("How old are you?");
putsl("You are " + userage + " and Kevin is " + myage);
}
The main applet window is just like drawing board, you have tools to draw cicles, lines, rectangle, ecllipse and text.
text(int x, int y, string str) --- display a string str at
locations (x,y)
line(int x1, int y1, int x2, int y2) --- draws a line from (x1, y1) to
(x2, y2)
rect(int x1, int y1, int x2, int y2) --- draws a rectangle from (x1, y1)
to (x2, y2)
roundrect(int x1, int y1, int x2, int y2, int cx, int cy) --- draws a
round rectangle from (x1, y1) to (x2, y2) with round corner (cx,cy)
circle(int x, int y, int r) --- draws a circle center at (x,y) with
radius r
ellipse(int x1, int y1, int x2, int y2) --- draws an ellipse from (x1,
y1) to (x2, y2)
For Example:
main() {
text(30,50, "helloworld");
rect( 25,25,50,50);
ellips(40,40,80,90);
}
There are a great amount of functions dedicated to the drawing system.
The best way to learn is to write a few applets.
PocketC offers a variable type string that is missing from the old wonderful C. In PocketC, string is treated as a single variable.
For example:
string myname, yourname; myname = "Kevin Cao"; yourname = "Unknown"; yourname = myname;
In the traditional C, you can do following:
char myname[] = "Kevin Cao"; char yourname[] = "Unknown"; strcpy(yourname,myname);
which way makes more sense to you?
Personally, I am use to the traditional C. It doesnot matter.
However, I think many new programmers would perfer string as a
seperate variable. It is more intuitive.
PocketC >> C One step further
(Good or Bad?)PocketC's variables are losely typed. Each type can be freely type casted into another type.
Same as before, we hope our PocketC makes programming fun and easier.
DIALOG: Sends and receives characters through the serial port.
PocketC has functions that allow you to transfer data through WinCE serial port API.
Pascal Favre has contributed part of his serial I/O code
publicly. Thanks!
------------------------------------------------------------------------
// 09 / 10 /1998 Version 1.00 by Pascal Favre.
// DIALOG. Establish the Rx - Tx dialog between the serial port of the HPC and any
external device.
// Copyright (c) 1998 by Pascal Favre.
//
// License is granted to you to use and modify this code only under the following
conditions:
// 1. You are a registered user of Orbworks Pocket C.
// 2. You agree not to hold Pascal Favre liable for any damages caused by the use or
misuse of this code.
// 3. You agree to make any modifications of this code freely available to registered
Pocket C users.
// This function allows you to send and to receive strings to / from any external device
// connected to the serial port.
// Remarks:
// 1. before it is sent, the command string is CAPITALIZED. This is a constrain that
applies to most dataloggers or //Hayes-compatible modems.
// 2. before returning, this function waits at most 1 second for an incoming character.
Timer number 10 is used for that purpose.
// Otherwise the time lapse between two incoming characters is set to 1/5 second.
// 3. the eventual sequences <CR><LF> at the beginning and / or at the end of
the received string are removed before //returning.
// 4. the event with an ID equal to 99 is tested. It is good practice to define it as an
"Exit" button, because it allows a return
// immediately from the while { } loop.
// 5. the function returns the string received by the serial port.
dialog(string cmde)
{
int i;
string rep;
if(strlen(cmde))
{
strupr(cmde);
for( i=0; i<strlen(cmde); i++ )
sersend( (char) strmid( cmde, i, 1) );
}
rep = "";
settimer(10,1000);
while(1)
{
if(serdata())
{
killtimer(10);
rep = rep + serrecv();
settimer(10,200);
}
i=event(0);
if(((i == PM_TIMER) && (timerid()==10)))
break;
else if(((i==PM_COMMAND) && (guiid()==99)) || (i==99))
{
postevent( 99 );
break;
}
}
killtimer( 10 );
if(strleft(rep,2)=="\r\n")
rep=strright(rep,strlen(rep)-2);
if(strright(rep,2)=="\r\n")
rep=strleft(rep,strlen(rep)-2);
return(rep);
}
GRID user interface API By Jim Burton
GRID: provides an easy way to create resolution-independent user interfaces for Pocket C programs. You can draw on the screen and place User Interface objects knowing that they'll look good on any size Win CE handheld screen.
visit http://www.burtcom.com/pocketc/
for the latest GRID
Grid accomplishes this by providing new versions of all screen functions (as of Pocket
C version 1.28). These work the same as the built-in functions except they accept X screen
coordinates from 0 to 1000 (0 represents the leftmost side of the screen, and 1000 is the
rightmost edge) and Y coordinates from 0 to 1000 (0 is the top and 1000 is the bottom of
the screen). Each Grid function calculates the real screen coordinates based on the
current resolution, then calls the corresponding built-in routine. Grid functions are
named the same as the built-in functions, except they are preceded with "g_".
Example:
Lets say you want to place the word "middle" in the center of a screen and you
don't have the Grid functions. If your screen resolution is 640 by 280 you would normally
use:
text (320, 140, "middle");
But what if one of your users had a machine with a resolution of 600 by 200? You'd have to
make a version of your program with the code:
text (300, 100, "middle");
Using the Grid routines, the only code you need is:
g_text (500, 500, "middle");
And this would place the text in the center of the screen no matter what resolution the
user is using.
What you get:
NEW
textbox(string,x,y,w,h,align,mchar);
g_textbox(string,x,y,w,h,align,mchar);
Textbox (and the corresponding Grid version) is a new routine that draws
a text string that fits within a defined box. The string is automatically sized to take up
the entire area of the defined box unless you use the alignment feature. You should note
that this routine sets text to a non-proportional font (Courier) because there is
currently no way to calculate the pixel length of text in a proportional font. The
arguments are:
string - the string to be drawn x - the x coordinate of the
upper-left corner of the textbox y - the y coordinate of the upper-left corner of
the textbox w - the width of the text box, in pixels h - the heigth of the
text box, in pixels align - could be one of three values:
0 - the string is aligned to the left of the box 1 - the
string is aligned to the center of the box 2 - the string is aligned to the right of
the box
mchar - set this to a number higher than the number of characters
in your string if you want to use the alignment feature. Otherwise set it to 0 and the
text is justified to take up the entire defined box.
MOUSE POSITION
g_mousex();
g_mousey();
These report the X and Y positions of the last mouse event in virtual Grid coordinates.
Therefore, if the pen was touched in the exact middle of the screen, g_mousex() would
return 500 and g_mousey() would return 500.
The following routines take the same arguments as their Pocket C counterparts, except they
accept Grid coordinates. Please see the Pocket C documentation for descriptions of the
arguments.
SCREEN DRAW
g_rect ( x1,y1,x2,y2);
g_roundrect ( ax,ay,bx,by,cx,cy );
g_ellipse ( x1,y1,x2,y2);
g_circle ( x,y,r);
g_line ( x1,y1,x2,y2);
g_text ( x,y,string);
g_drawbitblt( file, x, y, bit);
g_drawbitmap( file, x, y);
g_getpixelB( x, y);
g_getpixelG( x, y);
g_getpixelR( x, y);
g_setpixel( x,y);
Installation:
To install these routines, simply paste them into your program, or better yet, save them
as a file called "grid.pc" and use an "include" statement in your
program. For example, if you save grid.pc into a folder called "Include" you
would place the following line into your program:
#include "\\Include\\grid.pc"
Download the Zipped version, grid.zip
The language is very similar to standard C in syntax, but has a different feature set. Most notably, there are no pointers, no structs, and no preprocessor. A string data type has been added, and values are somewhat loosely typed. The next section is for those who are already somewhat familiar with C.
There are four types in PocketC: integers (int), floating point numbers (float), characters (char), strings (string), and single-dimensional arrays.
An expression consists of any number of variables, function calls, and constants of any type, joined by operators and parentheses. Thus, the following expressions are valid:
3 + 5 6.7 + 23 "Hello " + "World" 5*3 + foobar()
When an expression contains values of different types, the two values are first cast to the same type, and then the operator applied. For example in the following expression:
5.7 + 8
The 8 is first cast to a float (8.0), and the two numbers are added (5.7 + 8.0). This becomes slightly more interesting when we use strings. For example:
"The result is " + (5 + 8)
5 is first added to 8, resulting in 13. The 13 is then converted to a string, and appended to "The result is " resulting in "The result is 13". However,
"The result is " + 5 + 8
would result in "The result is 58", since the the 5 is first converted to a string, then appended to "The result is "...
Of course, explicit casting is possible:
56 + (int)"7"
evaluates to 63.
The following operators are provided (in order of precedence, with associativity):
Operator | Assoc | Description |
---|---|---|
= | right | assigns the value of the expression on the right to the variable on the left. |
|| | left | logical or, returns 0 if false, 1 if true |
&& | left | logical and |
== != < <= > >= | left | relational operators |
+ - | left | addition, subtraction |
* / % | left | multiplication, division, modulus |
- ! ++ -- | left | unary operators |
Note: No shortcut logic is performed on the operands of || and &&
Note2: The +=, -=, *=, etc. operators are not supported.
The following statements are fully supported: for, while, do, switch, case, break,
continue, if, then, return, .
Note: for requires a condition expression (i.e. for (;;) is not
legal, instead, use for (;1;) or while (1))
Example:
// My large applet #include "Part1" #include "Part2" main() { // call functions defined in other memos }
There are two ways to add special characters to a string. The first is by appending them by number, such as:
str = "Here is a neat little square: " + (char)149;
The other method is through using escape sequences. The following escape sequences are supported:
Escape sequence | \\ | \' | \" | \n | \r | \t | \x |
---|---|---|---|---|---|---|---|
Interpretation | \ | ' | " | newline | return char | tab | character specified by the following two hex digits. Example: '\x95' is the block character (decimal 149) |
Graphic user interface controls
Function:
createctrl(string strCtrl, string strName, int nStyle, int xpos, int ypos, int width, int
height, int nID);
For Example: createctrl("BUTTON",0,WS_VISIBLE|WS_CHILD,0,10,30,60,35,300);
With PocketC, users are able to create popup menu without knowning anything about
windows menu COMPLEX structure.
For example: if you want to create a popup menu with following City names
Chicago |
Cleveland |
----------(separator) |
NewYorkCity |
You need to assign an integer to each city. When user clicks on one of the city name, the menupop function will return the selection menu ID.
In our case:
menupop("Chicago|40030|Cleveland|40031|---|0|NewYorkCity|40032"));
Chicago|40030 means a menu item's string is Chicago, and its value is 40030
---|0 means a separator with value 0
Each menu entry is separated by character |
The menupop function will return the user selection. If the user selects nothing, it returns 0.
Chapter 4 Creating User Controls
Due to the complexity of Win32API, we provide a very brief documentation to windows user interface programming. If you wish to understand each control style's meaning and usage, please consult Microsoft's documentation. visit http://msdn.microsoft.com for detail.
Button control can become a button, a checkbox or a radio, by using different control style when you call createctrl() function.
button | createctrl("BUTTON",0,WS_VISIBLE|WS_CHILD,0, x_initial,y_initial,width,height,ID); |
checkbox | createctrl("BUTTON","", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP,0,x_initial,y_initial,width,height,ID); |
radio | createctrl("BUTTON","", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,0,x_initial,y_initial,width,height,ID); |
WS_VISIBLE it is a style you have to use to make your control visible when you call createctrl(), otherwise your control will be invisible until you call wndshow()
WS_CHILD makes your control as a child window of the main window
WS_TABSTOP ensure your control is on the tab stop list
BS_AUTOCHECKBOX make your control a checkbox
BS_AUTORADIOBUTTON make your control a radio button