C#求帮解决个热键问题

planet 2010-05-17 11:10:25

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
}
}

}


...全文
75 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
nolgbbenny 2010-05-18
  • 打赏
  • 举报
回复
学习了
planet 2010-05-18
  • 打赏
  • 举报
回复
if (this.WindowState != FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;

}

为什么把this.ShowInTaskbar = false和this.ShowInTaskbar = true去掉,就行了呢!!!
只是不能达到把任务栏的也隐藏了!有什么办法解决呢!!!
planet 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jacksonfox 的回复:]
if (this.ShowInTaskbar)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskba = false;
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal……
[/Quote]

不行额··
JacksonFox 2010-05-18
  • 打赏
  • 举报
回复
if (this.ShowInTaskbar)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskba = false;
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;

}
a12321321321312321 2010-05-18
  • 打赏
  • 举报
回复


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);

}
a12321321321312321 2010-05-18
  • 打赏
  • 举报
回复
int i = this.Handle.ToInt32();
this.ShowInTaskbar = ! this.ShowInTaskbar;
int j = this.Handle.ToInt32();
a12321321321312321 2010-05-18
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20091112/20/7d2e42c7-625e-4963-aa1d-70377ce78cbd.html
planet 2010-05-18
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!
planet 2010-05-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jacksonfox 的回复:]
直接判读是否ShowInTaskbar不行吗?不用管是不是最小化。
[/Quote]

我的目的是,按1次Ctrl+Z隐藏窗体(包括任务栏中的),再按1次就是把他们再显示出来·
JacksonFox 2010-05-17
  • 打赏
  • 举报
回复
直接判读是否ShowInTaskbar不行吗?不用管是不是最小化。
planet 2010-05-17
  • 打赏
  • 举报
回复
有人能帮看看嘛!??
planet 2010-05-17
  • 打赏
  • 举报
回复
问题在于:
if (this.WindowState != FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;

}

如果把this.ShowInTaskbar = false;和this.ShowInTaskbar = true; 去掉后按Ctrl+Z就可以得来回显示窗体
那如果加上他们,应该如何修改才能实现呢?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