.Net Compact Framework Programming with C# (Microsoft .Net Development Series)

Overview

“For nearly two decades, Paul Yao and David Durant have been acknowledged as experts on the Windows platform, so it’s only natural that they would bring their experienced point of view to the .NET Compact Framework. With a unique combination of historical perspective and in-depth understanding of the subject matter, Yao and Durant take the reader through not only the technical guts of the Compact Framework but also the reasons behind the design decisions.”

—Joshua Trupin, Executive Editor, MSDN Magazine

“Yao and...
See more details below
Paperback
$46.75
BN.com price
(Save 33%)$69.99 List Price
Other sellers (Paperback)
  • All (15) from $1.99   
  • New (7) from $45.12   
  • Used (8) from $1.99   
Sending request ...

Overview

“For nearly two decades, Paul Yao and David Durant have been acknowledged as experts on the Windows platform, so it’s only natural that they would bring their experienced point of view to the .NET Compact Framework. With a unique combination of historical perspective and in-depth understanding of the subject matter, Yao and Durant take the reader through not only the technical guts of the Compact Framework but also the reasons behind the design decisions.”

—Joshua Trupin, Executive Editor, MSDN Magazine

“Yao and Durant have written a book that, although it assumes no prior experience with the .NET Framework, serves both the rookie and advanced programmer equally well. This is definitely a rare quality among technical books and is certainly not an easy thing for an author to accomplish.”

—Doug Holland, Precision Objects

“This is a very good hands-on book with plenty of sample code illustrating programming tasks and techniques, which any serious development effort for Windows CE or Pocket PC will require.”

—Bill Draper, Director of Software Development

“This book serves as both a great reference and tutorial when building .NET Compact Framework applications. My only wish is that it had been available sooner.”

—Greg Hack, Senior Software Engineer, Allscripts Healthcare Solutions

“Of the handful of books on Compact Framework, this book takes the cake. Paul Yao and David Durant’s expertise with .NET Compact Framework is evident from their excellent and very insightful coverage of sections such as Building the User Interface, Managing Device Data, and Creating Graphical Output. The chapter discussing the topic of P/Invoke is unparalleled. After reviewing this book, I am certain that if there is one book that will help you understand .NET Compact Framework, this is the one.”

—Deepak Sharma, Senior Systems Specialist, Tata Infotech Ltd.

“Yao and Durant’s fresh, innovative, and in-depth look at the .NET Compact Framework gets developers up to speed using C# to develop robust and scaleable handheld software solutions. A definite must-read for mobile handheld developer enthusiasts!”

—Andrew Krowczyk, Software Architect, Zurich North America

.NET Compact Framework Programming with C# is the definitive tutorial and reference for the .NET Compact Framework (CF). It shows you how to transfer your skills and your code to the Pocket PC 2003 and other mobile and embedded smart devices.

Authors Paul Yao and David Durant draw upon their years of research and experience with members of the Microsoft .NET CF team to show you exactly how the best CF programming gets done in C#. This is the only book a programmer needs to master the art of CF coding. Throughout the book, sample code and examples illustrate best practices and programming techniques. In addition, the companion Web site includes downloadable code for all these examples, along with a set of development tools to help you with your CF development projects.

The authors expertly zero in on what programmers need to understand for successful smart device programming, including:

  • Garbage Collection in the .NET Compact Framework
  • Controls and supported Properties, Methods, and Events (PMEs)
  • Custom controls with Windows Forms Designer support
  • Using Platform Invoke (P/Invoke)
  • Simple and complex data binding and the DataGrid control
  • Programming with ADO.NET data classes
  • Synchronizing SQL Server CE with SQL Server 2000 databases
  • Creating graphical output, including font and printing coding tricks
  • Differences between the standard desktop framework and the CF

.NET Compact Framework Programming with C# is your single resource for everything you really need to know about CF programming.

Read More Show Less

Editorial Reviews

From The Critics
Derek Ferguson, .NET Developer's Journal
I take it with me into every introductory class that I give on the .NET Compact Framework. I have found that, in general, I know the answers to just about every question I get asked in such classes - but not all of them! In the cases where I can't, I simply wait for a break, then page through this book to find the answer - I've never been disappointed - I have always been able to find the answers here.
Read More Show Less

Product Details

  • ISBN-13: 9780321174031
  • Publisher: Addison-Wesley
  • Publication date: 5/28/2004
  • Series: Microsoft .Net Development Series
  • Pages: 1379
  • Sales rank: 448,646
  • Product dimensions: 7.10 (w) x 9.10 (h) x 2.90 (d)

Meet the Author

Paul Yao is president of The Paul Yao Company, which provides educational and consulting services to software engineers on software technologies based on Microsoft Windows. He has authored/coauthored seven books on Windows programming, including with David Durant the first book published on the subject, Programmer’s Guide to Windows (Sybex, 1987). Paul is a contributing editor to MSDN Magazine, writing regularly on topics of interest to Windows CE and Pocket PC developers.

