当前位置: 首页 > news >正文

品牌网网站建设公司大连装修公司前十名

品牌网网站建设公司,大连装修公司前十名,电商小程序名字大全,舟山论坛网本文经原作者授权以原创方式二次分享#xff0c;欢迎转载、分享。原文作者#xff1a;唐宋元明清原文地址#xff1a;https://www.cnblogs.com/kybs0/p/12558056.htmlC# 禁用 全局快捷键给软件添加快捷键时#xff0c;经常遇到其它软件或者系统已设置的快捷键#xff0c;导… 本文经原作者授权以原创方式二次分享欢迎转载、分享。原文作者唐宋元明清原文地址https://www.cnblogs.com/kybs0/p/12558056.html  C# 禁用 全局快捷键给软件添加快捷键时经常遇到其它软件或者系统已设置的快捷键导致功能冲突。HotKey函数下面介绍一个user32.dll的RegisterHotKey以及UnregisterHotKey热键处理的函数;注册热键 RegisterHotKey function [1];BOOL RegisterHotKey(HWND hWnd, //响应热键的窗口句柄如果为空则注册到调用线程上Int id, //热键的唯一标识UINT fsModifiers, //热键的辅助按键UINT vk //热键的键值 );解除注册热键UnregisterHotKey function [2];BOOL WINAPI UnregisterHotKey( HWND hWnd,//热键注册的窗口 int  id//要解除注册的热键ID  );添加热键注册和注销函数Register方法 -  注册user32.dll函数RegisterHotKey以禁用全局键并在缓存内添加禁用记录;ProcessHotKey方法 - 外界全局键调用时调用回调函数;public class HotKeys{#region 注册快捷键/// summary/// 注册快捷键/// /summary/// param namemodifiers/param/// param namekey/parampublic void Register(int modifiers, Keys key){Register(IntPtr.Zero, modifiers, key);}/// summary/// 注册快捷键/// /summary/// param namehWnd/param/// param namemodifiers/param/// param namekey/param/// param namecallBack/parampublic void Register(IntPtr hWnd, int modifiers, Keys key, HotKeyCallBackHanlder callBack  null){var registerRecord  _hotkeyRegisterRecords.FirstOrDefault(i  i.IntPtr  hWnd  i.Modifiers  modifiers  i.Key  key);if (registerRecord ! null){UnregisterHotKey(hWnd, registerRecord.Id);_hotkeyRegisterRecords.Remove(registerRecord);}int id  registerId;if (!RegisterHotKey(hWnd, id, modifiers, key))throw new Exception(注册失败);_hotkeyRegisterRecords.Add(new HotkeyRegisterRecord(){Id  id,IntPtr  hWnd,Modifiers  modifiers,Key  key,CallBack  callBack});}#endregion#region 注销快捷键/// summary/// 注销快捷键/// /summary/// param namehWnd/param/// param namemodifiers/param/// param namekey/parampublic void UnRegister(IntPtr hWnd, int modifiers, Keys key){var registerRecord  _hotkeyRegisterRecords.FirstOrDefault(i  i.IntPtr  hWnd  i.Modifiers  modifiers  i.Key  key);if (registerRecord ! null){UnregisterHotKey(hWnd, registerRecord.Id);_hotkeyRegisterRecords.Remove(registerRecord);}}/// summary/// 注销快捷键/// /summary/// param namemodifiers/param/// param namekey/parampublic void UnRegister(int modifiers, Keys key){var registerRecord  _hotkeyRegisterRecords.FirstOrDefault(i  i.IntPtr  IntPtr.Zero  i.Modifiers  modifiers  i.Key  key);if (registerRecord ! null){UnregisterHotKey(IntPtr.Zero, registerRecord.Id);_hotkeyRegisterRecords.Remove(registerRecord);}}/// summary/// 注销快捷键/// /summary/// param namehWnd/parampublic void UnRegister(IntPtr hWnd){var registerRecords  _hotkeyRegisterRecords.Where(i  i.IntPtr  hWnd);//注销所有foreach (var registerRecord in registerRecords){UnregisterHotKey(hWnd, registerRecord.Id);_hotkeyRegisterRecords.Remove(registerRecord);}}#endregion#region 快捷键消息处理// 快捷键消息处理public void ProcessHotKey(Message message){ProcessHotKey(message.Msg, message.WParam);}/// summary/// 快捷键消息处理/// /summary/// param namemsg/param/// param namewParam消息Id/parampublic void ProcessHotKey(int msg, IntPtr wParam){if (msg  0x312){int id  wParam.ToInt32();var registerRecord  _hotkeyRegisterRecords.FirstOrDefault(i  i.Id  id);registerRecord?.CallBack?.Invoke();}}#endregion#region MyRegion//引入系统API[DllImport(user32.dll)]static extern bool RegisterHotKey(IntPtr hWnd, int id, int modifiers, Keys vk);[DllImport(user32.dll)]static extern bool UnregisterHotKey(IntPtr hWnd, int id);//标识-区分不同的快捷键int registerId  10;//添加key值注册字典后续调用时有回调处理函数private readonly ListHotkeyRegisterRecord _hotkeyRegisterRecords  new ListHotkeyRegisterRecord();public delegate void HotKeyCallBackHanlder();#endregion}public class HotkeyRegisterRecord{public IntPtr IntPtr { get; set; }public int Modifiers { get; set; }public Keys Key { get; set; }public int Id { get; set; }public HotKeys.HotKeyCallBackHanlder CallBack { get; set; }}//组合控制键public enum HotkeyModifiers{Alt  1,Control  2,Shift  4,Win  8}在上方的HotKeys类中注册方法Register提供了一个回调函数后续监听到外界全局键时可以通知回调函数处理。参数WParam是窗口响应时快捷键值在winform和WPF窗口消息函数中都是有的。另组合快捷键内部枚举类HotkeyModifiers枚举值来自官网文档WM_HOTKEY message;无感知禁用全局快捷键比如禁用CtrlAlt1、CtrlAlt2、CtrlAlt3、CtrlAlt4Windows桌面图标大小的调节快捷键;HotKeys hotKeys  new HotKeys();hotKeys.Register((int)HotkeyModifiers.Control, Keys.N);hotKeys.Register((int)HotkeyModifiers.Control  (int)HotkeyModifiers.Alt, Keys.D1);hotKeys.Register((int)HotkeyModifiers.Control  (int)HotkeyModifiers.Alt, Keys.D2);hotKeys.Register((int)HotkeyModifiers.Control  (int)HotkeyModifiers.Alt, Keys.D3);hotKeys.Register((int)HotkeyModifiers.Control  (int)HotkeyModifiers.Alt, Keys.D4);注窗口句柄参数如果提供空的话则注册到调用线程上。Keys类型在system.windows.Forms程序集下如果是WPF的Key可以使用KeyInterop将Wpf键值类型转换为Winform键值再调用此函数。无感知禁用全局快捷键后回调如果禁用全局快捷键的同时外界触发快捷键时需要此程序回调处理可以添加窗口消息处理1 新建一个类HotKeyHandleWindow继承自Window;窗口样式 - 高宽为0窗口样式None;添加热键注册的调用;添加WndProc处理窗口消息;public class HotKeyHandleWindow : Window{private readonly HotKeys _hotKeys  new HotKeys();public HotKeyHandleWindow(){WindowStyle  WindowStyle.None;Width  0;Height  0;Loaded  (s, e) {//这里注册了CtrlAlt1 快捷键_hotKeys.Register(new WindowInteropHelper(this).Handle,(int)HotkeyModifiers.Control  (int)HotkeyModifiers.Alt, Keys.D1, CallBack);};}protected override void OnSourceInitialized(EventArgs e){base.OnSourceInitialized(e);var hwndSource  PresentationSource.FromVisual(this) as HwndSource;hwndSource?.AddHook(new HwndSourceHook(WndProc));}public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled){//窗口消息处理函数_hotKeys.ProcessHotKey(msg, wParam);return hwnd;}//按下快捷键时被调用的方法public void CallBack(){}}2调用窗口类;var hotKeyHandleWindow  new HotKeyHandleWindow(); hotKeyHandleWindow.Show(); hotKeyHandleWindow.Hide();以上有回调响应但是也是无感知的。源码下载[3]参考资料[1]RegisterHotKey function : https://docs.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-registerhotkey?redirectedfromMSDN[2]UnregisterHotKey function : https://docs.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-unregisterhotkey[3]源码下载: https://github.com/Kybs0/DiableGlobalShortcuts
http://www.lebaoying.cn/news/65146.html

