[WM][VB][拒接指定來電的連絡人]

  • 5888
  • 0

[WM][VB][拒接指定來電的連絡人]

如果要撰寫一支應用程式來拒絕擾人的電話,又不能關掉手機怎麼做,我們可以利用Microsoft.WindowsMobile.Status.SystemState類別來取得目前電話號碼,有的號碼我們就可以來做判斷是否拒接,怎麼做拒接就是如下圖模擬按下拒接來電按鍵的動作

image

Step1:開啟vs2008新增一個vb 智慧型裝置專案,在畫面上拉一個Treeview元件用來顯示連絡,ListBox來顯示來電號碼,接著將滑鼠移到方案總管點選參考,在按下右鍵點選功能表上的加入參考

image

Step2:挑選Microsoft.WindowsMobile.PocketOutlook、Microsoft.WindowsMobile.Status二個元件在按下確定

image

Step3:接下來在表單裡面撰寫程式 

Imports Microsoft.WindowsMobile.Status
Imports Microsoft.WindowsMobile.PocketOutlook


Public Class Form1
    Friend WithEvents Number As New SystemState(SystemProperty.PhoneIncomingCallerNumber)
    Private Declare Sub keybd_event Lib "coredll.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Const VK_F4 As Integer = &H73
    Const KEYEVENTF_KEYUP As Integer = &H2
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '表單在載入的時候先讀取手機的連絡人資填到Treeview元件
        Dim Session As New OutlookSession()
        For Each c As Contact In Session.Contacts.Items
            Dim Node As New TreeNode(c.LastName & "," & c.MobileTelephoneNumber)
            Node.Tag = c.MobileTelephoneNumber
            Me.TreeView1.Nodes.Add(Node)
        Next
    End Sub

    Private Sub Number_Changed(ByVal sender As Object, ByVal args As Microsoft.WindowsMobile.Status.ChangeEventArgs) Handles Number.Changed
        '判斷來電的號碼是不是空值
        If args.NewValue IsNot Nothing Then
            ListBox1.Items.Insert(0, args.NewValue)
            '在Treview 裡面尋找黑名單是否跟來電符合,若有配對成我就執行掛電話動作
            For Each node As TreeNode In Me.TreeView1.Nodes
                If node.Checked And node.Tag = args.NewValue Then
                    Drop()
                End If
            Next
        End If
    End Sub

    Private Sub Drop()
        '常用手機按鍵代碼
        ' VK_TSOFT1   VK_F1               // Softkey 1
        ' VK_TSOFT2   VK_F2               // Softkey 2
        ' VK_TTALK    VK_F3               // Talk            
        ' VK_TEND     VK_F4               // End            
        ' VK_THOME    VK_LWIN             // Home          
        ' VK_TBACK    VK_ESCAPE           // Back        
        ' VK_TACTION      VK_RETURN       // Action        
        ' VK_TRECORD      VK_F10          // Record
        ' VK_TFLIP        VK_F17          // Flip
        ' VK_TPOWER       VK_F18          // Power
        ' VK_TVOLUMEUP    VK_F6           // Volume Up        
        ' VK_TVOLUMEDOWN  VK_F7           // Volume Down  

        '此動作就是模擬按下拒接來電的動作
        keybd_event(VK_F4, 0, 0, 0)
        keybd_event(VK_F4, 0, KEYEVENTF_KEYUP, 0)
    End Sub


End Class

 

Step4:按下vs2008功能表上偵錯\開始偵錯進行部署應用程式來測一下吧

image

Step5:首先來看一下連絡的資料

image 

Step6:程式執行起來看一下Treeview的連絡人跟你的手機連絡人是否有同步,接著我們先鉤一個拒絕來電名單,用Cellular Emulator來測一下,發一通電話為非拒接人員試看看

image

Step6:接下來試一下播打為拒接名單的電話,看看應用程式是否有擋下來就成功

image

Step7: 源碼下載