淺析利用VB.NET啟動Smartphone常規(guī)方法
本人很喜歡使用VB.NET啟動Smartphone,在工作中也很喜歡總結(jié)關(guān)于VB.NET啟動Smartphone的經(jīng)驗教訓,下面就這個問題來詳細說說吧。下面是一個簡單示例,啟動手機中的計算器程序,步驟如下:
1、啟動VS.net2003,選Visual Basic 項目,在右邊的列表中選智能設(shè)備應(yīng)用程序,在下一個對話框中針對什么平臺選Smartphone,類型選Windows應(yīng)用程序。
2、將上面介紹的輔助類及API聲明的代碼做成兩個模塊。
3、為在form1的代碼模塊頂部加入如下語句:
- Imports System.Runtime.InteropServices
4、在 Form1的 load事件中加入啟動計算器的代碼如下:
- Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load- Dim tudtShellExecuteInfo As New SHELLEXECUTEINFO
- Dim tstrExecutePath As String
- Dim tudtStartupInfo As STARTUPINFO
- Dim tudtProcessInfo As PROCESS_INFORMATION
- Dim tlngTempa As Int32
- With tudtStartupInfo
- .cb = Marshal.SizeOf(GetType(STARTUPINFO))
- End With
- With tudtShellExecuteInfo
- .cbSize = Marshal.SizeOf(GetType(SHELLEXECUTEINFO))
- .lpFile = clsDAMSMobileMarshal.fnStringToHLocalUni("/windows/calc.exe")
- .lpParameters = IntPtr.Zero
- '不使用參數(shù),如使用參數(shù)可按lpFile的方法申請字符串指針
- End With
- tlngTempa = ShellExecuteEx(tudtShellExecuteInfo) '啟動程序
- tudtShellExecuteInfo.Dispose()
- If tlngTempa = 0 Then '使用shellexecuteex失敗,試圖使用createprocess再打開試試
- tlngTempa = CreateProcess("/windows/calc.exe", "/windows/calc.exe", IntPtr.Zero,
IntPtr.Zero, _ 0, 0, IntPtr.Zero, IntPtr.Zero, tudtStartupInfo, tudtProcessInfo)- If tlngTempa <> 0 Then
- Call CloseHandle(tudtProcessInfo.hThread)
- Call CloseHandle(tudtProcessInfo.hProcess)
- End If
- End If
- End Sub
以上就是VB.NET啟動Smartphone中的應(yīng)用程序的常規(guī)方法,代碼在本人的計算機上測試通過,本人的計算機系統(tǒng)配置為WIN2000 高級服務(wù)器版+Visual Studio 2003(完全安裝)+Smartphone 2003 SDK(開發(fā)Smartphone應(yīng)用程序必備,在微軟的網(wǎng)站可以下載,微軟提供的免費軟件啊!我喜歡8-),網(wǎng)址如下: http://msdn.microsoft.com/mobility/downloads/sdks/default.aspx)。
【編輯推薦】