桌面端的移动计算(四)

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Launching an Application

有很多原因使你要从一个桌面程序启动设备上的一个应用程序。在下面情况下,你可以使用这个技术:

· 安装一个新版本的应用程序。简单地拷贝CAB文件到设备上,然后在设备上运行CAB安装程序来提供安装。这项技术被经常用在你想自动发布和安装应用程序更新的情况下。

注意 另一个相似的发法是自动话桌面端的安装过程,使用ActiveSync内置的功能。

· 在安装了新版本应用程序后重起你的移动应用程序。

· 开始一个设备应用程序处理新更新的数据,在更新了文本或者XML文件后。

RAPI示例程序如图4

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 292.5pt; HEIGHT: 178.5pt" type="#_x0000_t75" alt=""><img src="/Develop/ArticleImages/27/27155/CSDN_Dev_Image_2004-4-231744520.gif" o:href="http://msdn.microsoft.com/library/en-us/dnroad/html/road0324200404.gif"><font face="宋体"></font></shape>

Figure 4. The Launch Application tab of the RAPI demo program

OpenNETCF.Desktop.Communication命名空间RAPI类提供CreateProcess方法来启动一个设备文件。你希望启动的设备应用程序作为该方法的第一个参数。你可以传递一个命令行给应用程序,作为第二个参数。

btnLaunchPerform按钮的点击事件演示了CreateProcess方法。

[VC#.NET]

private void btnLaunchPerform_Click(object sender, System.EventArgs e)

{

 

// Perform the launch.

 try

 {

 if (txtLaunchFile.Text == "")

 {

 MessageBox.Show("You must provide a file to launch.",

 "No File Provided");

 }
 else

 {

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);

 MessageBox.Show("Your file has been launched.", "Launch Success");

 }

 }

 

// Handle any errors that might occur.

 catch (Exception ex)

 {

 MessageBox.Show("The following error occurred while launching the 
file -" +

 ex.Message, "Launch Error");

 } 

}

[VB.NET]

Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click

' Perform the launch.

 Try

 If (txtLaunchFile.Text = "") Then

MessageBox.Show("You must provide a file to launch.", _ "No File Provided");

 }

 else

 "No File Provided");

 }

 else

 {

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);

 MessageBox.Show("Your file has been launched.", "Launch Success");

 }

 }

 

// Handle any errors that might occur.

 catch (Exception ex)

 {

 MessageBox.Show("The following error occurred while launching the 
file -" +

 ex.Message, "Launch Error");

 } 

}

[VB.NET]

Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click

' Perform the launch.

 Try

 If (txtLaunchFile.Text = "") Then

 MessageBox.Show("You must provide a file to launch.", _

 "No File Provided")

 Exit Sub

 End If

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text)

 MessageBox.Show("Your file has been launched.", "Launch Success")

' Handle any errors that might occur.

 Catch ex As Exception

 MessageBox.Show("The following error occurred while launching the file
-" & ex.Message, _

 "Launch Error")

 End Try

End Sub

接下来我们将进入最后一个RAPI有关的主题:获得系统信息。在下面的部分你将看到,RAPI类提供了一些方法用来得到连接设备的详细信息。

Retrieving System Information

得到指定的设备系统信息使你的程序能够在下面几个方面交付内容或改变功能:

· 连接设备上使用的处理器,当应用程序上传一个包含指定处理器的文件的CAB文件到设备上时。

注意 这项技术最常用的环境是当你发布应用程序到早期版本的Pocket PC设备上,例如基于ARM处理器的Windows Mobile设备。

· 运行在连接设备上的操作系统版本,根据处理器类型使用相应文件进行更新。

· 连接设备的电源状态,经常用于在使用者进入区域前,警告他们的设备运行于低电量状态下。

· 连接设备的内存状态,用于检测数据是否可以下载,如果用户下载了未被授权的应用程序或者其他内存相关函数,或者判断你是否有足够的空间安装应用程序的更新。

这部分操作的演示界面见图5

<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 292.5pt; HEIGHT: 178.5pt" type="#_x0000_t75" alt=""><img src="/Develop/ArticleImages/27/27155/CSDN_Dev_Image_2004-4-231744520.gif" o:href="http://msdn.microsoft.com/library/en-us/dnroad/html/road0324200405.gif"><font face="宋体"></font></shape>

