求用快捷键实现最大最小化窗体到托盘.
网上有直接加的,那种方式可以实现.可是利用快捷键怎么也不实现不了.现在我写了一部分.
只是实现了按了F12后最小化了,可是再按时就出错了.
请高手指教. 为了不影响大家的思路,先不贴我写的代码.
网上有直接加的,那种方式可以实现.可是利用快捷键怎么也不实现不了.现在我写了一部分.
只是实现了按了F12后最小化了,可是再按时就出错了.
请高手指教. 为了不影响大家的思路,先不贴我写的代码.
解决方案 »
- 想做一个检测软件自身运行繁忙程度的功能,请给个思路
- C#中修改、添加数据问题
- 关于c#调用c++写的DLL的参数类型问题
- 急急!!!无法加载 DLL“xxx_dll” 找不到指定的模块。 (异常来自 HRESULT0x8007007E)
- 安装程序无法找到msi包(在线等)
- c#怎么隐藏一个excel表的列?
- 100分请教高手:关于一键登录多QQ程序的开发方法
- 请问大家有没人知道怎样在C#下将根目录的所有文件,复制到指定的目录下啊!
- 各位大大帮我看看哪里错了呢?(update时的错误)
- C# 如何控制 多人同时插入、更新数据库表。
- 请教高手,如何替换字符串中的'\'字符!
- 只剩70分全奉上。一个搞了好久没有搞定的问题。(快疯了)
1.注册/删除热键问题
2.最大最小化窗体到托盘.第2个问题不说了,太简单了,我觉得你的问题可能是注册热键.帖一段我写的代码给你看看: /// <summary>
/// 自定义控制键枚举
/// </summary>
[Flags()]
public enum KeyModifiers
{
None = 11,
Alt = 12,
Control = 13,
Shift = 14,
Windows = 15
}
//为窗体注册热键
[DllImport("user32.dll", SetLastError=true)]
public static extern bool RegisterHotKey(int hWnd,int id,KeyModifiers fsModifiers,Keys vk);
//为窗体注销热键
[DllImport("user32.dll", SetLastError=true)]
public static extern bool UnregisterHotKey(int hWnd,int id);
public Keys m_hotkey;
public bool m_ctrlhotkey, m_shifthotkey, m_althotkey, m_winhotkey; public HotKeys()
{
} public HotKeys(Keys c, bool bCtrl, bool bShift, bool bAlt, bool bWindows)
{
this.m_hotkey = c;
this.m_althotkey = bAlt;
this.m_ctrlhotkey = bCtrl;
this.m_shifthotkey = bShift;
this.m_winhotkey = bWindows;
}
Alt = 12,
Control = 13,
Shift = 14,
Windows = 15
你这部分是随便写的值吗?
System.Timers.Timer tim;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError=true)]
public static extern short GetAsyncKeyState(int id);
private void Form1_Load(object sender, System.EventArgs e)
{
tim=new System.Timers.Timer(1);
tim.Elapsed+=new System.Timers.ElapsedEventHandler(tim_Elapsed);
tim.Start();
}
private void tim_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
short s=GetAsyncKeyState(123);//123 就是F12
if(s<0)
{
this.Visible=false;//这里写你要干什么,要是还有问题,字条我
}
}
if(s<0)
{
//this.Visible=false;//这里写你要干什么,要是还有问题,字条我
if(iStat==0)
{
隐藏;
iStat=1;
}
else
{
打开;
iStat=0;
}
}
?
F12不行.其它都行.不知道为什么?======================================2种可能,你的f12坏掉了,你的F12被注册过了,关掉所有程序,跑一次.注意关掉VS
如下是Ctrl+F12public const uint MOD_ALT = 1;
public const uint MOD_CONTROL = 2;
public const uint MOD_SHIFT = 4;
public const uint MOD_WIN = 8;
private const int F12IDENT = 0x0010;
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id,
uint fsModifiers, int vk);[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);private void Form1_Load(object sender, EventArgs e)
{
RegisterHotKey(Handle, F12IDENT, MOD_CONTROL, (int)Keys.F12);
}private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
UnregisterHotKey(Handle, F12IDENT);
}
public const int WM_HOTKEY = 0x0312;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_HOTKEY:
if (m.WParam == (IntPtr)F12IDENT)
MessageBox.Show("Zswang 路过");
break;
}
}