我有一个类来注册/取消注册热键。当应用程序以Form Load事件开始时,它可以正常工作。
private Hotkey myHotKey;
private IntPtr thisWindow;
private void Form1_Load(object sender, EventArgs e)
{
thisWindow = FindWindow(null, "Form1");
myHotKey = new Hotkey(thisWindow);
myHotKey.RegisterHotKeys();
}
现在的问题是我想在开始时隐藏应用程序在系统托盘中,但它没有注册我的主机密钥,当我在代码下面运行时它正在显示我Notify()和除了我的热键之外的其他东西没有效果。:
public Form1()
{
InitializeComponent();
notifyIcon1.ContextMenuStrip = contextMenuStrip1;
notifyIcon1.Click += notifyIcon1_Click;
notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
openToolStripMenuItem.Click += openToolStripMenuItem_Click;
exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
Notify("Application Name", "Application Started...", 1000);
thisWindow = FindWindow(null, "Form1");
myHotKey = new Hotkey(thisWindow);
myHotKey.RegisterHotKeys();
}
你能指导我做错了吗?谢谢
答案 0 :(得分:0)
谢谢大家的帮助,我遇到了这个以更好的方式解释一切的例子:
http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html
hotkey = new GlobalHotkeys();
hotkey.RegisterGlobalHotKey( (int) Keys.F11, GlobalHotkeys.MOD_CONTROL, this.Handle);