Modifying the App
At this point, I have a completed project that contains the two classes created by the wizard. As I mentioned, it's been awhile since I worked with Visual C++, but I was pleasantly surprised to find that the "starter" code looked exactly like the MFC code I was used to: The App class contained the constructor and InitInstance() functions and the Dialog class (which extends the MFC CDialog class) contained the standard DoDataExchange() and OnInitDialog() functions. As Figure 2 shows, the IDE allows the developer to choose the target Windows CE platform, microprocessor, and device. It also includes the standard VC++ dockable toolbars and windows (including the highly useful Workspace window, which contains the ClassView, ResourceView, and FileView tabbed panes for managing the current project).
Figure 2 The StatCalc project.
The following additional tools are available:
ClassWizardused to create message mapping between class events and handler functions and also manage class member variables.
Source Browserused to present alternate views of the source code in the project. Sample queries include Definitions and References, File Outline, Base Classes and Members, and Call Graph.
Windows CE versions of the standard Windows SDK tools, including Spy++, Registry Editor, Heap Walker, Process Viewer, Zoomin, File Viewer, and Error Lookup.
Debugger that supports breakpoints, watch statements, and code stepping.
Macro record and playback to automate oft-repeated tasks within the development environment.
Using the powerful Visual C++ resource editing tools, you can modify application resources (such as the StatCalc dialog) in order to build the GUI (see Figure 3).
Figure 3 Editing the StatCalc dialog.
For this example, I added a number of components to the existing CStatCalcDlg dialog. Along with these components, I added an event handler to trap the Add! button click. When this button is pressed, the number entered in the value text box is added to the list box below. At the same time, the mean and standard deviation values are calculated and the display is updated, thanks to code generated for me by the IDE's ClassWizard. To perform this operation, I created the displayMean() and displayStdDeviation() functions. The listing below shows the button click message handler and these two new functions (along with a calculateMean() helper function).
void CStatCalcDlg::OnValueButton() { UpdateData(TRUE); // Add value to list m_ListValues.AddString(m_Value); //Perform calculations displayMean(); displayStdDeviation(); UpdateData(FALSE); } double CStatCalcDlg::calculateMean() { int numValues = m_ListValues.GetCount(); double sum = 0; CString tempStr; // Iterate through the list and calculate // the arithmetic mean. for (int i=0; i < numValues; i++) { m_ListValues.GetText(i, tempStr); sum = sum + _tcstod(tempStr, 0); } return (sum / numValues); } void CStatCalcDlg::displayMean() { m_LblMeanValue.Format( _T("%.1f"), calculateMean()); } void CStatCalcDlg::displayStdDeviation() { double mean = calculateMean(); int numValues = m_ListValues.GetCount(); double sum = 0; CString tempStr; // Iterate through the list and calculate // the standard deviation. for (int i=0; i < numValues; i++) { m_ListValues.GetText(i, tempStr); sum = sum + pow((_tcstod(tempStr, 0) - mean), 2); } m_LblStdDevValue.Format( _T("%.1f"), sqrt(sum / numValues)); }
Figure 4 shows the app running in the Palm-Size PC 1.2 emulator.
Figure 4 The StatCalc application.
eMbedded Visual C++ stacks up very well against its desktop counterpartparticularly when you consider that it's free! As I've mentioned, much of the functionality is identical to "standard" Visual C++ and the documentation does a good job of specifying which MFC/ATL classes have changed for the Windows CE tool. If you're new to Windows CE and have decided that C++ is right for your project, eMbedded Visual C++ is clearly the tool of choice. Developers with existing Visual C++ experience will be effective immediately, although it's recommended that you spend some time up front identifying the API differences between Win32 and WinCE. In my next article, I'll build the same app using eMbedded Visual Basic and will discuss the strengths and weaknesses of that product.