111,126
社区成员
发帖
与我相关
我的任务
分享
[DllImport("user32")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
[DllImport("user32")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0312:
if (m.WParam.ToString() == "123")
{
this.Hide();
}
else if (m.WParam.ToString() == "456")
{
this.Visible = true;
}
break;
}
base.WndProc(ref m);
}
private void BookShelf_Load(object sender, EventArgs e)
{
//register:press [H] key to hide,and press [S] key to show
RegisterHotKey(this.Handle, 123, 1, Keys.H);
RegisterHotKey(this.Handle, 456, 1, Keys.S);
//这里1是shift,2是ctrl,0是两个都不要
}
private void BookShelf_FormClosed(object sender, FormClosedEventArgs e)
{
UnregisterHotKey(this.Handle, 123);
UnregisterHotKey(this.Handle, 456);
}