It's Still Windows Programming
While differences between Windows CE and the other versions of Windows do exist, they shouldn't be overstated. Programming a Windows CE application is programming a Windows application. It has the same message loop, the same windows, and for the most part, the same resources and the same controls. The differences don't hide the similarities. One of the key similarities is the tradition of Hungarian notation.
Hungarian Notation
A tradition, and a good one, of almost all Windows programs since Charles Petzold wrote Programming Microsoft Windows is Hungarian notation. This programming style, developed years ago by Charles Simonyi at Microsoft, prefixes all variables in the program usually with one or two letters indicating the variable type. For example, a string array named Name would instead be named szName, with the sz prefix indicating that the variable type is a zero-terminated string. The value of Hungarian notation is the dramatic improvement in readability of the source code. Another programmer, or you after not looking at a piece of code for a while, won't have to look repeatedly at a variable's declaration to determine its type. Table 1-1 shows typical Hungarian prefixes for variables.
Variable Type | Hungarian Prefix |
---|---|
Integer | i or n |
Word (16-bit) | w or s |
Double word (32-bit unsigned) | Dw |
Long (32-bit signed) | L |
Char | C |
String | Sz |
Pointer | P |
Long pointer | lp |
Handle | h |
Window handle | hwnd |
Struct size | cb |
You can see a few vestiges of the early days of Windows. The lp, or long pointer, designation refers to the days when, in the Intel 16-bit programming model, pointers were either short (a 16-bit offset) or long (a segment plus an offset). Other prefixes are formed from the abbreviation of the type. For example, a handle to a brush is typically specified as hbr. Prefixes can be combined, as in lpsz, which designates a long pointer to a zero-terminated string. Most of the structures defined in the Windows API use Hungarian notation in their field names. I use this notation as well throughout this book, and I encourage you to use this notation in your programs.