The Code Samples

< BACK  NEXT >
[oR]

Throughout the book you will find code samples showing how to use the facilities being discussed. All the code is on the CDROM, so it can be copied directly into your application. Unless otherwise stated, all the code is in a single project called examples.vcp in the directory \examples. The source code isarranged by chapter, and each chapter has its own source file, for example Chapter2.cpp, Chapter3.cpp, and so on.

The examples.exe application can be run on a real device, or under emulation. The user interface has been optimized to run under Pocket PC, but can easily be adapted to run on other platforms. The menu contains drop downs for each of the chapters arranged into groups, and the drop downs contain menu items allowing each code sample to be run. Figure 1.3 shows how the application looks, with sample output. No prizes for best user interface here! Note that not all the sample code will run on all platforms. In particular, some samples will not run under emulation.

Figure 1.3. Examples application used to run sample code
graphics/01fig03.gif

The code samples are designed to remove all irrelevant code so you can concentrate on what is really important. In the Examples project, all output is displayed to a read-only edit window (which, in Figure 1.3, contains the text "Mounted vol: SystemHeap" and so on). A C++ class object called "cout" has been created to emulate the basic behaviors of the standard C++ "cout" object used in command line, character mode applications. The "cout" object is an instance of the class COutput which is declared in Examples.h and implemented in InputOutput.cpp. The "<<" operator has overloads for most common data types, including strings, integers, and characters. Calling the COutput"CLS" method removes all the text from the text edit window. You will find statements like the following to display data to the edit window:

 cout << _T("Unicode File") << endl; 

Input is obtained from the user in a dialog using the function GetTextResponse. The function is passed the string to prompt the user with, a string in which the data will be returned as well as the maximum number of characters of data that can be placed in the string. The function returns TRUE if a string is returned, or FALSE if the user pressed Cancel.

 if(!GetTextResponse(_T("Enter URL to Display: "), szURL, MAX_PATH))    return; 

The function GetFileName will display a File Open command dialog box allowing the user to select a file. This function takes the same arguments as GetTextResponse:

 if(!GetFilename(_T("Enter filename:"), szFilename, MAX_PATH)) return; 

Some of the sample code is in separate projects, and because some of these projects run on a desktop PC, the projects should be compiled using Visual C++ 6.0.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net