相关文章:

  • 响应式网站建设的未来发展6做网站建设
  • wordpress更改站点国内网站备案
  • 做淘宝网站要多少钱wordpress dxc
  • 阿里巴巴网站建设目标建设限额哪里看
  • php网站开发接口文档iis7 网站权限
  • 个人博客网站总结网站服务
  • 2018威胁网站检测平台建设专业建公司网站
  • 中建八局招聘出国劳务兰州做网站优化的公司
  • 最好的微网站建设公司推荐腾讯云部署wordpress
  • 苏州网站模板建站传奇做网站空间
  • 黄页营销网站个人网站布局下载
  • 秦皇岛市城乡建设局网站媒体门户网站建设方案
  • 做网站推广可行吗信用家装修网官网
  • ps线下培训班一般学费多少什么是优化营商环境
  • 《高性能网站建设》建设厅企业锁在哪个网站登录
  • 成都建网站多少钱郴州网站建设哪家好
  • c 做网站源码实例深圳公司的网站设计
  • 东莞响应式网站制作浏览器在线打开
  • 上海做网站的公司哪家好上线了做网站怎么查看
  • 网站建设合同服务内容上海公司做网站的价格
  • 古镇网站建设洛阳网红打卡地
  • 网站模板为什么不好跨境电商公司招聘岗位及要求
  • 洛阳网站的优化设计高端的国外网站
  • 网站首页添加代码网站转化低的原因
  • 一个网站开发小组自己制作免费网页
  • 免费的行情软件网站下载想学计算机怎么入门
  • 甘肃省住房和建设厅网站首页创意设计网站公司
  • 南京网站seo专家wordpress上传ftp失败
  • 网站建设 中企动力厨具wordpress带微信二维码
  • 如何用api做网站招工网站服务