110,538
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace 热键2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Activated_1(object sender, EventArgs e)
{
HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Ctrl, Keys.Z);
}
private void Form1_Leave_1(object sender, EventArgs e)
{
HotKey.UnregisterHotKey(Handle, 100);
}
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
if (WM_HOTKEY == m.Msg)
{
switch (m.WParam.ToInt32())
{
case 100:
if (this.WindowState != FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
}
break;
}
}
base.WndProc(ref m);
}
}
class HotKey
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
public enum KeyModifiers
{
None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4,
WindowsKey = 8
}
}
}
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
if (m.Msg == WM_HOTKEY && m.WParam.ToInt32()==100)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Height = 516;
this.Width = 715;
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
//this.Visible = true;
this.Focus();
//this.notifyIcon1.Visible = false;
}
else
{
this.Height = 516;
this.Width = 715;
this.WindowState = FormWindowState.Minimized;
//this.Visible = false;
this.ShowInTaskbar = false;
//skinEngine1.SkinFile = "WaveColor1.ssk";
//this.notifyIcon1.Visible = true;
}
}
HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Ctrl, Keys.B);
base.WndProc(ref m);
}