30 Days of .NET [Windows Mobile Applications] - Day 02: Bluetooth Manager(蓝牙管理器)
2009-05-21 17:17
501 查看
原文见 Day 02: Bluetooth
Manager
看过我之前的文章会知道,在Windows Mobile下打开关闭Bluetooth,就是P/Invoke BthSetMode().
.NET
Compact Framework下的Bluetooth开发 之 Windows Embedded Source Tools for Bluetooth
.NET
Compact Framework下的Bluetooth开发 之 32feet.NET
.NET
Compact Framework下的Bluetooth开发 之 Bluetooth Virtual Serial Port
[DllImport("BthUtil.dll")]
private static extern int BthGetMode(out RadioMode dwMode);
[DllImport("BthUtil.dll")]
private static extern int BthSetMode(RadioMode dwMode);
状态变更功能,如果外部程序变更了Bluetooth的状态,当前程序需要被通知并处理变更。
using Microsoft.WindowsMobile.Status;
SystemState bluetoothStatePowerOn = new SystemState(SystemProperty.BluetoothStatePowerOn);
bluetoothStatePowerOn.Changed += new ChangeEventHandler(bluetoothStatePowerOn_Changed);
void bluetoothStatePowerOn_Changed(object sender, ChangeEventArgs args)
{
UpdateScreen();
}
这里使用了State and Notifications Broker API,需要引用Microsoft.WindowsMobile.Status库。SystemState(SystemProperty.BluetoothStatePowerOn)指定了状态监控的类型,生成Bluetooth开关的系统状态对象,bluetoothStatePowerOn.Changed += new ChangeEventHandler(bluetoothStatePowerOn_Changed)订阅Bluetooth开关系统状态的变更消息,并使用bluetoothStatePowerOn_Changed进行处理该消息。
State and Notifications Brokerz API是一个很重要的API,这API可以监控注册表的变化状况。总所周知,在Windowns里面注册表就是保持系统信息和应用程序信息的小型数据库。State and Notifications Brokerz API提供监控注册表的功能,表示他能监控系统信息以及应用程序信息的变化。这些信息包括摄像头状态,ActiveSync,电源状态,SMS,计划任务,呼叫信息,Bluetooth状态,网络链接状态,modem状态等等。所以这API广泛运用于系统信息相关事件触发的开发,参考链接见下面。
增加自动关闭程序功能。
private void timer_Tick(object sender, EventArgs e)
{
textBox.Text = string.Empty;
for (int i = 10; i > 0; i--)
{
textBox.Text += string.Format("Auto shutdown in {0} seconds
" + Environment.NewLine, i);
Thread.Sleep(1000);
}
this.Close();
}
this.timer.Interval = 60000;
这个程序运行1分钟后,自动关闭自己。在关闭前,有10秒钟的倒数,目的使得用户知道这个程序不是Crash,而是自动关闭了,这是用户友好性设计的表现。
施炯 同学的文章 在Windows Mobile模拟器上使用蓝牙以及 Dmitry Klionsky的Bluetooth for Microsoft Device Emulator。
安装程序: bluetoothManager.cab
源代码: bluetoothManager.zip
参考文献:
MSDN:State and
Notifications Broker
.NET Compact Framework, WinCE, Windows Mobile开发系列
Jake's Blog in 博客园 -- 精简开发 无线生活
Manager
需求
Page Brooks为了省电,想一步完成Bluetooth开关的操作。实现
使用的技术有P/Invoke蓝牙API, PictureBox, State and Notification Broker API.看过我之前的文章会知道,在Windows Mobile下打开关闭Bluetooth,就是P/Invoke BthSetMode().
.NET
Compact Framework下的Bluetooth开发 之 Windows Embedded Source Tools for Bluetooth
.NET
Compact Framework下的Bluetooth开发 之 32feet.NET
.NET
Compact Framework下的Bluetooth开发 之 Bluetooth Virtual Serial Port
[DllImport("BthUtil.dll")]
private static extern int BthGetMode(out RadioMode dwMode);
[DllImport("BthUtil.dll")]
private static extern int BthSetMode(RadioMode dwMode);
状态变更功能,如果外部程序变更了Bluetooth的状态,当前程序需要被通知并处理变更。
using Microsoft.WindowsMobile.Status;
SystemState bluetoothStatePowerOn = new SystemState(SystemProperty.BluetoothStatePowerOn);
bluetoothStatePowerOn.Changed += new ChangeEventHandler(bluetoothStatePowerOn_Changed);
void bluetoothStatePowerOn_Changed(object sender, ChangeEventArgs args)
{
UpdateScreen();
}
这里使用了State and Notifications Broker API,需要引用Microsoft.WindowsMobile.Status库。SystemState(SystemProperty.BluetoothStatePowerOn)指定了状态监控的类型,生成Bluetooth开关的系统状态对象,bluetoothStatePowerOn.Changed += new ChangeEventHandler(bluetoothStatePowerOn_Changed)订阅Bluetooth开关系统状态的变更消息,并使用bluetoothStatePowerOn_Changed进行处理该消息。
State and Notifications Brokerz API是一个很重要的API,这API可以监控注册表的变化状况。总所周知,在Windowns里面注册表就是保持系统信息和应用程序信息的小型数据库。State and Notifications Brokerz API提供监控注册表的功能,表示他能监控系统信息以及应用程序信息的变化。这些信息包括摄像头状态,ActiveSync,电源状态,SMS,计划任务,呼叫信息,Bluetooth状态,网络链接状态,modem状态等等。所以这API广泛运用于系统信息相关事件触发的开发,参考链接见下面。
增加自动关闭程序功能。
private void timer_Tick(object sender, EventArgs e)
{
textBox.Text = string.Empty;
for (int i = 10; i > 0; i--)
{
textBox.Text += string.Format("Auto shutdown in {0} seconds
" + Environment.NewLine, i);
Thread.Sleep(1000);
}
this.Close();
}
this.timer.Interval = 60000;
这个程序运行1分钟后,自动关闭自己。在关闭前,有10秒钟的倒数,目的使得用户知道这个程序不是Crash,而是自动关闭了,这是用户友好性设计的表现。
Emulator下调试
由于Windows Mobile的Emulator不直接支持Bluetooth,所以源代码需要在真实设备上进行调试,为了方便,可以尝试在Emulator调试。可以参考施炯 同学的文章 在Windows Mobile模拟器上使用蓝牙以及 Dmitry Klionsky的Bluetooth for Microsoft Device Emulator。
安装程序: bluetoothManager.cab
源代码: bluetoothManager.zip
参考文献:
MSDN:State and
Notifications Broker
.NET Compact Framework, WinCE, Windows Mobile开发系列
Jake's Blog in 博客园 -- 精简开发 无线生活
相关文章推荐
- 30 Days of .NET [Windows Mobile Applications] - Day 04: Mileage Tracker(里程耗油计算程序)
- 30 Days of .NET [Windows Mobile Applications] - Day 01: Minutes to Midnight Countdown(午夜倒数器)
- 30 Days of .NET [Windows Mobile Applications] - Day 03: GPS Compass(GPS指南针)
- 30 Days of .NET Windows Mobile Applications
- restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-
- enbdding Fonts for wp from:http://www.jeffblankenburg.com/2010/10/24/31-days-of-windows-phone-day-24-embedding-fonts/
- Programming. NET Windows applications
- Ring Tone Manager on Windows Mobile
- 31 Days of Windows Phone | Day #4 Device Orientation
- The Windows SDK team is proud to announce that the RTM release of the Microsoft Windows SDK for Windows Server 2008 and .NET Fra
- The step-by-step guide of making a C# (or VB.NET) Windows 7 Trigger Start Service
- .NETZ:Reducing the Size of .NET Applications(给.NET程序减肥)
- windows下实现gettimeofday
- Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager
- HOW TO: Tune and Scale Performance of Applications That Are Built on the .NET Framework -zt from MS
- Turorial of buliding Windows Mobile development Enviroment
- (30 hackdays day 21) Wakatime - 现在几点了,你在做什么呢
- 使用ActiveReport for .net 进行报表开发(一)(转自Cure The Last Day Of Summer)
- (30 hackdays day 9) Rekognition - 借我借我一双慧眼吧
- (30 hackdays day 22) Import.io - 最简单好用的网页爬虫服务