📄 form1.cs
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.WindowsMobile.Status;
using System.Threading;
namespace SmartAnswerCall
{
public partial class Form1 : Form
{
private const int KEYEVENTF_KEYUP = 0x0002;
[DllImport("coredll.dll")]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private SystemState callState, callCount;
private String number;
public Form1()
{
InitializeComponent();
SystemState phonestate = new SystemState(SystemProperty.PhoneIncomingCall);
phonestate.Changed += new ChangeEventHandler(phonestate_Changed);
ListenCall();
#region 初始化屏蔽号码名单
DropCall.BannedList.Add("1 (312) 132-132");
DropCall.BannedList.Add("1 (234) 567-892");
DropCall.BannedList.Add("123");
#endregion
#region 挂载事件委托
//取得来电号码
SystemState state = new SystemState(SystemProperty.PhoneIncomingCallerNumber);
SystemState SS = new SystemState(SystemProperty.PhoneIncomingCall);
//添加事件
SS.Changed += new ChangeEventHandler(SS_Changed);
state.Changed += new ChangeEventHandler(state_Changed);
#endregion
}
#region 事件处理函数
void SS_Changed(object sender, ChangeEventArgs args)
{
try
{
if (DropCall.BannedList.Exists((s) =>
{
s = number;
return (from t in DropCall.BannedList
where t.Equals(s)
select t).Count() == 0 ? false : true;
}))
DropCall.Drop();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//状态的转换事件
void state_Changed(object sender, ChangeEventArgs args)
{
try
{
if (args.NewValue != null)
{
number = (String)args.NewValue;
MessageBox .Show ("NO:"+number);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
#endregion
private void menuItem1_Click(object sender, EventArgs e)
{
//退出程序
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
DropCall.BannedList.Add(textBox1 .Text .ToString ());
label1.Text ="设置成功!";
}
//监听来电
public void ListenCall()
{
callState = new SystemState(SystemProperty.PhoneCallTalking);
callCount = new SystemState(SystemProperty.PhoneActiveCallCount);
callState.Changed += new ChangeEventHandler(callState_Changed);
callCount.Changed += new ChangeEventHandler(callCount_Changed);
}
void callCount_Changed(object sender, ChangeEventArgs args)
{
if (args.NewValue != null && (int)args.NewValue != 0)
{
label1 .Text ="电话 Incomig.....";
}
callState = new SystemState(SystemProperty.PhoneCallCalling);
}
// 用来判断电话是否正在通话
void callState_Changed(object sender, ChangeEventArgs args)
{
if (args.NewValue != null)
{
String state = ((int)args.NewValue) == 1 ? "talking..." : "hang up";
//Form3 ff3 = new Form3();
//ff3.Record();
MessageBox.Show(state);
}
}
private void button2_Click(object sender, EventArgs e)
{
AcceptCall();
//Form3 f3 = new Form3();
//f3.Show();
}
public static void AcceptCall()
{
keybd_event((byte)Keys.F3, 0, 0, 0);
Thread.Sleep(500);
keybd_event((byte)Keys.F3, 0, KEYEVENTF_KEYUP, 0);
}
void phonestate_Changed(object sender, ChangeEventArgs args)
{
AcceptCall();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == System.Windows.Forms.Keys.Up))
{
// Up
}
if ((e.KeyCode == System.Windows.Forms.Keys.Down))
{
// Down
}
if ((e.KeyCode == System.Windows.Forms.Keys.Left))
{
// Left
}
if ((e.KeyCode == System.Windows.Forms.Keys.Right))
{
// Right
}
if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
{
// Enter
}
}
[DllImport("coredll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
private void Form1_Load(object sender, EventArgs e)
{
callState = new SystemState(Microsoft.WindowsMobile.Status.SystemProperty.PhoneCallTalking);
callCount = new SystemState(Microsoft.WindowsMobile.Status.SystemProperty.PhoneActiveCallCount);
//outcallState = new SystemState(Microsoft.WindowsMobile.Status.SystemProperty.PhoneCallCalling);
callState.EnableApplicationLauncher("Form1");
callCount.EnableApplicationLauncher("Form1");
//outcallState.EnableApplicationLauncher("Form1");
callState.Changed += new Microsoft.WindowsMobile.Status.ChangeEventHandler(callState_Changed);
callCount.Changed += new Microsoft.WindowsMobile.Status.ChangeEventHandler(callCount_Changed);
//outcallState.Changed += new Microsoft.WindowsMobile.Status.ChangeEventHandler(outcallState_Changed);
}
private void menuItem3_Click(object sender, EventArgs e)
{
//Form3 F2 = new Form3();
//F2.Show();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -