代码改变世界

从0开始Windows Mobile 开发

2009-05-20 22:09  王克伟  阅读(35223)  评论(34编辑  收藏  举报

我从事Windows Mobile开发半年多了,这半年很努力,收获也很多。对于当初连Windows是基于消息机制都不知道的我来说,起点可以说是0。之所以写这篇文章,是想和大家分享我的经验,能够为那些初学者提供一些儿帮助。未来我工作和学习的重点将放在用户界面和多媒体开发上。欢迎和我交流,我的QQ是:3423 67 776。

言归正传,先来看看微软在操作系统方面的产品,桌面操作系统大体的历程:
MS-DOS
Windows 1.0
Windows 2.0
Windows 3.0
Windows NT 3.1
Windows 3.2
Windows 95
Windows NT 4.0(发布同一年——1996年,11月份发布Windows CE 1.0)
Windows 98
Windows ME
Windows 2000
Windows XP
Windows Vista
Windows 7
关于桌面操作系统发展史有很多有意思的事情,在此略过。(关于以后的文章中我总结一下《Windows Internals》读书笔记。)

嵌入式操作系统有:
Windows CE 1.0
Windows CE 2.0
Windows CE 3.0(改名为Windows for Pocket PC,简称Pocket PC)
Windows CE 4.0(即Windows CE.Net)
Windows CE 5.0(开放250万行源代码)
Windows Embedded CE 6.0(2006年11月推出,在内核方面改进了很多,比如内存管理等。并且共享100%内核源码。)
image

image
之后微软宣布将Windows Embedded CE
Windows Embedded StandardWindows XP Embedded
Windows Embedded EnterprisePOSReady( next generation of Windows Embedded for Point of Service)、
Windows Embedded NavReadyWindows Embedded Server组成Windows Embedded系列产品。

基于Windows CE操作系统的有:

网络投影仪、网络多媒体设备、车载计算机、电视机顶盒、生产在线的控制设备、公共场所的信息站等等,有些设备甚至没有任何人机界面。微软针对不同嵌入式设备推出不同定制的Windows CE内核,比如我们这里讲的Windows Mobile操作系统,它是专门针对智能手机的,在Windows CE内核基础上添加了智能手机所具有的功能和界面,还比如前段时间我看到微软推出针对MP4的专用操作系统。(关于Windows CE/Windows Mobile内核方面知识在此略过,我会在以后的文章中总结。)

现在让我们看看Windows Mobile操作系统的发展史:
image

Windows Mobile 6.0是基于Windows CE 5.0内核,所以内存管理方面跟Windows CE 5.0是一样的,Windows Mobile 7.0将采用Windows CE 6.0内核。

开发工具(第1、3两项需要向微软购买,如果仅仅是学习第4项你下个试用版就可以了。具体请看这里)

1.Platform Builder for Windows Mobile(注意和Windows CE版本的区别),在定制内核、内核调试(另外可以借助很多PB的插件)等操作中,它将是一个得力的助手。

2.Windows Mobile 6 Professional SDK(或者Standard版本的,这里仅仅提供Professional版本),在安装完Visual Studio之后安装Windows Mobile 6 Professional SDK Refresh.msi,然后安装中文包:Windows Mobile 6 Professional Images (CHS).msi。提供了你开发所需要的基本接口,和调试用的模拟器等。另外其它的头文件和Lib库等文件你可能需要在AKU里面查找。

3.Adaptation Kit Update(AKU),微软更新Windows Mobile的方式。来看看维基的解释:
"It is a collection of updates, fixes and enhancements to the tools delivered to hardware device manufacturers to create or update devices based on a specific platform.”更多

4.Visual Studio 2005/2008(有很多提高开发效率的插件,比如Visual Assist X),VS自带的工具,如下图,都是很有用的。
 clip_image002

5.ActiveSync,不管是真机还是模拟器,如果想与PC同步(比如手机通过PC来上网),需要使用这个工具。

6.SourceInsight(驱动开发常用的工具,管理、编辑代码很方便。)

7.在如内存泄漏等错误查找方面有很多专门的工具,比如Application Verify等。(请各位看官补充一下:))

整体开发流程

主要分为:硬件、Driver、RIL、应用程序。(在以后的文章中详细总结)

应用程序开发技术

语言:C/C++(Native Code)     VS   C#/VB/…(Managed Code)

选择什么开发方式就选择什么语言,选择Managed Code,即在.Net CF下开发,但是实现有些功能你需要P/Invoke Win32   DLL。比如在CodeProject上的一个使用C#编写的,在Windows Mobile上运行的iPhone界面程序,就调用了GDI API函数AlphaBlend来实现半透明。请看

