You are previewing Programming Microsoft® Windows® CE .NET, 3rd Edition.
O'Reilly logo
Programming Microsoft® Windows® CE .NET, 3rd Edition

Book Description

Here is the definitive guide to programming the Windows CE API—now in its third edition, with details on how to use Windows CE .NET to design high-performance applications for smart devices.

Table of Contents

  1. Programming Microsoft® Windows® CE .NET, Third Edition
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Acknowledgments
  5. Introduction
    1. Just What Is Windows CE?
    2. A Little Windows CE History
      1. The Devices
      2. The Operating System
    3. Why You Should Read This Book
    4. What's New in the Third Edition
    5. .NET Compact Framework
    6. What About MFC?
    7. Windows CE Development Tools
    8. Target Systems
    9. What's on the CD
    10. Other Sources
    11. Support
      1. Visit the Microsoft Press Web Site
    12. Updates and Feedback
  6. I. Windows Programming Basics
    1. 1. Hello Windows CE
      1. What Is Different About Windows CE
        1. Fewer Resources in Windows CE Devices
        2. Unicode
        3. New Controls
        4. Componentization
        5. Win32 Subset
      2. It's Still Windows Programming
        1. Hungarian Notation
      3. Your First Windows CE Application
        1. Building Your First Application
        2. Running the Program
        3. What's Wrong?
      4. Hello2
      5. Anatomy of a Windows-Based Application
        1. The Window Class
        2. The Window Procedure
        3. The Life of a Message
      6. Hello3
        1. Registering the Window Class
        2. Creating the Window
        3. The Message Loop
        4. The Window Procedure
          1. WM_PAINT
          2. WM_DESTROY
      7. HelloCE
        1. The Code
          1. InitInstance
          2. MainWndProc
          3. DoPaintMain and DoDestroyMain
        2. Running HelloCE
    2. 2. Drawing on the Screen
      1. Painting Basics
        1. Valid and Invalid Regions
        2. Device Contexts
      2. Writing Text
        1. Device Context Attributes
          1. Foreground and Background Colors
          2. Text Alignment
          3. Drawing Mode
        2. The TextDemo Example Program
        3. Fonts
          1. Creating a Font
          2. Selecting a Font into a Device Context
          3. Querying a Font's Characteristics
          4. Destroying a Font
          5. Enumerating Fonts
        4. The FontList Example Program
          1. Unfinished Business
      3. Bitmaps
        1. Device-Dependent Bitmaps
        2. Device-Independent Bitmaps
        3. DIB Sections
        4. Drawing Bitmaps
      4. Lines and Shapes
        1. Lines
          1. Pens
        2. Shapes
          1. Brushes
          2. Rectangles
          3. Circles and Ellipses
          4. Round Rectangles
          5. Polygons
        3. Fill Functions
        4. The Shapes Example Program
    3. 3. Input: Keyboard, Mouse, and Touch Screen
      1. The Keyboard
        1. Input Focus
        2. Keyboard Messages
        3. Keyboard Functions
          1. Testing for the Keyboard
        4. The KeyTrac Example Program
      2. The Mouse and the Touch Screen
        1. Mouse Messages
        2. Working with the Touch Screen
          1. Stylus Messages
          2. Inking
          3. Input Focus and Mouse Messages
          4. Right-Button Clicks
        3. The TicTac1 Example Program
    4. 4. Windows, Controls, and Menus
      1. Child Windows
      2. Window Management Functions
        1. Enumerating Windows
        2. Finding a Window
        3. Editing the Window Structure Values
          1. Changing the Style Flags
          2. Subclassing a Window
      3. Windows Controls
        1. Button Controls
          1. Push Buttons
          2. Check Boxes
          3. Radio Buttons
          4. Group Boxes
          5. Customizing the Appearance of a Button
          6. Owner-Draw Buttons
        2. The Edit Control
        3. The List Box Control
        4. The Combo Box Control
        5. Static Controls
        6. The Scroll Bar Control
          1. Scroll Bar Messages
          2. Configuring a Scroll Bar
        7. The CtlView Example Program
          1. Controls and Colors
      4. Menus
        1. Handling Menu Commands
      5. Resources
        1. Resource Scripts
        2. Icons
        3. Accelerators
        4. Bitmaps
        5. Strings
      6. The DOIView Example Program
    5. 5. Common Controls and Windows CE
      1. Programming Common Controls
      2. The Common Controls
        1. The Command Bar
          1. Creating a Command Bar
          2. Command Bar Menus
          3. Command Bar Buttons
          4. Referencing Images
          5. Working with Command Bar Buttons
          6. Disabled Buttons
          7. Drop-Down Buttons
          8. Combo Boxes on the Command Bar
          9. Command Bar Tooltips
          10. Other Command Bar Functions
          11. Design Guidelines for Command Bars
        2. The CmdBar Example
        3. Command Bands
          1. Creating a Command Bands Control
          2. Adding Bands
          3. Configuring Individual Bands
          4. Saving the Band Layout
          5. Handling Command Band Messages
        4. The CmdBand Example
        5. The Menu Bar
          1. Creating a Menu Bar
          2. Menu Bar Resources
          3. Working with a Menu Bar
        6. The MenuBar Example
        7. The Month Calendar Control
          1. Initializing the Control
          2. Month Calendar Notifications
        8. The Date and Time Picker Control
          1. Creating a Date and Time Picker Control
          2. Customizing the Format
        9. The List View Control
          1. Styles in Report Mode
          2. Virtual List View
        10. The CapEdit Control
      3. Other Common Controls
        1. The Status Bar Control
          1. The Status Bar Control
          2. The Tab Control
          3. The Trackbar Control
          4. The Progress Bar Control
          5. The Up-Down Control
          6. The Toolbar Control
          7. The Tree View Control
      4. Unsupported Common Controls
    6. 6. Dialog Boxes and Property Sheets
      1. Dialog Boxes
        1. Dialog Box Resource Templates
        2. Creating a Dialog Box
        3. Dialog Box Procedures
        4. Modeless Dialog Boxes
        5. Property Sheets
          1. Creating a Property Sheet
          2. Creating a Property Page
          3. Property Page Procedures
          4. Switching Pages
          5. Closing a Property Sheet
        6. Common Dialogs
      2. The DlgDemo Example Program
  7. II. Windows CE Programming
    1. 7. Memory Management
      1. Memory Basics
        1. About RAM
        2. About ROM
        3. About Virtual Memory
          1. Paged Memory
          2. Querying the System Memory
        4. An Application's Address Space
      2. The Different Kinds of Memory Allocation
        1. Virtual Memory
          1. Allocating Virtual Memory
          2. Regions vs. Pages
          3. Freeing Virtual Memory
          4. Changing and Querying Access Rights
        2. Heaps
        3. The Local Heap
          1. Allocating Memory on the Local Heap
          2. Freeing Memory on the Local Heap
          3. Resizing and Querying the Size of Local Heap Memory
        4. Separate Heaps
          1. Creating a Separate Heap
          2. Allocating Memory in a Separate Heap
          3. Freeing Memory in a Separate Heap
          4. Resizing and Querying the Size of Memory in a Separate Heap
          5. Destroying a Separate Heap
        5. The Stack
        6. Static Data
        7. String Resources
        8. Selecting the Proper Memory Type
        9. Managing Low-Memory Conditions
          1. The WM_HIBERNATE Message
          2. Memory Thresholds
    2. 8. Files and the Registry
      1. The Windows CE File System
        1. The Object Store vs. Other Storage Media
        2. Standard File I/O
          1. Creating and Opening Files
          2. Reading and Writing
          3. Moving the File Pointer
          4. Closing a File
          5. Truncating a File
          6. Getting File Information
          7. File Times
          8. File Size and Other Information
        3. The FileView Sample Program
        4. Memory-Mapped Files and Objects
          1. Memory-Mapped Files
        5. Navigating the File System
          1. File and Directory Management
          2. Creating a Temporary File
          3. Finding Files
          4. Distinguishing Drives from Directories
      2. The Registry
        1. Registry Organization
        2. The Registry API
          1. Opening and Creating Keys
          2. Reading Registry Values
          3. Writing Registry Values
          4. Deleting Keys and Values
          5. Closing Keys
          6. Enumerating Registry Keys
        3. The RegView Example Program
    3. 9. Windows CE Databases
      1. Databases
        1. Basic Definitions
          1. Designing a Database
          2. Database Volumes
        2. The Database API
          1. Mounting a Database Volume
          2. Enumerating Mounted Database Volumes
          3. Unmounting a Database Volume
          4. Using the Object Store as a Database Volume
          5. Creating a Database
          6. Opening a Database
          7. Seeking (or Searching for) a Record
          8. Changing the Sort Order
          9. Reading a Record
          10. Writing a Record
          11. Deleting Properties, Records, and Entire Databases
          12. Enumerating Databases
          13. Querying Object Information
        3. The AlbumDB Example Program
    4. 10. Modules, Processes, and Threads
      1. Modules
      2. Processes
        1. Creating a Process
        2. Terminating a Process
        3. Other Processes
      3. Threads
        1. The System Scheduler
          1. Never Do This!
        2. Creating a Thread
        3. Setting and Querying Thread Priority
        4. Setting a Thread's Time Quantum
        5. Suspending and Resuming a Thread
      4. Fibers
      5. Thread Local Storage
      6. Synchronization
        1. Events
        2. Waiting…
          1. Waiting on a Single Object
          2. Waiting on Processes and Threads
          3. Waiting on Multiple Objects
          4. Waiting While Dealing with Messages
        3. Semaphores
        4. Mutexes
        5. Duplicating Synchronization Handles
        6. Critical Sections
        7. Interlocked Variable Access
      7. Windows CE Security
      8. Interprocess Communication
        1. Finding Other Processes
        2. WM_COPYDATA
        3. Named Memory-Mapped Objects
          1. Naming a Memory-Mapped Object
        4. Message Queues
        5. Communicating with Files and Databases
      9. The XTalk Example Program
      10. Exception Handling
        1. C++ Exception Handling
          1. Using Exceptions to Report Errors
          2. The try, catch Block
        2. Win32 Exception Handling
          1. The __try, __except Block
          2. Determining the Problem
          3. Generating Your Own Exceptions
          4. The __try, __finally Block
    5. 11. Notifications
      1. User Notifications
        1. Setting a User Notification
          1. Configuring a User Notification
          2. Acknowledging a User Notification
      2. Timer Event Notifications
      3. System Event Notifications
      4. The Note Demo Example Program
      5. Querying Scheduled Notifications
  8. III. Communications
    1. 12. Serial Communications
      1. Basic Serial Communication
        1. Opening and Closing a Serial Port
        2. Reading from and Writing to a Serial Port
        3. Asynchronous Serial I/O
        4. Configuring the Serial Port
        5. Setting the Port Timeout Values
        6. Querying the Capabilities of the Serial Driver
        7. Controlling the Serial Port
        8. Clearing Errors and Querying Status
        9. Stayin' Alive
      2. The CeChat Example Program
    2. 13. Windows CE Networking
      1. Windows Networking Support
        1. WNet Functions
          1. Conventions of UNC
          2. Mapping a Remote Drive
          3. Disconnecting a Remote Resource
          4. Enumerating Network Resources
          5. Querying Connections and Resources
        2. The ListNet Example Program
    3. 14. Device-to-Device Communication
      1. Basic Sockets
        1. Initializing the Winsock DLL
          1. ASCII vs. Unicode
        2. Stream Sockets
          1. Creating a Socket
          2. Server Side: Binding a Socket to an Address
          3. Listening for a Connection
          4. Accepting a Connection
          5. Client Side: Connecting a Socket to a Server
          6. Sending and Receiving Data
          7. Closing a Socket
      2. IrSock
        1. Querying and Setting IR Socket Options
        2. Blocking vs. Nonblocking Sockets
        3. The MySquirt Example Program
      3. Bluetooth
        1. Stack
        2. Discovery
          1. Device Discovery
          2. Service Discovery
        3. Publishing a Service
          1. SDP Records
        4. Bluetooth Communication with Winsock
          1. Server Side
          2. Client Side
        5. Bluetooth Communication with Virtual COM Ports
          1. Server Side
          2. Client Side
        6. The BtHello Example Program
      4. OBEX
        1. Initialization
        2. Application Callbacks
        3. Device Discovery
          1. Synchronous Device Detection
          2. Asynchronous Device Detection
        4. OBEX Communication
        5. The ObexSquirt Example Program
    4. 15. Connecting to the Desktop
      1. The Windows CE Remote API
        1. RAPI Overview
          1. Dealing with Different Versions of RAPI
          2. Initializing RAPI
          3. Handling RAPI Errors
          4. Ending a RAPI Session
        2. Predefined RAPI Functions
          1. RAPI System Information Functions
          2. RAPI File and Directory Management Functions
          3. RAPI Database Management Functions
          4. RAPI Registry Management Functions
          5. RAPI Shell Management Functions
          6. RAPI Window Management Functions
        3. The RapiDir Example Program
        4. Custom RAPI Functions
          1. Using RAPI to Call a Custom Function
          2. Writing a RAPI Server Function
          3. Stream Mode
        5. The RapiFind Example Program
      2. The CeUtil Functions
        1. Accessing ActiveSync Registry Entries
          1. Accessing ActiveSync Registry Entries
          2. Enumerating Registered Devices
          3. Reading and Writing Values
      3. Connection Notification
        1. Registry Method
        2. COM Method
          1. The IDccMan Interface
          2. The IDccManSink Interface
        3. The CnctNote Example Program
        4. Connection Detection on the Windows CE Side
      4. Direct Socket Connections
  9. IV. Device Programming
    1. 16. The Explorer Shell
      1. Working with the Shell
        1. The Shell Namespace
        2. Special Folders
        3. Shortcuts
        4. Configuring the Start Menu
        5. Recent Documents List
        6. Launching Applications
        7. The Taskbar
        8. The TBIcons Example Program
        9. The Out Of Memory Error Dialog Box
      2. Console Applications
        1. The CEFind Example Program
        2. Console Redirection
      3. Hardware Keys
        1. Virtual Codes for Hardware Keys
          1. Navigation Key Codes
          2. Application Launch Key Codes
        2. Using the Application Launch Keys
        3. Dynamically Overriding Application Launch Keys
    2. 17. Programming the Pocket PC
      1. What Is a Pocket PC?
        1. Is It a PDA, a Phone, or Both?
        2. The Pocket PC Screen
      2. Hello Pocket PC
        1. Differences in a Pocket PC Application
          1. Single Instance
          2. Use a Menu Bar, Not a Command Bar
          3. Manually Sizing the Main Window
          4. Dealing with Changes in the SIP
          5. Ctrl-Q Closes a Pocket PC Application
        2. Building HelloPPC
      3. The New Menu
        1. Managing the New Menu
          1. Managing the New Menu
        2. The NewMenuX Example
          1. Handling the New Menu from Within an Application
      4. Pocket PC Notifications
        1. Adding a Notification
        2. Modifying a Notification
        3. Removing a Notification
      5. Dialog Boxes
        1. Full-Screen Dialog Boxes
        2. Input Dialogs
        3. Property Sheets
      6. AutoRun
      7. Additional Pocket PC Shell Functions
        1. Full-Screen Windows
        2. Freeing Memory
        3. Controlling the SIP
          1. Querying the State of the SIP
          2. Changing the Default Input Method
    3. 18. Extending the Pocket PC
      1. Custom Today Screen Items
        1. Implementing a Today Screen Item
          1. Creating the Item Window
          2. The Item Window
          3. Interacting with the User
          4. Unloading the Custom Item
          5. The Options Dialog
        2. Registering the Custom Item
        3. Debugging a Custom Item
        4. The PowerBar Custom Today Screen Item
      2. Custom Input Methods
        1. The Components of a SIP
        2. Threading Issues with Input Methods
        3. The IInputMethod and IInputMethod2 Interfaces
          1. IInputMethod::Select
          2. IInputMethod::GetInfo
          3. IInputMethod::ReceiveSipInfo
          4. IInputMethod::RegisterCallback
          5. IInputMethod::Showing and IInputMethod::Hiding
          6. IInputMethod::GetImData and IInputMethod::SetImData
          7. IInputMethod::Deselect
          8. IInputMethod::UserOptionsDlg
          9. IInputMethod2::RegisterCallback2
          10. IInputMethod2::SetIMMActiveContext
        4. The IIMCallback and IIMCallback2 Interfaces
          1. IIMCallback::SetImInfo
          2. IIMCallback::SendVirtualKey
          3. IIMCallback::SendCharEvents
          4. IIMCallback::SendString
          5. IIMCallback2::SendAlternatives2
        5. The NumPanel Example Input Method
    4. 19. Programming the Smartphone
      1. Introducing the Smartphone
        1. A Smartphone Application
      2. The Smartphone's MenuBar Control
        1. Creating a Smartphone MenuBar Control
        2. Working with the Buttons and Menus
        3. The Back Button and Other Interesting Buttons
      3. Message Boxes
      4. Dialog Boxes
        1. Scrolling Dialogs
      5. Smartphone Controls
        1. Text Controls
        2. Expandable Edit Controls
        3. Spinner Controls
      6. File Operation in the Smartphone
      7. Communication
        1. Phone API
          1. Dialing the Phone
          2. Viewing the Call Log
        2. The Connection Manager
          1. Connecting
          2. Setting and Querying Status
        3. SMS Messaging
          1. Accessing the SMS System
          2. Sending a Message
          3. Receiving a Message
          4. Configuring the SMS System
        4. The SMSTalk Example
      8. Smartphone Security
    5. 20. GAPI, the Game API
      1. GAPI Initialization
        1. Getting Display Information
        2. Querying Button Information
        3. Accessing the Buttons
      2. Drawing to the Screen
      3. Indirect Access to the Frame Buffer
      4. GAPI Maintenance
      5. Cleaning Up
      6. The GAPIShow Example
  10. V. Advanced Windows CE
    1. 21. System Programming
      1. The Windows CE Memory Architecture
      2. Writing Cross-Platform Windows CE Applications
        1. Platforms and Operating System Versions
        2. Compile-Time Versioning
        3. Explicit Linking
        4. Run-Time Version Checking
      3. Power Management
      4. Querying the Power State
        1. Changing the Power State
          1. Powering Down
          2. Turning Off the Screen
          3. Powering Up the System
          4. Preventing the System from Powering Down
        2. The Power Manager
          1. Power Notifications
          2. Setting the Power State
    2. 22. Device Drivers and Services
      1. Basic Drivers
        1. Driver Names
        2. The Device Driver Load Process
        3. Enumerating the Active Drivers
        4. Reading and Writing Device Drivers
      2. Writing a Windows CE Stream Device Driver
        1. The Stream Driver Entry Points
          1. xxx_Init
          2. xxx_Deinit
          3. xxx_Open
          4. xxx_Close
          5. xxx_Read
          6. xxx_Write
          7. xxx_Seek
          8. xxx_PowerDown
          9. xxx_PowerUp
          10. xxx_IOControl
        2. Device Interface Classes
          1. Advertising an Interface
          2. Monitoring for an Interface
        3. Device Driver Power Management
          1. Power Management Functions for Devices
          2. IOCTL_POWER_CAPABILITIES
          3. IOCTL_REGISTER_POWER_RELATIONSHIP
          4. IOCTL_POWER_GET
          5. IOCTL_POWER_QUERY
          6. IOCTL_POWER_SET
      3. Building a Device Driver
        1. Debug Zones
        2. The Generic Driver Example
      4. Asynchronous Driver I/O
      5. Services
        1. Service Architecture
        2. The Life of a Service
        3. Application Control of a Service
        4. The Service DLL Entry Points
          1. xxx_Init
          2. xxx_Deinit
          3. xxx_IOControl
          4. Other Entry Points
        5. The Service IOCTL Commands
          1. IOCTL_SERVICE_START
          2. IOCTL_SERVICE_STOP
          3. IOCTL_SERVICE_REFRESH
          4. IOCTL_SERVICE_INSTALL
          5. IOCTL_SERVICE_UNINSTALL
          6. IOCTL_SERVICE_STATUS
          7. IOCTL_SERVICE_QUERY_CAN_DEINIT
          8. IOCTL_SERVICE_CONSOLE
          9. IOCTL_SERVICE_CONTROL
          10. IOCTL_SERVICE_DEBUG
          11. IOCTL_SERVICE_CALLBACK_FUNCTIONS
          12. IOCTL_SERVICE_SUPPORTED_OPTIONS
        6. Super Service
          1. Programmatically Controlling the Super Service
          2. SuperService IOCTLs
          3. IOCTL_SERVICE_REGISTER_SOCKADDR
          4. IOCTL_SERVICE_STARTED
          5. IOCTL_SERVICE_DEREGISTER_SOCKADDR
          6. IOCTL_SERVICE_CONNECTION
          7. IOCTL_SERVICE_NOTIFY_ADDR_CHANGE
        7. Services.exe Command Line
        8. TickSrv Example Service
    3. 23. Programming the .NET Compact Framework
      1. It's Becoming a Managed World
        1. To .NET or Not to .NET
      2. A Brief Introduction to Managed Applications
        1. HelloCF
          1. Namespaces
          2. Visual Basic .NET
        2. Common Language Runtime Basics
          1. Value vs. Reference Types
          2. Events and Delegates
          3. Strings
      3. The Framework Class Library
      4. Windows Forms Applications
        1. A Basic Windows Forms Application
          1. Painting
          2. Adding Controls
          3. Adding an Event Handler
          4. Where Is All This Code?
        2. Configuring a Top-Level Form
      5. Compact Framework Unique Classes
        1. MessageWindow
          1. MessageWindow
          2. InputPanel
          3. IrDA Classes
      6. Accessing the Underlying Operating System
        1. P/Invoke
        2. P/Invoke Arguments
          1. Simple Types
          2. Structures and Arrays
          3. Working with Strings
      7. The IrSquirtCF Example
  11. Index
  12. About the Author
  13. Copyright