David Durant is principal of Durant Associates and lead author of the groundbreaking book Programmer’s Guide to Windows (Sybex, 1987), the first book published on the subject. David was an early proponent of .NET, is a frequent contributor to industry journals and forums, and leads seminars on .NET-based technologies for corporate clients worldwide.

Read More Show Less

Read an Excerpt

We feel pretty fortunate. During the past two decades, we have traveled the world teaching programmers what we know. The two of us have led many classes and together have taught thousands of smart, highly motivated software engineers, test engineers, and development managers. We enjoy working with the people who are inventing the future, and we enjoy being at the cutting edge of each successive wave of software development technology. We have learned much from the discussions we have had with these students. This book represents one way we can thank them for all their support.

We worked together on the first book published on the subject of Windows programming, Programmer’s Guide to Windows (Sybex, 1987). Long out of print, in its day the book helped many programmers tackle the challenges presented by Windows version 1.01. That version of Windows came out in November 1985, and in those days developers typically worked on computers running MS-DOS with no hard drive, no network support, and no network servers to rely on.

Things have changed a lot during the 17 years since our first book came out. A pocket-sized computer now has more memory and CPU power than the typical desktop system of the 1980s. A typical desktop system has more raw computing power than a roomful of computers had back then. With this increase in capacity has come a dramatically improved set of development tools available to software developers: Online programming references, context-sensitive help, and graphical editors all help support the task of software development. Programmers can be more productive today thanks to all these tools.

With this increase in computing power and tool support has also come an increase in the complexity of programming interfaces. While the .NET initiative provides a new set of programming interfaces that are better organized than any other Microsoft has created, it is still very large and very intricate. Given enough time, most programmers can master these intricacies. But most programmers do not have enough time to learn about a new technology while also building new software, yet that is what their employers require of them.

Our primary mission is to support you, the software engineer, in saving time. In this book, we distill many years of research and sample code to give you the information you need in a way you can use. We do the same thing in our training classes, in our magazine articles, and in the talks we give at conferences. We concentrate our efforts on helping software engineers become more productive. Time saved in learning about software development issues can be focused on meeting the specific needs of the end users whom you are supporting (or, perhaps, on taking some time off between projects to recharge your mental and physical batteries).

What You Need to Use This Book

To make the most of what this book has to offer, you are going to need a few things, as described in the following subsections.

Hardware

Software developers have historically had the fastest and most capable computer systems they could get their hands on. Developing for smart devices like the Pocket PC and the Smartphone is no different. To get started, we recommend you have the following:

  • Desktop system compatible with Microsoft Windows 2000 or Windows XP
  • Minimum 128MB RAM (256MB recommended)
  • Minimum 4GB hard drive (10GB recommended)
  • Windows CE-powered device (Pocket PC, Pocket PC 2002, Pocket PC 2003, Smartphone 2003, or other Windows CE-powered device)

Strictly speaking, you do not need a Windows CE device because you can run your software on an emulator that runs on your development system. You will, however, eventually want to test your software on real devices, the same ones you expect your users to use. The emulator technology is very good—more than good, in fact. Today’s emulators provide an excellent replication of the software on a device.1 But the hardware and associated device drivers are not going to be the same on an actual device as on an emulator running on a PC. This is the major cause of differences between an emulator and an actual device. When we teach our Pocket PC programming classes, we always recommend to participants that a major portion of testing be done on devices.

While the focus of this book is on writing code, the reality of software development is that you spend a lot of time debugging your code. For that reason, you want to remove anything that slows down your debugging. We suggest you invest in a network connection between your development system and your smart-device system, which means you need the following:

  • Network card (wired or wireless) for the desktop development system
  • Network card (wired or wireless) for the Windows CE-powered device
Software

The development tools can run on any supported version of Microsoft Windows. However, an emulator requires that you run on a 32-bit version of the operating system. This means you want one of the following:

  • Microsoft Windows 2000 (with Service Pack 2 or later)
  • Microsoft Windows XP Professional
  • Microsoft Windows Server 2003

