📄 mainform.cs
字号:
using Microsoft.WindowsCE.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Status;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using SmartAnswerCall.处理类;
namespace SmartAnswerCall
{
public partial class MainForm : Form
{
private SystemState _phoneCallContactState = new SystemState(SystemProperty.PhoneIncomingCall);
private SystemState _phoneCallTalkState = new SystemState(SystemProperty.PhoneCallTalking);
private IntPtr hPhone;
private bool keybd_event_flag = false;
private const int KEYEVENTF_KEYDOWN = 0;
private const int KEYEVENTF_KEYUP = 2;
private uint lResult;
private IntPtr m_hLineApp = IntPtr.Zero;
private byte minute;
private OutlookSession mySession = new OutlookSession();
private string PhoneName;
private bool ringing = false;
private byte second;
private int spec_Second;
private bool talking = false;
private WaveIn wi;
private WaveOut wo;
public MainForm()
{
this.InitializeComponent();
this._phoneCallContactState.Changed += new ChangeEventHandler(this._phoneCallContactState_Changed);
this._phoneCallTalkState.Changed += new ChangeEventHandler(this._phoneCallTalkState_Changed);
}
private void _phoneCallContactState_Changed(object sender, ChangeEventArgs args)
{
if (this.menuItem1.Text == "关 ")
{
if (!this.ringing)
{
this.ringing = true;
this.keybd_event_flag = false;
Thread.Sleep((int) (this.DelayBar.Value * 0x3e8));
if (SystemState.PhoneIncomingCall)
{
DateTime now = DateTime.Now;
if (((string) SystemState.GetValue(SystemProperty.PhoneIncomingCallerName)) != "")
{
this.treeView.Nodes.Insert(0, new TreeNode(((string) SystemState.GetValue(SystemProperty.PhoneIncomingCallerName)) + "_" + now.Minute.ToString() + now.Second.ToString()));
}
else
{
this.treeView.Nodes.Insert(0, new TreeNode((string) SystemState.GetValue(SystemProperty.PhoneIncomingCallerNumber)));
}
this.treeView.Nodes[0].Nodes.Add("电话 №: " + ((string) SystemState.GetValue(SystemProperty.PhoneIncomingCallerNumber)));
this.treeView.Nodes[0].Nodes.Add("播放 ");
this.treeView.Nodes[0].Nodes.Add("日期: " + now.ToLongTimeString());
this.treeView.Nodes[0].Nodes.Add("蓝浪软件");
this.PhoneName = (string) SystemState.GetValue(SystemProperty.PhoneIncomingCallerName);
keybd_event(0x72, 0, 0, 0);
keybd_event(0x72, 0, 2, 0);
this.keybd_event_flag = true;
}
}
else
{
this.ringing = false;
}
}
}
private void _phoneCallTalkState_Changed(object sender, ChangeEventArgs args)
{
if ((this.menuItem1.Text == "关 ") && this.keybd_event_flag)
{
if (!this.talking)
{
uint num3;
if (File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\templates\" + this.PhoneName + ".wav"))
{
this.wo = new WaveOut();
this.wo.Play(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\templates\" + this.PhoneName + ".wav", 0x100000, 0xffff, 0xffff);
Thread.Sleep((int) this.wo.Milliseconds());
}
else
{
this.wo = new WaveOut();
this.wo.Play(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\templates\Other.wav", 0x100000, 0xffff, 0xffff);
Thread.Sleep((int) this.wo.Milliseconds());
}
this.wo = new WaveOut();
this.wo.Play(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\templates\beep.wav", 0x100000, 0xffff, 0xffff);
Thread.Sleep((int) this.wo.Milliseconds());
this.minute = 0;
this.second = 0;
this.spec_Second = 0;
this.timer.Enabled = true;
this.wi = new WaveIn();
this.wi.Preload(this.RecordBar.Value * 0x3e8, 0x100000);
this.wi.Start();
uint lpdwAPIVersion = 0x20000;
IntPtr zero = IntPtr.Zero;
TAPI.LPPHONEINITIALIZEEXPARAMS structure = new TAPI.LPPHONEINITIALIZEEXPARAMS();
structure.dwTotalSize = (uint) Marshal.SizeOf(structure);
structure.dwNeededSize = structure.dwTotalSize;
structure.dwUsedSize = structure.dwTotalSize;
structure.hEvent = IntPtr.Zero;
structure.dwOptions = 2;
TAPI.phoneInitializeEx(out this.m_hLineApp, zero, IntPtr.Zero, "Test", out num3, ref lpdwAPIVersion, ref structure);
bool flag = false;
for (uint i = 0; (i < num3) && !flag; i++)
{
IntPtr ptr2;
IntPtr ptr3;
this.lResult = TAPI.phoneNegotiateAPIVersion(this.m_hLineApp, i, 0x10004, 0x20001, out ptr2, IntPtr.Zero);
this.lResult = TAPI.phoneNegotiateExtVersion(this.m_hLineApp, i, ptr2, 0, 0x10004, out ptr3);
this.lResult = TAPI.phoneOpen(this.m_hLineApp, i, out this.hPhone, ptr2, IntPtr.Zero, IntPtr.Zero, 2);
this.lResult = TAPI.phoneSetHookSwitch(IntPtr.Zero, 4, 4);
this.lResult = TAPI.phoneSetHookSwitch(this.hPhone, 4, 4);
}
this.talking = true;
}
else
{
this.lResult = TAPI.phoneSetHookSwitch(this.hPhone, 4, 8);
this.lResult = TAPI.phoneClose(this.hPhone);
this.lResult = TAPI.phoneShutdown(this.m_hLineApp);
try
{
//MessageBox.Show(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" + this.treeView.Nodes[0].Text + ".wav");
this.wi.Save(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" + this.treeView.Nodes[0].Text + ".wav");
}
catch
{
}
this.talking = false;
this.timer.Enabled = false;
this.treeView.Nodes[0].Nodes.Add(string.Concat(new object[] { "长度: ", this.minute, "m ", this.second, "s" }));
SetForegroundWindow(FindWindowCE(null, "iSecretary"));
}
}
}
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
this.wi = new WaveIn();
this.wi.Preload(this.RecordBar.Value * 0x3e8, 0x100000);
this.wi.Start();
this.label9.Text = "正在录制... ";
}
private void button2_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
if (this.wi != null)
{
this.wi.Stop();
}
this.label9.Text = "";
new Sound(string.Concat(new object[] { Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), @"\templates\", this.listBox1.Items[this.listBox1.SelectedIndex], ".wav" })).Play();
}
private void button3_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
if (this.listBox1.Items.Count > 0)
{
this.wi.Save(string.Concat(new object[] { Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), @"\templates\", this.listBox1.Items[this.listBox1.SelectedIndex], ".wav" }));
this.label9.Text = "";
}
}
private void button4_Click(object sender, EventArgs e)
{
//if ((this.textBox1.Text != this.Encrypt(this.textBox2.Text, 10)) || (this.textBox2.TextLength < 4))
//{
// MessageBox.Show("注册码错误。 ");
//}
//else
//{
this.RecordBar.Enabled = true;
this.DelayBar.Enabled = true;
//MessageBox.Show("已注册。 ");
this.panel3.Hide();
//}
}
//加密算法
public string Encrypt(string s, ushort sk)
{
ushort num = 0x5ae;
ushort num2 = 0x926;
ushort num3 = sk;
string str = "";
Encoding dstEncoding = Encoding.GetEncoding(0x4e3);
byte[] bytes = Encoding.Unicode.GetBytes(s);
byte[] buffer2 = Encoding.Convert(Encoding.Unicode, dstEncoding, bytes);
for (int i = 0; i < buffer2.Length; i++)
{
byte num4 = (byte) (buffer2[i] ^ (num3 >> 8));
num3 = (ushort) (((num4 + num3) * num) + num2);
str = str + num4.ToString("X2");
}
return str;
}
[DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)]
private static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);
[DllImport("coredll.dll", CharSet=CharSet.Unicode)]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private void MainForm_Closing(object sender, CancelEventArgs e)
{
StreamWriter writer = File.CreateText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\iSecretary.cfg");
writer.WriteLine(this.textBox2.Text);
writer.WriteLine(this.textBox1.Text);
writer.WriteLine(this.RecordBar.Value.ToString());
writer.WriteLine(this.DelayBar.Value.ToString());
writer.Close();
}
private void MainForm_Load(object sender, EventArgs e)
{
StreamReader reader = File.OpenText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\iSecretary.cfg");
this.textBox2.Text = reader.ReadLine();
this.textBox1.Text = reader.ReadLine();
if ((this.textBox1.Text == this.Encrypt(this.textBox2.Text, 10)) && (this.textBox2.TextLength > 4))
{
this.RecordBar.Enabled = true;
this.RecordBar.Value = Convert.ToInt32(reader.ReadLine());
this.DelayBar.Enabled = true;
this.DelayBar.Value = Convert.ToInt32(reader.ReadLine());
this.panel3.Hide();
}
reader.Close();
for (int i = 0; i < this.mySession.Contacts.Items.Count; i++)
{
this.listBox1.Items.Add(this.mySession.Contacts.Items[i].FileAs);
}
this.listBox1.Items.Insert(0, "其他 ");
}
private void menuItem1_Click(object sender, EventArgs e)
{
if (this.menuItem1.Text == "关 ")
{
this.menuItem1.Text = "On";
}
else
{
this.menuItem1.Text = "关 ";
}
}
private void menuItem2_Click(object sender, EventArgs e)
{
base.Close();
}
private void menuItem3_Click(object sender, EventArgs e)
{
File.Delete(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\templates\" + this.listBox1.SelectedItem.ToString() + ".wav");
}
private void pCallBack(uint hDevice, uint dwMessage, uint dwInstance, uint dwParam1, uint dwParam2, uint dwParam3)
{
}
[DllImport("coredll.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void timer_Tick(object sender, EventArgs e)
{
this.second = (byte) (this.second + 1);
if (this.second == 60)
{
this.minute = (byte) (this.minute + 1);
this.second = 0;
}
this.spec_Second++;
if (this.spec_Second >= this.RecordBar.Value)
{
keybd_event(0x73, 0, 0, 0);
keybd_event(0x73, 0, 2, 0);
}
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
this.label5.Text = this.DelayBar.Value.ToString() + "s.";
}
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
this.label6.Text = this.RecordBar.Value.ToString() + "s.";
}
private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Text == "播放 ")
{
MessageBox.Show("播放 ");
new Sound(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" + e.Node.Parent.Text + ".wav").Play();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -