Microsoft 智能手机(Smartphone)C#开发入门

 

Microsoft 智能手机(Smartphone)C#开发入门

原文地址:http://www.codeproject.com/KB/mobile/SmartphoneIntroCSharp.aspx

ByLogu Krishnan

译者:林七佛

 

Introduction(引言)

The objective of this article is to provide the prelude to the beginners of SmartPhone programming. This article provides introduction to SmartPhone, its features and APIs. Also, the article discusses on creating a simple program using C# for the SmartPhone.

      本文的目的是为智能手机编程开发的初学者介绍一些入门知识。本文将介绍智能手机的一些入门知识,它的一些特征和API。当然,本文还讨论了使用C#创建一个简单的智能手机程序。

In recent days, mobility is getting its momentum and attention both from the public consumers of mobile services and major corporations of the world. Mobility today equips knowledge workers with the power to access information and data from any part of the world.

      今天,便携(可移动的,随身携带)设备已经成为大众消费者和世界主要厂商的关注的焦点。如今拥有较高文化层次的工人已经装备了移动设备,这样就可以从世界的任何角落获取信息和数据。

As any other rapid technology evolution, mobility has certainly evolved and its recent form is on Mobile Phones, but be sure that, this mobility would create a whole new world and accessories useful for mankind, starting from a lay man to the richest. And it is also true that soon mobility would take another form and shape, and would become part of our lives.

      和其它高速发展的技术一样,现在的便携设备已经进化到最新的移动手机模式,不过毫无疑问的是,这些便携设备将创造一个全新的世界并成为人们有用的附件,无论他是穷人还是富人。便携设备也会很快以其它样式出现,并成为我们生活的一部分。

Fine… But what do I get as a developer on all these happening around me… Actually, there is a whole new exciting world opened up for developers which is definitely a paradigm shift from today’s Desktop and Web Application development. New technology, new challenges, new opportunities, and… new way to earn… $ Money $ ;-)

      言归正传,这些到底对身为开发人员到底有什么意义呢?事实上,对开发者而言这将对我们展现一个崭新刺激的世界,从今天的桌面和web程序开发中脱身出来,新的技术、新的挑战和新的机遇,还有新的赚钱的机会(*^__^*)

Mobility Evolution(移动设备的发展)

As part of the evolution, we had various handheld devices, Pocket PCs, PDAs et al. Today’s mobility world is trying to gain advantage by leveraging advantages of successful cellular phones which are truly mobile and is owned by people of all sectors of the world.

      我们有各种的手持设备:掌上电脑、PDA(个人数字助理)等。今天的移动世界将要让手机成为真正的便携式电话从而获得其中的好处,并让全世界的人们都可以分享这个成果。

There have been various models of phones available in today’s market. As of today, the market is ruled by Symbion OS embedded on the Nokia Phones and other proprietary phones like Sony, Samsung et al.

      今天的市场上有各种型号的电话。内嵌Symbion OSNokia(诺基亚)手机和其他电话如索尼、三星等。

      Much like the Web Browser market, Microsoft is a bit late to enter the mobile world. Today Microsoft has its own proprietary operation system, called as Microsoft Windows Mobile 2003, powered by the strong WinCE 4.2 OS. These phones with the Microsoft OS is slowly capturing up the market, and the developers' world.

      非常像web浏览器市场,微软进入移动世界的时机有点晚。现在微软已经有他们的操作系统(移动平台),叫做Microsoft Windows Mobile 2003,基于强大的WinCE 4.2操作系统(PS:现在WM 6.0WinCE 5.2.这些使用微软操作系统的手机进入市场和开发人员的时间较迟。

As always, Microsoft provides adequate developer support to program these phones using existing languages and technologies. Microsoft .NET Compact Framework, a subset of the rich .NET Framework, does this magic. One great news is that the .NET CF runtime is now preloaded on the ROM of the Microsoft, which definitely eases the burden during the application deployment.

      微软总是给开发人员提供足够的支持来开发这些手机的程序,可以利用现有的语言和技术。Microsoft .NET Compact Framework(微软的.NET 小型框架包)是强大的.net framework的一个子集。一个好消息是.NET CF运行时将在微软的ROMA中预装,这将对这些程序的部署起到简化的作用。

Features(特征)

Microsoft SmartPhone is loaded with a very rich suite of software, which communicates to the user through Voice, Text and Internet capable applications, by leveraging the connectivity options like GSM, GPRS, SMS, PPTP, Bluetooth, USB, and Infrared IrDA.

      微软的智能手机已经预装了丰富的软件,可以通过语音通信、处理文本和访问互联网的程序,可以使用GSM, GPRS(目前cn的手机上网方式), SMS, PPTP, Bluetooth(蓝牙), USB和红外线。

下面罗列出微软智能手机已经包含的软件:

Pocket Internet Explorer

用来上网的浏览器

No more plain vanilla WAP Browser on phones, instead a full blown IE 5 is loaded on the phones supporting HTML 3.2, XML, XSL, cHTML, WA P 1.2.1 , WML Script, Active Script, ActiveX, SSL, JPEG, GIF etc.

Pocket Outlook

电子邮件

With tools for contacts, calendar, email, tasks and voice notes. Along with support for IMAP4, POP3 and SMS.

MSN Messenger

即时通讯软件

A full blown messenger

Microsoft ActiveSync

和电脑同步的软件

Supports Server and Desktop synchronization.

Windows Media Player

媒体播放器

Plays MP3, WMA, AVI

Voice Notes

录制语音

To quickly record voices

Games

游戏

Variety of Mobile games.

File Management Utilities

文件管理

File Manager [like Windows Explorer], Task Manager

资源管理器和任务管理器

Wireless Modem

无线猫

Options to connect through USB, IR, COM

MMS Client

短信

Send and receive MMS messages

Camera

相机

Camera support for image capture and video capture

SmartPhone Layout(智能手机的功能键布局)

Microsoft has suggested a standard layout and control structure for the devices. [Ref: SmartPhone SDK]

微软推荐的标准布局和该类设备的控制结构【参考自智能手机 SDK

The placement of soft keys, the Home key, the Back key, and the five-way navigation pad illustrated in the preceding figure is strongly recommended. All the hardware controls (soft keys, and so on) must be present; however, a device manufacturer is free to deviate from the design.

左软键、主页键、返回键和五维按键的布局是强烈推荐的(感觉这款手机好难看啊)。所有的硬件控制都必须有;尽管如此,设备制造商还是有自由设计的空间。

Recently, Microsoft launched the Microsoft Windows Mobile 2003 Second Edition, and the following developer tools are available, based on its open Win32 development environment and an SDK for SmartPhone [can be downloaded].

  • Embedded VC++ 4.0
  • Visual Studio .NET – C#, VB.NET

近来,微软发布了Microsoft Windows Mobile 2003第二版,还有下面的开发工具,基于win32开发环境和智能手机SDK

A Simple Hello World Program(一个简单的Hello world程序)

Now, let’s get into business. Let us write a simple Hello World program. The first and foremost activity we need to do for programming the SmartPhone using Visual Studio 2003 is to download the SmartPhone 2003 SDK. Upon installing the SDK, the smart device extensions are extended with support for SmartPhone development along with the SmartPhone emulator.

现在,让我们切入正题。写个简单的Hello World程序。首先也是最重要的是我们需要一VS2003(并下载Smartphone 2003 SDK,其实你用vs2005都自带了,不过我现在用vs2008)来开发智能手机程序。当安装SDK后,就可以利用模拟器并支持智能手机开发扩张。

After the SDK is installed, launch Visual Studio, choose Smart Device Application under project templates, and give a name for your application, and click OK. Now, you should see a screen as below:

当安装好SDK后,启动VS,在工程模板下选择智能设备程序,给程序命名并点击OK。接下来你可以看到下面的屏幕:

注意:为简单明了起见,下面简化一些。和原文不同

当新建工程后,你会发现下面就自动加入一个菜单控件,我们桌面程序的菜单一般在窗体上面,而只能手机是在下面的。

这些菜单控件的使用方法和其他程序差不多,可以很方便的添加。你只要现场折腾一下就会了。

随意添加几个,下面双击菜单的其中那个Say Hello的项目,加入代码如下:

private void menuItem2_Click(object sender,System.EventArgs e)
   
   
{
   
   
     MessageBox.Show("Hello Logu!");
   
   
}
   
   

上面这个是跳出一个提示对话框!

下面这个代码是退出程序的:

private void menuItem3_Click(object sender, System.EventArgs e)
   
   
{
   
   
    this.Close();
   
   

}

是不是非常简单?现在要运行了,这里通过模拟器来执行:

F5运行,会让你选择模拟器,Smartphone 2003 Emulator (Virtual Radio) (Default)”, and hit “Deploy”.

你可以选择上面写的那个,并单击部署!

这样模拟器就会运行,会显示一个手机,你写的程序会在program下面,自己到处看看,会找到的。

我是用vs2005/vs2008都写过,令我惊讶的是,这些程序也一样可以直接在电脑上运行(手机上还有其他exe程序曾经拷贝到电脑却不行,提示不是有效的win32程序)。

还有要说的是那个模拟器似乎效率低下,我双核4400+ 2G 内存都觉得很慢。所以还是直接拷贝到手机上运行快很多。

下面再简要看看提供的API(现在我急需这些API文档,希望SDK中有,正在下载中)

  • ActiveSync API
  • Bluetooth API
  • CE Messaging API
  • Device Management API
  • Home Screen API
  • Object Exchange (OBEX)
  • Pocket Outlook Object Model (POOM)
  • Speech Recognizer
    • Telephony - TAPI
    • Accessing the SIM card
    • P/Invoke to native SIM Toolkit APIs
  • RAPI – Remote API to connect to the desktops programmatically
  • GAPI – To develop Mobile games
  • Vibrate API
  • Voice Recorder Controls

我也是刚接触这个,所以一切都是new的,呵呵!

 

 

 

     

 

 

using System; using System.Data; using System.Data.SqlClient; using System.Collections; namespace mobilesale { /// <summary> /// DataBL 的摘要说明。 /// </summary> public class DataBL { public DataBL() { // // TODO: 在此处添加构造函数逻辑 // } public static SqlConnection getConn() { SqlConnection sqlCon= new SqlConnection("server=.;Integrated Security=SSPI;Database=MTSSystem"); return sqlCon; } public static DataTable selectMobile() { SqlConnection con=DataBL.getConn(); String strSelect="select mobileModelID as '手机编号',mobileModel as '手机型号',mobileFactory as '手机厂家',totalPrice as '手机全价',maxDisccunt as '最大折扣' from mobileModel"; SqlDataAdapter adapter=new SqlDataAdapter(strSelect,con); DataTable tab=new DataTable(); adapter.Fill(tab); return tab; } public static DataTable selectSales() { SqlConnection con=DataBL.getConn(); String strSelect="select saleID as '营业员编号',saleName as '姓名',salesVolume as '销售额' from mobileSales"; SqlDataAdapter adapter=new SqlDataAdapter(strSelect,con); DataTable tab=new DataTable(); adapter.Fill(tab); return tab; } public static ArrayList selectSaleNames() { SqlConnection con=DataBL.getConn(); String strSelect="select saleName as '姓名'from mobileSales"; SqlCommand cmd=new SqlCommand(strSelect,con); con.Open(); SqlDataReader reader=cmd.ExecuteReader(); ArrayList data=new ArrayList(); while(reader.Read()) { data.Add(reader.GetString(0)); } con.Close(); return data; } public static ArrayList selectMobileModel() { SqlConnection con=DataBL.getConn(); String strSelect="select mobileModel as '手机型号'from mobileModel"; SqlCommand cmd=new SqlCommand(strSelect,con); con.Open(); SqlDataReader reader=cmd.ExecuteReader(); ArrayList data=new ArrayList(); while(reader.Read()) { data.Add(reader.GetValue(0)); } con.Close(); return data; } public static ArrayList selectDisccunt(string mobileModel) { SqlConnection con=DataBL.getConn(); String strSelect="select maxDisccunt from mobileModel where mobileModel='"+mobileModel+"'"; SqlCommand cmd=new SqlCommand(strSelect,con); con.Open(); int maxDisccunt=Int32.Parse( cmd.ExecuteScalar().ToString()); con.Close(); ArrayList data=new ArrayList(); for(int i=maxDisccunt;i<=100;i++) { data.Add(i); } return data; } public static String setPrice(string mobileModel,string count,string disccunt) { SqlConnection con=DataBL.getConn(); String strSelect="select totalprice from mobileModel where mobileModel='"+mobileModel+"'"; SqlCommand cmd=new SqlCommand(strSelect,con); con.Open(); int maxDisccunt=Int32.Parse( cmd.ExecuteScalar().ToString()); con.Close(); return (maxDisccunt*Int32.Parse(count)*Int32.Parse(disccunt)/100).ToString(); } public static int insertOrder(string saleName,string mobileModel,string customer,string IDCardNo,string amount ,string price) { SqlConnection con=DataBL.getConn(); String strSelect="select saleID from mobileSales where saleName='"+saleName+"'"; SqlCommand cmd=new SqlCommand(strSelect,con); con.Open(); int saleId=Int32.Parse( cmd.ExecuteScalar().ToString()); con.Close(); strSelect="select mobileModelID from mobileModel where mobileModel='"+mobileModel+"'"; cmd=new SqlCommand(strSelect,con); con.Open(); int mobileModelID=Int32.Parse( cmd.ExecuteScalar().ToString()); con.Close(); string strInsert ="insert into mobileOrder values ('"+customer+"','"+IDCardNo+"',"+saleId+","+mobileModelID+","+Int32.Parse(amount)+","+Int32.Parse(price)+",'"+DateTime.Now.ToString()+"')"; cmd=new SqlCommand(strInsert,con); con.Open(); return cmd.ExecuteNonQuery(); con.Close(); } } }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值