2013-08-23 47 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'? –

回答