With the right operating system in place, you can then use the software development tools. The first item in the following list is required; the other items are “nice-to-have” tools.

  • Microsoft Visual Studio .NET 2003 (required).
  • (Optional) Microsoft eMbedded Visual C++ 3.0 (for Pocket PC and Pocket PC 2002).
  • Microsoft eMbedded Visual C++ 4.0 (for Pocket PC 2003, Smartphone 2003, and later).
  • P/Invoke Wizard, available from The Paul Yao Company, for help in creating declarations needed to call native code from the .NET Compact Framework. (Learn more about this tool and download a demo version from http://www.paulyao.com/pinvoke.)
The Latest Version of the .NET Compact Framework

As we were finishing this book, Microsoft made available Service Pack 2 of the .NET Compact Framework. Should you upgrade to this latest version (or whatever later version might be available by the time you read this)? We must say yes! This is a new technology, and the .NET Compact Framework team is still working on improvements and upgrades to make the library work better and faster. After shipping a new library, the .NET Compact Framework team members—like most development team members at Microsoft—take a weekend or two off, and then their reward for their hard work is that they get to start all over again, working to create something even better. It’s a good thing that they like what they are doing—and that they are so good at it.

The Sample Code

You can download the code for this book from the following URL: http://www.paulyao.com/cdbook/code.

When you install the sample code directory tree from the Web site, you see four top-level directories.

  • ..\CS contains all the C# samples.
  • ..\VB contains all the Visual Basic .NET samples.
  • ..\CPP contains C/C++ samples.
  • ..\Tools contains binaries of useful tools.

Each of the .NET Compact Framework samples is available in two languages: C# and Visual Basic .NET. Some samples are written in C++, using the Windows API (also known as Win32).

Within the three samples directories (..\CS, ..\VB, and ..\CP) you find a directory for each chapter. Within each chapter directory you find another set of directories for all the samples in that directory.

For example, one of the samples in Chapter 5 is named “FormEvents.” The C# version is at this location: ..\CS\Ch05_CreatingForms\FormEvents. The Visual Basic .NET version is at this location: ..\VB\Ch05_CreatingForms\FormEvents.

The Target Audience for This Book

We wrote this book to help programmers with the .NET Compact Framework. We assumed that no prior programming experience with Windows 95/98/2000/XP, with Windows CE, or with .NET was required. At the same time, if you have experience with programming for Windows on the desktop, with Windows CE, or with the .NET Framework, that experience will help you.

For Programmers Experienced with Windows CE

If you already have experience writing Windows CE programs, you might be wondering if you even need to use the .NET Compact Framework. Whether you do or not depends on what tools you have been using and what type of work you expect to do.

If you have been using eMbedded Visual Basic (eVB) to write Windows CE programs, you are probably already aware that Microsoft plans to discontinue support for eVB. As of this writing, the Pocket PC 2003 supports eVB; that is the last platform to be supported. The .NET Compact Framework is a great replacement. It is well designed, and it provides Visual Basic programmers with support that puts them on a level playing field with C# programmers.

If you have been using the Microsoft Foundation Class (MFC) Library, the ActiveX Template Library (ATL), or the Windows Template Library (WTL), then the case for the .NET Compact Framework is still pretty good. Chapter 1 describes the .NET Compact Framework and its benefits. The new .NET programming paradigm provides many benefits for programmers who have worked with other frameworks. Getting involved with .NET Compact Framework programming is a great way to get into the world of .NET because the libraries are scaled back from the (sometimes) overwhelming number of classes and features found on the desktop .NET Framework. And there is an added bonus for making the move to the .NET Compact Framework: The fundamental elements of programming for the .NET Compact Framework programming are the same as the fundamental elements for all .NET-based technologies. So learning the .NET Compact Framework today will help you learn to build Web applications using ASP.NET, Windows Forms applications for the desktop, and managed-code stored procedures for Yukon (the code name for the next version of SQL Server).

If you have been using the core Windows API/Win32, then you might wonder whether to continue writing Win32 code or to jump into the .NET Compact Framework. For some things, including the following, you must continue using Win32.2

  • Fastest executables
  • Best real-time support
  • Source code portability between platforms
  • Ability to wrap Component Object Model (COM) for access by .NET Compact Framework applications
  • Ability to create device drivers
  • Ability to create control panel applets
  • Support for custom user interface skins
  • Support for security extensions
  • Ability to build Simple Object Access Protocol (SOAP) Web Service servers
  • Support for Pocket PC shell extensions
  • Ability to use existing Win32 code
For Programmers Experienced with the .NET Framework

If you are experienced with writing programs that use the .NET Framework, you are going to find much that is familiar. The C# and Visual Basic .NET languages, for one thing, use the same syntax for two very popular languages that are available for desktop .NET development. The fundamental data types that support interoperability between different languages on the desktop also play a core part of interoperability with smart-device programs.

One thing that may be surprising to desktop .NET Framework developers is the extent to which they might need to rely on P/Invoke support to call the underlying Win32 API functions that Windows CE supports. While the desktop .NET Framework provides an extensive set of classes that minimizes the need to call outside the framework, the .NET Compact Framework provides a reduced set of classes to meet the size constraints of mobile and embedded devices.

To help programmers move from the .NET Framework to the .NET Compact Framework, throughout the book we provide some detailed discussions of differences between the two frameworks. In the many workshops we have taught, we have observed the knowledge and skills of programmers who are experienced with the .NET Framework transfer quite readily to the .NET Compact Framework.

The primary challenge comes from an experience we refer to as “stubbing your toe”—tripping over a familiar desktop feature (whether a class, an enumeration, an attribute, or an operating system feature) that is not present on smart mobile devices. When this happens, you have found a limit on the support available in the .NET Compact Framework (or, perhaps, a limit on the support of the underlying Windows CE operating system). The attitude you take in dealing with such experiences will play a big role in determining how successful you are in .NET Compact Framework programming—and how enjoyable you will find it. We have observed that the programmers who excel with device development are the ones who are able to see in these limitations an enticing challenge and an opportunity to explore new ways to solve old problems.

We extend our very best wishes to you on your .NET Compact Framework development, whether for the Pocket PC, the Smartphone, or some other Windows CE-powered smart device. We look forward to seeing you in one of our workshops or at an industry conference, or trading comments with you online (contact us via e-mail at info@paulyao.com).

Paul Yao, Bellevue, Washington David Durant, Goldendale, Washington March 2004

Notes

1. Historically, not all emulators have provided high fidelity to device software. In particular, Windows CE 1.x and 2.x emulators were based on an older technology that was good but not great. The last emulator to use this older technology was the Pocket PC emulator that shipped with Microsoft eMbedded Visual C++ 3.0. All emulators for Visual Studio .NET 2003 use the newer emulation technology.

2. For a detailed discussion of these, see the following white paper on the Microsoft Web site: http://msdn.microsoft.com/library/en-us/dncenet/html/choose_api.asp.

Read More Show Less

Table of Contents

Foreword.

Preface.

Acknowledgments.

About the Authors.

I. FOUNDATIONS.

1. .NET Compact Framework Architecture.

Windows CE Overview.

What Is .NET?

The .NET Compact Framework.

Conclusion.

2. What Is a .NET Compact Framework Program?

The Essence of a .NET Compact Framework Program.

Using Visual Studio .NET 2003.

The Cistern Sample Program.

Adding Classes.

Conclusion.

3. The .NET Type System.

Using Type Information: Namespace References and Assembly References.

Standard Types.

Strings.

Type Conversion.

Memory Management.

Conclusion.

4. Platform Invoke.

Overview of P/Invoke.

Creating P/Invoke Declarations.

Supported P/Invoke Function Parameters.

A Sample Program: CallWin32.

Writing Win32 Dynamic Link Libraries.

Manual P/Invoke Parameter Passing.

Communicating between Unmanaged and Managed Code.

Comparing P/Invoke Support.

Conclusion.

II. BUILDING THE USER INTERFACE.

5. Creating Forms.

What Are Forms?

Manipulating Forms.

Inheritance and Visual Inheritance.

Conclusion.

6. Mouse and Keyboard Input.

Overview of Input.

Programming for Mouse Input.

Programming for Keyboard Input.

Conclusion.

7. Inside Controls.

What Are Controls?

Categories of Controls.

Properties, Methods, and Events.

The Core Events.

The Core Properties.

The Core Methods.

Working with Control Type Information.

Five Commonly Used Controls.

A Sample Program: TimeTracker.

The Label Control 436The TextBox Control.

The ListBox and ComboBox Controls.

The Button Control.

The RadioButton and CheckBox Controls.

Conclusion.

8. Data Binding to Controls.

Data Binding.

Complex Data Binding.

Simple Data Binding.

The DataGrid Control.

Conclusion.

9. Inside More Controls.

Detecting Support for Properties, Methods, and Events.

Menus.

Grabbing Events.

The ToolBar and ImageList Controls.

Dialog Boxes.

Conclusion.

10. Building Custom Controls.

Custom Controls.

Controls as Objects.

Deriving Custom Controls from an Existing .NET Control.

Creating Composite Controls.

Creating New Controls.

Adding Animation to a Custom Control.

Authoring Custom Controls for the Multithreaded Environment.

Adding a Custom Control to the Visual Studio .NET Toolbox.

Conclusion.

III. Managing Device Data.

11. Storage.

Smart-Device Data Storage.

File I/O.

Registry Access.

Conclusion.

12. ADO.NET Programming.

Examining ADO.NET.

Working with Data Sets.

Microsoft SQL Server CE.

Microsoft SQL Server.

Web Services.

Conclusion.

13. Synchronizing Mobile Data.

Understanding Remote Data Applications.

Installing Remote Data Connectivity.

Using RDA.

Using Merge Replication.

Choosing between Merge Replication and RDA.

Conclusion.

14. The Remote API.

What Is ActiveSync?

RAPI Fundamentals.

Accessing the Object Store.

Detecting Changes in Device Connection State.

Loading Programs and DLLs.

Conclusion.

IV. Creating Graphical Output.

15..NET Compact Framework Graphics.

An Introduction to .NET Compact Framework Graphics.

Drawing on the Display Screen.

Raster Graphics.

Vector Graphics.

Conclusion.

16. Text and Fonts.

Drawing Text.

Font Selection.

Placing Text.

Text Color.

Conclusion.

17. Printing.

The Printing Pipeline.

Programming for Printed Output.

Direct Printing.

Rendering with GDI.

HP Mobile Printing.

Rendering with PrinterCE.

Conclusion.

V. APPENDIXES.

Appendix A: Hungarian Notation for .NET Programs.

Goals and Objectives.

Guidelines.

.NET Naming Guidelines.

Hungarian Notation.

Appendix B: Supported PMEs for .NET Compact Framework Controls.

Appendix C: Data Synchronization Wizards.

The Virtual Directory Creation Wizard.

The Create Publication Wizard.

Appendix D: Windows API Allocation and Cleanup Functions.

Glossary.

Index.

Read More Show Less

Preface

We feel pretty fortunate. During the past two decades, we have traveled the world teaching programmers what we know. The two of us have led many classes and together have taught thousands of smart, highly motivated software engineers, test engineers, and development managers. We enjoy working with the people who are inventing the future, and we enjoy being at the cutting edge of each successive wave of software development technology. We have learned much from the discussions we have had with these students. This book represents one way we can thank them for all their support.

We worked together on the first book published on the subject of Windows programming, Programmer’s Guide to Windows (Sybex, 1987). Long out of print, in its day the book helped many programmers tackle the challenges presented by Windows version 1.01. That version of Windows came out in November 1985, and in those days developers typically worked on computers running MS-DOS with no hard drive, no network support, and no network servers to rely on.

Things have changed a lot during the 17 years since our first book came out. A pocket-sized computer now has more memory and CPU power than the typical desktop system of the 1980s. A typical desktop system has more raw computing power than a roomful of computers had back then. With this increase in capacity has come a dramatically improved set of development tools available to software developers: Online programming references, context-sensitive help, and graphical editors all help support the task of software development. Programmers can be more productive today thanks to all these tools.

With this increase in computing power and tool support has also come an increase in the complexity of programming interfaces. While the .NET initiative provides a new set of programming interfaces that are better organized than any other Microsoft has created, it is still very large and very intricate. Given enough time, most programmers can master these intricacies. But most programmers do not have enough time to learn about a new technology while also building new software, yet that is what their employers require of them.

Our primary mission is to support you, the software engineer, in saving time. In this book, we distill many years of research and sample code to give you the information you need in a way you can use. We do the same thing in our training classes, in our magazine articles, and in the talks we give at conferences. We concentrate our efforts on helping software engineers become more productive. Time saved in learning about software development issues can be focused on meeting the specific needs of the end users whom you are supporting (or, perhaps, on taking some time off between projects to recharge your mental and physical batteries).

What You Need to Use This Book

To make the most of what this book has to offer, you are going to need a few things, as described in the following subsections.

Hardware

Software developers have historically had the fastest and most capable computer systems they could get their hands on. Developing for smart devices like the Pocket PC and the Smartphone is no different. To get started, we recommend you have the following:

  • Desktop system compatible with Microsoft Windows 2000 or Windows XP
  • Minimum 128MB RAM (256MB recommended)
  • Minimum 4GB hard drive (10GB recommended)
  • Windows CE-powered device (Pocket PC, Pocket PC 2002, Pocket PC 2003, Smartphone 2003, or other Windows CE-powered device)

Strictly speaking, you do not need a Windows CE device because you can run your software on an emulator that runs on your development system. You will, however, eventually want to test your software on real devices, the same ones you expect your users to use. The emulator technology is very good—more than good, in fact. Today’s emulators provide an excellent replication of the software on a device.1 But the hardware and associated device drivers are not going to be the same on an actual device as on an emulator running on a PC. This is the major cause of differences between an emulator and an actual device. When we teach our Pocket PC programming classes, we always recommend to participants that a major portion of testing be done on devices.

While the focus of this book is on writing code, the reality of software development is that you spend a lot of time debugging your code. For that reason, you want to remove anything that slows down your debugging. We suggest you invest in a network connection between your development system and your smart-device system, which means you need the following:

  • Network card (wired or wireless) for the desktop development system
  • Network card (wired or wireless) for the Windows CE-powered device

Software

The development tools can run on any supported version of Microsoft Windows. However, an emulator requires that you run on a 32-bit version of the operating system. This means you want one of the following:

  • Microsoft Windows 2000 (with Service Pack 2 or later)
  • Microsoft Windows XP Professional
  • Microsoft Windows Server 2003

With the right operating system in place, you can then use the software development tools. The first item in the following list is required; the other items are “nice-to-have” tools.

  • Microsoft Visual Studio .NET 2003 (required).
  • (Optional) Microsoft eMbedded Visual C++ 3.0 (for Pocket PC and Pocket PC 2002).
  • Microsoft eMbedded Visual C++ 4.0 (for Pocket PC 2003, Smartphone 2003, and later).
  • P/Invoke Wizard, available from The Paul Yao Company, for help in creating declarations needed to call native code from the .NET Compact Framework. (Learn more about this tool and download a demo version from http://www.paulyao.com/pinvoke.)

The Latest Version of the .NET Compact Framework

As we were finishing this book, Microsoft made available Service Pack 2 of the .NET Compact Framework. Should you upgrade to this latest version (or whatever later version might be available by the time you read this)? We must say yes! This is a new technology, and the .NET Compact Framework team is still working on improvements and upgrades to make the library work better and faster. After shipping a new library, the .NET Compact Framework team members—like most development team members at Microsoft—take a weekend or two off, and then their reward for their hard work is that they get to start all over again, working to create something even better. It’s a good thing that they like what they are doing—and that they are so good at it.

The Sample Code

You can download the code for this book from the following URL: http://www.paulyao.com/cdbook/code.

When you install the sample code directory tree from the Web site, you see four top-level directories.

  • ..\CS contains all the C# samples.
  • ..\VB contains all the Visual Basic .NET samples.
  • ..\CPP contains C/C++ samples.
  • ..\Tools contains binaries of useful tools.

Each of the .NET Compact Framework samples is available in two languages: C# and Visual Basic .NET. Some samples are written in C++, using the Windows API (also known as Win32).

Within the three samples directories (..\CS, ..\VB, and ..\CP) you find a directory for each chapter. Within each chapter directory you find another set of directories for all the samples in that directory.

For example, one of the samples in Chapter 5 is named “FormEvents.” The C# version is at this location: ..\CS\Ch05_CreatingForms\FormEvents. The Visual Basic .NET version is at this location: ..\VB\Ch05_CreatingForms\FormEvents.

The Target Audience for This Book

We wrote this book to help programmers with the .NET Compact Framework. We assumed that no prior programming experience with Windows 95/98/2000/XP, with Windows CE, or with .NET was required. At the same time, if you have experience with programming for Windows on the desktop, with Windows CE, or with the .NET Framework, that experience will help you.

For Programmers Experienced with Windows CE

If you already have experience writing Windows CE programs, you might be wondering if you even need to use the .NET Compact Framework. Whether you do or not depends on what tools you have been using and what type of work you expect to do.

If you have been using eMbedded Visual Basic (eVB) to write Windows CE programs, you are probably already aware that Microsoft plans to discontinue support for eVB. As of this writing, the Pocket PC 2003 supports eVB; that is the last platform to be supported. The .NET Compact Framework is a great replacement. It is well designed, and it provides Visual Basic programmers with support that puts them on a level playing field with C# programmers.

If you have been using the Microsoft Foundation Class (MFC) Library, the ActiveX Template Library (ATL), or the Windows Template Library (WTL), then the case for the .NET Compact Framework is still pretty good. Chapter 1 describes the .NET Compact Framework and its benefits. The new .NET programming paradigm provides many benefits for programmers who have worked with other frameworks. Getting involved with .NET Compact Framework programming is a great way to get into the world of .NET because the libraries are scaled back from the (sometimes) overwhelming number of classes and features found on the desktop .NET Framework. And there is an added bonus for making the move to the .NET Compact Framework: The fundamental elements of programming for the .NET Compact Framework programming are the same as the fundamental elements for all .NET-based technologies. So learning the .NET Compact Framework today will help you learn to build Web applications using ASP.NET, Windows Forms applications for the desktop, and managed-code stored procedures for Yukon (the code name for the next version of SQL Server).

If you have been using the core Windows API/Win32, then you might wonder whether to continue writing Win32 code or to jump into the .NET Compact Framework. For some things, including the following, you must continue using Win32.2

  • Fastest executables
  • Best real-time support
  • Source code portability between platforms
  • Ability to wrap Component Object Model (COM) for access by .NET Compact Framework applications
  • Ability to create device drivers
  • Ability to create control panel applets
  • Support for custom user interface skins
  • Support for security extensions
  • Ability to build Simple Object Access Protocol (SOAP) Web Service servers
  • Support for Pocket PC shell extensions
  • Ability to use existing Win32 code

For Programmers Experienced with the .NET Framework

If you are experienced with writing programs that use the .NET Framework, you are going to find much that is familiar. The C# and Visual Basic .NET languages, for one thing, use the same syntax for two very popular languages that are available for desktop .NET development. The fundamental data types that support interoperability between different languages on the desktop also play a core part of interoperability with smart-device programs.

One thing that may be surprising to desktop .NET Framework developers is the extent to which they might need to rely on P/Invoke support to call the underlying Win32 API functions that Windows CE supports. While the desktop .NET Framework provides an extensive set of classes that minimizes the need to call outside the framework, the .NET Compact Framework provides a reduced set of classes to meet the size constraints of mobile and embedded devices.

To help programmers move from the .NET Framework to the .NET Compact Framework, throughout the book we provide some detailed discussions of differences between the two frameworks. In the many workshops we have taught, we have observed the knowledge and skills of programmers who are experienced with the .NET Framework transfer quite readily to the .NET Compact Framework.

The primary challenge comes from an experience we refer to as “stubbing your toe”—tripping over a familiar desktop feature (whether a class, an enumeration, an attribute, or an operating system feature) that is not present on smart mobile devices. When this happens, you have found a limit on the support available in the .NET Compact Framework (or, perhaps, a limit on the support of the underlying Windows CE operating system). The attitude you take in dealing with such experiences will play a big role in determining how successful you are in .NET Compact Framework programming—and how enjoyable you will find it. We have observed that the programmers who excel with device development are the ones who are able to see in these limitations an enticing challenge and an opportunity to explore new ways to solve old problems.

We extend our very best wishes to you on your .NET Compact Framework development, whether for the Pocket PC, the Smartphone, or some other Windows CE-powered smart device. We look forward to seeing you in one of our workshops or at an industry conference, or trading comments with you online (contact us via e-mail at info@paulyao.com).

Paul Yao, Bellevue, Washington
David Durant, Goldendale, Washington
March 2004

Notes

1. Historically, not all emulators have provided high fidelity to device software. In particular, Windows CE 1.x and 2.x emulators were based on an older technology that was good but not great. The last emulator to use this older technology was the Pocket PC emulator that shipped with Microsoft eMbedded Visual C++ 3.0. All emulators for Visual Studio .NET 2003 use the newer emulation technology.

2. For a detailed discussion of these, see the following white paper on the Microsoft Web site: http://msdn.microsoft.com/library/en-us/dncenet/html/choose_api.asp.

Read More Show Less

Introduction

We feel pretty fortunate. During the past two decades, we have traveled the world teaching programmers what we know. The two of us have led many classes and together have taught thousands of smart, highly motivated software engineers, test engineers, and development managers. We enjoy working with the people who are inventing the future, and we enjoy being at the cutting edge of each successive wave of software development technology. We have learned much from the discussions we have had with these students. This book represents one way we can thank them for all their support.

We worked together on the first book published on the subject of Windows programming, Programmer's Guide to Windows (Sybex, 1987). Long out of print, in its day the book helped many programmers tackle the challenges presented by Windows version 1.01. That version of Windows came out in November 1985, and in those days developers typically worked on computers running MS-DOS with no hard drive, no network support, and no network servers to rely on.

Things have changed a lot during the 17 years since our first book came out. A pocket-sized computer now has more memory and CPU power than the typical desktop system of the 1980s. A typical desktop system has more raw computing power than a roomful of computers had back then. With this increase in capacity has come a dramatically improved set of development tools available to software developers: Online programming references, context-sensitive help, and graphical editors all help support the task of software development. Programmers can be more productive today thanks to all these tools.

With this increase in computing power and toolsupport has also come an increase in the complexity of programming interfaces. While the .NET initiative provides a new set of programming interfaces that are better organized than any other Microsoft has created, it is still very large and very intricate. Given enough time, most programmers can master these intricacies. But most programmers do not have enough time to learn about a new technology while also building new software, yet that is what their employers require of them.

Our primary mission is to support you, the software engineer, in saving time. In this book, we distill many years of research and sample code to give you the information you need in a way you can use. We do the same thing in our training classes, in our magazine articles, and in the talks we give at conferences. We concentrate our efforts on helping software engineers become more productive. Time saved in learning about software development issues can be focused on meeting the specific needs of the end users whom you are supporting (or, perhaps, on taking some time off between projects to recharge your mental and physical batteries).

What You Need to Use This Book

To make the most of what this book has to offer, you are going to need a few things, as described in the following subsections.

Hardware

Software developers have historically had the fastest and most capable computer systems they could get their hands on. Developing for smart devices like the Pocket PC and the Smartphone is no different. To get started, we recommend you have the following:

  • Desktop system compatible with Microsoft Windows 2000 or Windows XP
  • Minimum 128MB RAM (256MB recommended)
  • Minimum 4GB hard drive (10GB recommended)
  • Windows CE-powered device (Pocket PC, Pocket PC 2002, Pocket PC 2003, Smartphone 2003, or other Windows CE-powered device)

Strictly speaking, you do not need a Windows CE device because you can run your software on an emulator that runs on your development system. You will, however, eventually want to test your software on real devices, the same ones you expect your users to use. The emulator technology is very good—more than good, in fact. Today's emulators provide an excellent replication of the software on a device.1 But the hardware and associated device drivers are not going to be the same on an actual device as on an emulator running on a PC. This is the major cause of differences between an emulator and an actual device. When we teach our Pocket PC programming classes, we always recommend to participants that a major portion of testing be done on devices.

While the focus of this book is on writing code, the reality of software development is that you spend a lot of time debugging your code. For that reason, you want to remove anything that slows down your debugging. We suggest you invest in a network connection between your development system and your smart-device system, which means you need the following:

  • Network card (wired or wireless) for the desktop development system
  • Network card (wired or wireless) for the Windows CE-powered device

Software

The development tools can run on any supported version of Microsoft Windows. However, an emulator requires that you run on a 32-bit version of the operating system. This means you want one of the

  • Microsoft Windows 2000 (with Service Pack 2 or later)
  • Microsoft Windows XP Professional
  • Microsoft Windows Server 2003

With the right operating system in place, you can then use the software development tools. The first item in the following list is required; the other items are "nice-to-have" tools.

  • Microsoft Visual Studio .NET 2003 (required).
  • (Optional) Microsoft eMbedded Visual C++ 3.0 (for Pocket PC and Pocket PC 2002).
  • Microsoft eMbedded Visual C++ 4.0 (for Pocket PC 2003, Smartphone 2003, and later).
  • P/Invoke Wizard, available from The Paul Yao Company, for help in creating declarations needed to call native code from the .NET Compact Framework.

The Latest Version of the .NET Compact Framework

As we were finishing this book, Microsoft made available Service Pack 2 of the .NET Compact Framework. Should you upgrade to this latest version (or whatever later version might be available by the time you read this)? We must say yes! This is a new technology, and the .NET Compact Framework team is still working on improvements and upgrades to make the library work better and faster. After shipping a new library, the .NET Compact Framework team members—like most development team members at Microsoft—take a weekend or two off, and then their reward for their hard work is that they get to start all over again, working to create something even better. It's a good thing that they like what they are doing—and that they are so good at it.

The Sample Code

You can download the code for this book.

When you install the sample code director Web site, you see four top-level directories.

  • ..\CS contains all the C# samples.
  • ..\VB contains all the Visual Basic .NET samples.
  • ..\CPP contains C/C++ samples.
  • ..\Tools contains binaries of useful tools.

Each of the .NET Compact Framework samples is available in two languages: C# and Visual Basic .NET. Some samples are written in C++, using the Windows API (also known as Win32).

Within the three samples directories (..\CS, ..\VB, and ..\CP) you find a directory for each chapter. Within each chapter directory you find another set of directories for all the samples in that directory.

For example, one of the samples in Chapter 5 is named "FormEvents." The C# version is at this location: ..\CS\Ch05_CreatingForms\FormEvents. The Visual Basic .NET version is at this location: ..\VB\Ch05_CreatingForms\FormEvents.

The Target Audience for This Book

We wrote this book to help programmers with the .NET Compact Framework. We assumed that no prior programming experience with Windows 95/98/2000/XP, with Windows CE, or with .NET was required. At the same time, if you have experience with programming for Windows on the desktop, with Windows CE, or with the .NET Framework, that experience will help you.

For Programmers Experienced with Windows CE

If you already have experience writing Windows CE programs, you might be wondering if you even need to use the .NET Compact Framework. Whether you do or not depends on what tools you have been using and what type of work you expect to do.

If you have been using eMbedded Visual Basic (eVB) to write Windows CE programs, you are probably already aware Microsoft plans to discontinue support for eVB. As of this writing, the Pocket PC 2003 supports eVB; that is the last platform to be supported. The .NET Compact Framework is a great replacement. It is well designed, and it provides Visual Basic programmers with support that puts them on a level playing field with C# programmers.

If you have been using the Microsoft Foundation Class (MFC) Library, the ActiveX Template Library (ATL), or the Windows Template Library (WTL), then the case for the .NET Compact Framework is still pretty good. Chapter 1 describes the .NET Compact Framework and its benefits. The new .NET programming paradigm provides many benefits for programmers who have worked with other frameworks. Getting involved with .NET Compact Framework programming is a great way to get into the world of .NET because the libraries are scaled back from the (sometimes) overwhelming number of classes and features found on the desktop .NET Framework. And there is an added bonus for making the move to the .NET Compact Framework: The fundamental elements of programming for the .NET Compact Framework programming are the same as the fundamental elements for all .NET-based technologies. So learning the .NET Compact Framework today will help you learn to build Web applications using ASP.NET, Windows Forms applications for the desktop, and managed-code stored procedures for Yukon (the code name for the next version of SQL Server).

If you have been using the core Windows API/Win32, then you might wonder whether to continue writing Win32 code or to jump into the .NET Compact Framework. For some things, including the following, you must continue using Win32.2

  • Fastest executables
  • Best real-time support
  • Source code portability between platforms
  • Ability to wrap Component Object Model (COM) for access by .NET Compact Framework applications
  • Ability to create device drivers
  • Ability to create control panel applets
  • Support for custom user interface skins
  • Support for security extensions
  • Ability to build Simple Object Access Protocol (SOAP) Web Service servers
  • Support for Pocket PC shell extensions
  • Ability to use existing Win32 code

For Programmers Experienced with the .NET Framework

If you are experienced with writing programs that use the .NET Framework, you are going to find much that is familiar. The C# and Visual Basic .NET languages, for one thing, use the same syntax for two very popular languages that are available for desktop .NET development. The fundamental data types that support interoperability between different languages on the desktop also play a core part of interoperability with smart-device programs.

One thing that may be surprising to desktop .NET Framework developers is the extent to which they might need to rely on P/Invoke support to call the underlying Win32 API functions that Windows CE supports. While the desktop .NET Framework provides an extensive set of classes that minimizes the need to call outside the framework, the .NET Compact Framework provides a reduced set of classes to meet the size constraints of mobile and embedded devices.

To help programmers move from the .NET Framework to the .NET Compact Framework, throughout the book we provide some deta frameworks. In the many workshops we have taught, we have observed the knowledge and skills of programmers who are experienced with the .NET Framework transfer quite readily to the .NET Compact Framework.

The primary challenge comes from an experience we refer to as "stubbing your toe"—tripping over a familiar desktop feature (whether a class, an enumeration, an attribute, or an operating system feature) that is not present on smart mobile devices. When this happens, you have found a limit on the support available in the .NET Compact Framework (or, perhaps, a limit on the support of the underlying Windows CE operating system). The attitude you take in dealing with such experiences will play a big role in determining how successful you are in .NET Compact Framework programming—and how enjoyable you will find it. We have observed that the programmers who excel with device development are the ones who are able to see in these limitations an enticing challenge and an opportunity to explore new ways to solve old problems.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)