|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
GUI Uniform Platform Makes Life Easier for Developers
Uniform Platform Makes Life Easier for Developers
Mar. 27, 2003 12:00 AM
With the .NET Compact Framework Microsoft released a uniform development platform for the development of desktop and Pocket PC applications. This new platform should make life much easier for the Pocket PC developer by offering a uniform Visual Studio .NET development environment. Based on eTrainSoft, a mobile training data acquisition application for the Pocket PC, this article shows how to develop mobile GUI applications using the .NET Compact Framework, with a special focus on the GUI and data synchronization aspects. This project was part of a larger project in the context of mobile training acquisition and analysis for professional athletes. The Compaq iPAQ is used for mobile training data acquisition for professional triathletes. This data is transferred to a PC in a well-formed and valid XML data file. The task of this project was to develop a sophisticated GUI application on the Compaq iPAQ 3970 with the .NET Compact Framework using C#. The application should be easy to use, taking advantage of the GUI capabilities of the .NET Compact Framework. In the project we used the first .NET Compact Framework beta, but this article will also reflect the changes with the new VS.NET 2003 beta. The article assumes that you are already familiar with the VS.NET IDE and the design of GUI applications; it will highlight some details that are important for .NET Compact Framework GUI development (and others), rather than giving you an introduction to GUI development with VS.NET.
The .NET Compact Framework A very new feature compared to former versions is the bytecode compatibility of both frameworks. That means that .NET Compact Framework assemblies can be run seamlessly on the PC and on the small device, as long as no GUI and no special .NET Compact Framework classes are used. The same is true vice versa.
The Application The data is transferred to a PC in a standard XML data file, which can be used for further analysis on the PC. In the next step, we synchronize the data with a central data server using Web services.
Smart Device Extensions Figure 1 shows the Smart Device Application Wizard, which allows the creation of SDE for VB.NET and C#; C++ and J++ are currently not supported. The Wizard distinguishes between "Windows CE" and "Pocket PC" platforms and allows the creation of four different project types for each platform.
The project can be run directly on a connected device. If the .NET environment is not yet installed, it will be deployed automatically. By default, the project assembly and any other required files will be deployed into the Windows folder. However, I recommend setting the "Output File Folder" in the project settings to another folder, for example, a custom subfolder of the "Program Files" folder (which is the standard on desktop installations). In the eTrainSoft application we took advantage of the bytecode compatibility and developed a common business logic assembly that runs on the Pocket PC and on the Desktop PC for data synchronization. We needed only to add the assembly to the project as a reference. During development it is also recommended to add the "System.SR" component to device projects. With this component, exceptions will be a bit more verbose. To save memory on small devices, most exceptions do not contain detailed descriptions. The System.SR dll contains the complete string resources for the exceptions. When a project is distributed, this dll is generally not included.
The Emulator To run the emulator, the TCP/IP protocol must be installed on the operating system of the development computer. If your PC is connected to the network, you will have installed TCP/IP and need do nothing else. Otherwise you have to install the Microsoft Loopback Adapter. To deploy your application to the emulator, you must select Pocket PC Emulator in the Device Extension toolbar of VS.NET, as shown in Figure 2. Using the Connect to Device button and the Deployment Device dropdown list you can start the emulator without downloading and running the project. Using the emulator also has a few disadvantages. First, there is no way to get a connection via ActiveSync. This means that you cannot synchronize and exchange files with the virtual device. To transfer a file to the emulator, you must first add it to the VS.NET project you are going to deploy. Then you change the Build Action file property of the file to Content. With the next deployment, the file will be downloaded to the program directory. Second, although the emulator itself computes quickly, the graphical user interface is slower. Finally, the memory of the emulator is limited to 16MB. So although the emulator is a very useful development tool, it cannot replace real hardware.
Device Controls Table 1 lists all of the controls for standard .NET Framework for Windows applications and highlights those that are also available in the .NET Compact Framework. Note: the InputPanel control, which stands for the keyboard on the Pocket PC is, of course, only available for the .NET Compact Framework. A lot of controls have been added to the .NET Compact Framework since the beta. Controls we were missing in our project include the OpenFileDialog and SaveFileDialog. Also now available is DataGrid-Control, which is very handy. While some controls can be omitted without any problems or even don't make sense for the .NET Compact Framework, the omission of others is painful and there is no particular reason why they are not available. In this category are the DateTimePicker control and the MonthCalendar control. Both were heavily missed in our project especially since both were available in the Windows CE operating system. According to older articles both controls (together with even more) were expected to be available, but haven't yet been implemented unfortunately. In our eTrainSoft application date selection is necessary because it is used as a navigation element. The user should be able to query for and edit the training data on a per-date base. Since neither control was available, we found a wrapper from Tim Wilson that creates the control through system calls during runtime. Although this solution works fine, it has one major drawback; the control doesn't yet support event-handling, since handling of Windows Messages wasn't documented at that time. At MSDN there is now documentation available about how to handle Windows Messages in the Compact Framework. So to be able to recognize user inputs, the application continuously polls the DateTimePicker this will eventually be replaced with a proper solution.
The eTrainSoft GUI We used the tab control for our two main views, the daily and weekly training session overview. Figure 3 shows the daily overview of the training session of the athlete. The control always places itself at the top, independent of the tab settings, and uses the complete window size. We placed the tabs at the bottom row. You can enforce the tab control behavior using a Panel. We noticed other restrictions on the controls. The text of a label can only be aligned to the top. The image in a picture box cannot be scaled. Sometimes it is simpler to write your own control. This is fairly straightforward; you just derive your class from the class Control and overwrite the OnPaint method. This method receives the PaintEventArgs object, which, among others, contains a Graphics object. You can now use this Graphics object to draw, write, and insert pictures into your GUI. Any Control in eTrainSoft, that shows a data record is implemented this way.
GUI Manipulation
Forms The menu is always at the bottom and works only with Pocket PCs. The input panel symbol is always automatically shown to the right side of the menu bar. If only the input panel is needed, you can add it with an empty menu bar. If you set the WindowState property on the form to Maximized and you do not have a menu, the title bar with the start menu also disappears and you have full-screen form.
Single Program Instances The Application.Run method catches all exceptions and rethrows them; dealing with this is laborious for developers. They do not know where the exception happened and have to discover the error through other means, as this information is not part of the exception. As a conclusion, you can handle nearly all GUI tasks with the .NET Compact Framework, but you have to do a little bit more work than you would using the standard .NET Framework.
Data Synchronization with the Desktop You can develop your own ActiveSync Service Provider. This method is the most user-friendly, as the synchronization takes place in the well-known ActiveSync environment. You can also configure and automate the synchronization therein. To achieve this, you must implement your synchronization logic in COM objects with a given interface. On the .NET Compact Framework this cannot be implemented without a major additional effort. RAPI allows you to remotely make system calls on the Pocket PC from Windows. This API is not (yet) part of .NET, but you may easily include it via DllImport or wrappers from the Internet. For eTrainSoft we used this technology to read the data from an XML file to the desktop computer. After synchronization the updated data is written back the same way. As an alternative to manually starting synchronization, you can configure the synchronization to be automatically started after an ActiveSync procedure. To achieve this, the eTrainSoft synchronization tool has to be registered in the Registry under HKEY_CURRENT_USER\Software\Microsoft\Windows CE Services\End Callback. Active-Sync starts this program after the synchronization. However, a problem arose from the fact that files were used as a persistent data store on the Pocket PC. If the Pocket PC application is running (and has loaded the content of the file into memory) during the synchronization, the synchronization will change the content of the file without notifying the running application. So the next save of the eTrainSoft application would overwrite the just-synchronized data. We solved this problem by starting a TCP server to the local loopback interface on the Pocket PC. After a connection, the program locks the file internally for a few seconds. Each new connection renews the lock. After a timeout the XML file is reimported into the application. The synchronization tool regularly starts a little program that opens the requested TCP connection. Another option would be to use SQL Server CE. This allows synchronization via a network and IIS to a SQL Server. In this case you do not have to write an extra piece of software. ActiveSync may also synchronize a Pocket Access database, but unfortunately there are no .NET drivers for Pocket Access at the moment.
Summary To allow productive use the Compact Framework still needs to mature a bit more, mainly in the area of GUI programming (e.g., missing date controls). Some important features for Pocket PC programming, such as support for synchronization and single program instances, should be offered in the future. Smart Device Extensions is fully integrated into Visual Studio and needs no other IDE such as eMbedded Visual C++. The integrated documentation has one major disadvantage. Developers have to filter the relevant information from the complete .NET documentation. A separate documentation of the .NET Compact Framework class libraries would be more practical. Despite the optimization for minimal resource usage, you have to pay tribute to .NET and the JIT compilation. The eTrainSoft .NET application uses more than 2MB RAM even if it is not very feature rich. Nonetheless, .NET's benefits of easier programming and hardware-independent assemblies outweigh this disadvantage.
References Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||