0

我有一堂课来注册/注销热键。当应用程序以 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();
}

你能指导我我做错了什么吗?谢谢

4

1 回答 1

0

感谢大家的帮助,我遇到了这个例子,它以更好的方式解释了一切:

http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html

hotkey = new GlobalHotkeys();
hotkey.RegisterGlobalHotKey( (int) Keys.F11, GlobalHotkeys.MOD_CONTROL, this.Handle);
于 2013-08-23T13:08:38.813 回答