设置好快捷键之后,窗体Hide()了再Show(),或者this.Visible = false后再ture,快捷键就失效了,怎么回事呢,高手帮忙看下
我是这么设置快捷键的,RegisterHotKey(Handle, 100, (KeyModifiers)4, Keys.A);
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd,int id);
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4, } protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312; switch (m.Msg)
{
case WM_HOTKEY:
…… break;
} base.WndProc(ref m);
}
我是这么设置快捷键的,RegisterHotKey(Handle, 100, (KeyModifiers)4, Keys.A);
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd,int id);
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4, } protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312; switch (m.Msg)
{
case WM_HOTKEY:
…… break;
} base.WndProc(ref m);
}
先设置ShowInTaskbar,然后登记热键。
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
ShowWindow(this.Handle, 0);
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
}
把this.ShowInTaskbar = false;去掉或在该行后重新注册热键。