C# 屏蔽系统热键 比如CTRL+ALT+DEL,WIN系列等

专业搬砖填坑 2008-10-25 02:44:00
现在要做的一项目牵扯到这个问题,所以问下,谢谢了。有现成的源码最好。
...全文
1772 31 打赏 收藏 转发到动态 举报
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
public void Start(bool InstallMouseHook, bool InstallKeyboardHook)
{
//disable shell tray bar
EnableTrayBar(false);
// install Mouse hook only if it is not installed and must be installed
if (hMouseHook == 0 && InstallMouseHook)
{
// Create an instance of HookProc.
MouseHookProcedure = new HookProc(MouseHookProc);
//install hook
hMouseHook = SetWindowsHookEx(
WH_MOUSE_LL,
MouseHookProcedure,
Marshal.GetHINSTANCE(
Assembly.GetExecutingAssembly().GetModules()[0]),
0);
//If SetWindowsHookEx fails.
if (hMouseHook == 0)
{
//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
int errorCode = Marshal.GetLastWin32Error();
//do cleanup
Stop(true, false, false);
//Initializes and throws a new instance of the Win32Exception class with the specified error.
throw new Win32Exception(errorCode); }
}
执行时上面红色地方报错,提示为:未处理:Win32Exception
  • 打赏
  • 举报
回复
public void Start(bool InstallMouseHook, bool InstallKeyboardHook)
{
//disable shell tray bar
EnableTrayBar(false);
// install Mouse hook only if it is not installed and must be installed
if (hMouseHook == 0 && InstallMouseHook)
{
// Create an instance of HookProc.
MouseHookProcedure = new HookProc(MouseHookProc);
//install hook
hMouseHook = SetWindowsHookEx(
WH_MOUSE_LL,
MouseHookProcedure,
Marshal.GetHINSTANCE(
Assembly.GetExecutingAssembly().GetModules()[0]),
0);
//If SetWindowsHookEx fails.
if (hMouseHook == 0)
{
//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
int errorCode = Marshal.GetLastWin32Error();
//do cleanup
Stop(true, false, false);
//Initializes and throws a new instance of the Win32Exception class with the specified error.
throw new Win32Exception(errorCode); }
}
执行时上面红色地方报错,提示为:未处理:Win32Exception
  • 打赏
  • 举报
回复
大侠们,求助…………
我把上面那位大哥的代码拷贝到我程序里面新建的cs文件里面,但是报错了……如图错误,请各位大哥帮忙解决下……
vincent200liu 2011-07-11
  • 打赏
  • 举报
回复
太强大了,多谢
88991193 2011-01-10
  • 打赏
  • 举报
回复
hongqi162 的代码好NB,直接把 任务栏也屏蔽了 任务栏上 点 左右鼠都没用
cppfaq 2009-10-14
  • 打赏
  • 举报
回复
进来拜一下
nixiang12 2009-05-18
  • 打赏
  • 举报
回复
受益匪浅啊 嘿嘿
freewind0521 2009-05-03
  • 打赏
  • 举报
回复
目前最好的屏蔽方法就是DirectInput 设置成独享键盘模式即可

否则CTRL ALT DEL屏蔽不了

这一招对所有版本的WINDOWS通吃 因为是硬件级别的屏蔽了
surewy 2008-12-08
  • 打赏
  • 举报
回复
mark
hm7921936 2008-12-04
  • 打赏
  • 举报
回复
mstj
A1027 2008-10-27
  • 打赏
  • 举报
回复
直接改注册表比较简单吧, 当能是程序中改
yinrongg 2008-10-27
  • 打赏
  • 举报
回复
有截咯
夏脑 2008-10-27
  • 打赏
  • 举报
回复
好东西,先试一下,正用得着.谢谢
yijianxiangde100 2008-10-27
  • 打赏
  • 举报
回复
值得收藏啊,这么好的代码?
yilunduyue 2008-10-27
  • 打赏
  • 举报
回复
up
sxmonsy 2008-10-27
  • 打赏
  • 举报
回复
踩一脚,然后收藏
baichangle 2008-10-27
  • 打赏
  • 举报
回复
留个脚印
shahe059 2008-10-27
  • 打赏
  • 举报
回复
路过先
zmr362 2008-10-27
  • 打赏
  • 举报
回复
谢谢受教了
东北大亨 2008-10-25
  • 打赏
  • 举报
回复
没有用过。
加载更多回复(11)

110,537

社区成员

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

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

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