public partial class 捷通客户添加 : Form
{
static int cishu = 0;
public enum KeyModifiers //组合键枚举
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private void ProcessHotkey(Message m) //按下设定的键时调用该函数
{
IntPtr id = m.WParam; //IntPtr用于表示指针或句柄的平台特定类型
string sid = id.ToString();
switch (sid)
{
case "100":
{
MessageBox.Show("复制无效请勿尝试复制");
cishu = cishu + 1;
if (cishu > 4)
{
Application.Exit();
}
}
break;
case "200":
{
MessageBox.Show("剪切无效请勿尝试剪切");
cishu = cishu + 1;
if (cishu > 4)
{
Application.Exit();
}
}
break;
}
}
首先,这个代码拿过来就可以用,至于怎么分析我希望一起研究!
private void 捷通客户添加_Load(object sender, EventArgs e)
{
RegisterHotKey(Handle, 100, 2, Keys.C);
RegisterHotKey(Handle, 200, 2, Keys.X);
}
protected override void WndProc(ref Message m)//监视Windows消息
{
const int WM_HOTKEY = 0x0312;//如果m.Msg的值为0x0312那么表示用户按下了热键
switch (m.Msg)
{
case WM_HOTKEY:
ProcessHotkey(m);//按下热键时调用ProcessHotkey()函数
break;
}
base.WndProc(ref m); //将系统消息传递自父类的WndProc
}