2013-08-23 114 views
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(); 

     } 

现在的问题是我想在开始隐藏在系统托盘中的应用,但它不是注册我的主机密钥,当我运行下面的代码它显示的是我成功的通知()和除了我的热键其他东西都没有效果。:

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

见我的答案在这里:http://stackoverflow.com/questions/15434505/key-capture-using-global/hotkey-in -c-sharp/15434675#15434675 –

+0

FindWindow(null,“Form1”)'使用这个你试图捕获当前窗体的句柄?为什么不使用'this.Handle'? –

回答