热键无法处理表单加载
本文关键字:表单 加载 处理 | 更新日期: 2023-09-27 18:28:42
我有一个类要注册/注销热键。当应用程序以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();
}
你能告诉我我做错了什么吗。感谢
感谢大家的帮助,我看到了这个例子,它以更好的方式解释了一切:
http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html
hotkey = new GlobalHotkeys();
hotkey.RegisterGlobalHotKey( (int) Keys.F11, GlobalHotkeys.MOD_CONTROL, this.Handle);