Figure 5. The Device Information tab of the RAPI demo program

RAPI类提供了四个方法来得到这些信息,GetDeviceSystemInfo (处理器类型), GetDeviceVersion (操作系统版本), GetDeviceSystemPowerStatus (电源状态) GetDeviceMemoryStatus (内存).

BtnInfoRetrieve按钮的点击事件示范了这些方法。

[VC#.NET]

private void btnInfoRetrieve_Click(object sender, System.EventArgs e)

{

 string info;

 MEMORYSTATUS ms;

 SYSTEM_INFO si;

 SYSTEM_POWER_STATUS_EX sps;

 OSVERSIONINFO vi;

// Retrieve the system information.

 myrapi.GetDeviceSystemInfo(out si);

// Retrieve the device OS version number.

 myrapi.GetDeviceVersion(out vi);

// Retrieve the device power status.

 myrapi.GetDeviceSystemPowerStatus(out sps);

// Retrieve the device memory status.

 myrapi.GetDeviceMemoryStatus(out ms);

// Format the retrieved information.

 info = "The connected device has an ";

 switch (si.wProcessorArchitecture)

 {

 case ProcessorArchitecture.Intel:

 info += "Intel processor.\n";

 break;

 case ProcessorArchitecture.MIPS:

 info += "MIPS processor.\n";

 break;

 case ProcessorArchitecture.ARM:

 info += "ARM processor.\n";

 break;

 default:

 info = "unknown processor type.\n";

 break;

 }

 info += "OS version: " + vi.dwMajorVersion + "." + 
vi.dwMinorVersion + "." +

vi.dwBuildNumber + "\n";

 if (sps.ACLineStatus == 1)

 {

 info += "On AC power: YES\n";

 }

 else

 {

 info += "On AC power: NO \n";

 }

 info += "Battery level: " + sps.BatteryLifePercent + "%\n";

 info += "Total memory: " + String.Format("{0:###,###,###}", 
ms.dwTotalPhys) +

 "\n";

// Display the results.

 lblInfo.Text = info; 

}

[VB.NET]

Private Sub btnInfoRetrieve_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnInfoRetrieve.Click

 Dim info As String

 Dim ms As New MEMORYSTATUS

 Dim si As New SYSTEM_INFO

 Dim sps As New SYSTEM_POWER_STATUS_EX

 Dim vi As New OSVERSIONINFO

' Retrieve the system information.

 myrapi.GetDeviceSystemInfo(si)

' Retrieve the device OS version number.

 myrapi.GetDeviceVersion(vi)

' Retrieve the device power status.

 myrapi.GetDeviceSystemPowerStatus(sps)

' Retrieve the device memory status.

 myrapi.GetDeviceMemoryStatus(ms)

' Format the retrieved information.

 info = "The connected device has an "

 Select Case si.wProcessorArchitecture

 Case ProcessorArchitecture.Intel

 info += "Intel processor." & vbCrLf

 Case ProcessorArchitecture.MIPS

 info += "MIPS processor." & vbCrLf

 Case ProcessorArchitecture.ARM

 info += "ARM processor." & vbCrLf

 Case Else

 info = "unknown processor type." & vbCrLf

 End Select

 info += "OS version: " & vi.dwMajorVersion & "." & vi.dwMinorVersion 
& "." & vi.dwBuildNumber & vbCrLf

 info += "On AC power: " & IIf(sps.ACLineStatus = 1, "YES", "NO") 
& vbCrLf

 info += "Battery level: " & sps.BatteryLifePercent & "%" & vbCrLf

 info += "Total memory: " & String.Format("{0:###,###,###}", 
ms.dwTotalPhys) & vbCrLf

' Display the results.

 lblInfo.Text = info

End Sub

到这里我们如果将桌面应用程序加入到你的移动解决方案和关于Remote API的介绍就要告以段落了。我建议你花一些时间来检验OpenNETCF.Desktop.Communication命名空间提供的其他的功能。记住,那才是所有的操作,OpenNETCF命名空间为你的应用程序提供了多种类的操作。

Back on the Road

又是一个新的月份了。春天已经来到了每个角落,我要带着我的滑水板和Pocket PC前往阳光充足的Florida。在我的下一篇文章里,我们将检验关于移动开发者更多的操作。

你可能感兴趣的:(F#,Office,vb,vc++,VB.NET)