关于本地代码开发和提高代码开发的比较有很多资料,这里不详细介绍了,它们的PK是开发效率和运行效率上面的PK。其实在一个项目中它们可能都是需要的。

.Net CF
是微软.NET Framework 的子集合,专为Mobile Device上的Windows CE平台系列提供应用程序开发的支持。目前.NET Compact Framework最新版本为3.5,可运行在Windows CE 6.0以及Windows Mobile 6.0系统中。更多

Win32
我们团队用的最多的,开发效率低,直接使用系统的API,程序的运行效率比较高。因为Windows Mobile编程继承了Windows桌面编程风格,所以学习这方面知识你可以阅读《Windows 程序设计(第5版)》、《Windows核心编程(第5版)》等书籍。 
clip_image002[7]

MFC
采用的倒是不多,简单的界面就直接编写个Win32应用程序,复杂一点的界面可以使用WTL或者使用.Net CF(第三方OpenNETCF提供更多的扩展)进行托管开发。
MFC对Win32的封装跟WTL很多地方是相似的,封装的机制值得学习,关于这方面的基础视频推荐:《孙鑫C++视频》。

COM
扩展微软自带的应用程序,比如IE、Windows Media Player等,需要使用COM技术。
不单单如此,微软的技术很多都是构建于组件技术的,所以值得深入学习,推荐《COM技术内幕》(侯捷和潘爱民都有翻译)。

ATL
Active Template Library(活动模板库),是一个以C++模板技术的类的集合,帮助你更方便的使用COM,创建ActiveX等。推荐阅读深入解析ATL(第2版)维基更多介绍

WTL
是一个用于研发的面向对象的C++模板函数库,它主要被开发作为MFC的轻量化替代品,以ATL函数库为基础。
一个使用WTL和使用MFC生产的应用程序的简单比较:更多

Version

Size (in KB on disk)

MFC Debug

2030

MFC Release

212

WTL Debug

420

WTL Release

56

 

我们再来看看Windows Mobile 6.5及以后带给我们开发人员的好东西

用户界面(静态的、动态的和可交互的)一直是开发中的难点,怎样提高用户体验一直是开发中不断挖掘的东西。以下两个技术就是为此而生的:

Silverlight for mobile

Q: What is Silverlight?
A: Microsoft Silverlight powers rich application experiences and delivers high quality, interactive video across the Web and mobile devices through the most comprehensive runtime available on the Web.
Built to integrate with Microsoft Servers, Developer and Designer Tools and supported by a thriving partner ecosystem, the Silverlight solution accelerates the results of compelling experiences through powerful technology.

Q: How does Silverlight for mobile integrate with the standards-based Web?
A: Silverlight for mobile fully integrates with the standards-based Web technologies. On the client side, there is seamless DOM integration and bi-directional integration between Silverlight and JavaScript. On the server side, Silverlight can communicate with any standards-based server side technology including REST, POX, SOAP, and more.
目前Silverlight for mobile还在开发中,让我们期待一下吧。

Widgets

在Mobile上,它吸引我的地方在于它可以仅仅做成一个独立的基于网络交互的应用程序,它使用的技术就像我当初写网页用的技术一样:XHTML、CSS、AJAX、JavaScript,这相当爽的啊。那是在Today界面上编写一个天气预报的插件那是多么的方便啊,想想现在得用C++写,实属没办法。请看

A good way to think of a Windows Mobile Widget is as a “Portable chunk of the web” or just basically a rich internet application.  Widgets are written using all the web technologies we know and love (HTML, CSS, AJAX, JavaScript) and, since they are powered under the covers by our new internet browser, they have full access to flash and other ActiveX controls available on the device (Like MediaPlayer).

Widgets最初源于苹果电脑的一个插件工具——Konfabulator,现在W3C发布了关于Widget的标准草案。请看

学习和参考资料

[1].Windows Mobile 6.0/6.5/7.0 Documentation(最主要的资料。)

在你安装的Windows Mobile 6 Professional SDK目录下,有很多不错的Samples,初学者应该多阅读这里的代码:
clip_image002[9]
里面的htm文件已经帮你归类了,比如:
clip_image002[11]
你到论坛上面问的一些简单问题在这里都能找到答案。

[2].Microsoft WebCast开发资料(包括视频、PPT和示例代码,这是个好东西,我喜欢。你可以使用ireaper小程序方便的下载和管理这些资料。):
clip_image002

[3].CSDN Windows Mobile论坛

[4].MSDN Windows Mobile论坛

[5].Windows Mobile中国官方网站

[6].CodeProject/http://sourceforge.net//http://www.codeplex.com/(好东西啊)

[7].维基百科嵌入式系统介绍

[8].其它资源请见施炯的博客:Windows Mobile Jump Start Guide