【发布时间】:2013-08-23 11:39:01
【问题描述】:
我有一个类来注册/取消注册热键。当应用程序以 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();
}
请您指导我做错了什么。谢谢
【问题讨论】:
-
在这里查看我的答案:stackoverflow.com/questions/15434505/…
-
FindWindow(null, "Form1")使用这个你想捕获当前表单的句柄吗?为什么不使用this.Handle?
标签: c# registerhotkey