CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

菜鸟问题,在C#中用RegisterHotKey热键怎么没有反应?

楼主sun900()2004-12-04 10:40:48 在 .NET技术 / C# 提问

//这样注册的  
  [DllImport("user32.dll",   EntryPoint="RegisterHotKey")]  
  public   static   extern   bool   RegisterHotKey(   IntPtr   hWnd, int   id,  
                                                                                    uint   fsModifiers,   uint   vk   );    
   
  我想按组合键ALT+A或者F10,(窗口句柄都没有问题)  
  ALT+A  
  RegisterHotKey(hWnd,99,1,65);  
  F10  
  RegisterHotKey(hWnd,999,0,121);  
   
  这两个都没有反应,怎么办?  
   
   
   
  问题点数:100、回复次数:6Top

1 楼sun900()回复于 2004-12-04 10:43:38 得分 0

我怀疑是参数给错了,就是不知道错在那,对的是什么Top

2 楼lucbesson(女娃哈哈)回复于 2004-12-04 22:35:59 得分 20

RegisterHotKey(hWnd,999,0,121);  
  RegisterHotKey(hWnd,99,1,65);  
  改成16进制    
  顺便查看一下windows定义消息,看看你的正确吗   ?Top

3 楼cnhgj(戏子) (没时间练太极)回复于 2004-12-04 22:41:14 得分 0

http://www.vccode.com/file_show.php?id=1863Top

4 楼cnhgj(戏子) (没时间练太极)回复于 2004-12-04 22:44:25 得分 30

不好意思,上面贴错了。。  
   
    TheAres(班门斧)   (   )   信誉:256     2002-11-23   20:40:32Z     得分:25    
     
     
       
  参考:  
  文章末尾有代码下载,是讲述如何使用RegisterHotKey来杀掉弹出窗口  
   
  弹出窗口杀手(上)  
  http://www.csdn.net/develop/read_article.asp?id=15534  
   
  弹出窗口杀手(下)      
  http://www.csdn.net/develop/read_article.asp?id=15535  
       
     
  Top

5 楼lucbesson(女娃哈哈)回复于 2004-12-04 23:01:05 得分 0

还有就是你要激活热键。  
  要不你只是注册了没什么用啊。。。。  
  http://dev.csdn.net/develop/article/43/43413.shtm  
   
  参考这个   然后去msdn上找   !Top

6 楼lucbesson(女娃哈哈)回复于 2004-12-04 23:04:19 得分 50

你在程序中需要自己注册全局热键,  
  用到API  
  RegisterHotKey  
  UnregisterHotKey  
   
   
  首先,创建一个WinHotKey类,如下  
  public   class   WinHotKey  
  {  
          [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  
          );  
   
          [Flags()]  
          public   enum   KeyModifiers  
          {  
  None   =   0,  
  Alt   =   1,  
  Control   =2,  
  Shift   =   4,  
  Windows   =   8  
          }  
   
          public   WinHotKey()  
          {  
  //  
  //   TODO:   在此处添加构造函数逻辑  
  //  
          }  
  }  
   
  然后,在程序中这样调用  
  //快捷键定义  
  private   bool   key_Ctrl   =   false;  
  private   bool   key_Shift   =   false;  
  private   bool   key_Alt   =   false;  
  private   bool   key_Windows   =   false;  
  private   Keys     key_other;  
   
  public   void   SetHotKey(bool   bCtrl,bool   bShift,bool   bAlt,bool    
  bWindows,Keys   nowKey)  
  {  
  try  
  {  
  this.key_Alt   =   bAlt;  
  this.key_Ctrl   =   bCtrl;  
  this.key_Shift   =   bShift;  
  this.key_Windows   =   bWindows;  
  this.key_other   =   nowKey;  
   
  WinHotKey.KeyModifiers   modifier   =   WinHotKey.KeyModifiers.None;  
   
  if(   this.key_Ctrl   )  
  modifier   |=   WinHotKey.KeyModifiers.Control;  
  if(this.key_Alt   )  
  modifier   |=   WinHotKey.KeyModifiers.Alt;  
  if(this.key_Shift)  
  modifier   |=   WinHotKey.KeyModifiers.Shift;  
  if(this.key_Windows)  
  modifier   |=   WinHotKey.KeyModifiers.Windows;  
   
  WinHotKey.RegisterHotKey(Handle,100,modifier,nowKey);  
  }  
  catch  
  {  
  //login.ShowMessage("快捷键定义错误!");  
  }  
  }  
   
  //激活热键  
  protected   override   void   WndProc(ref   Message   m   )  
  {  
  const   int   WM_HOTKEY   =   0x0312;    
   
  switch(m.Msg)  
  {  
  case   WM_HOTKEY:  
  {  
  //如果有新消息,弹出消息  
  if(   ReceiveNewMessage   ==   true)  
  {  
  for(int   i=0;i<this.manInforList.Count;i++)  
  {  
  ManInfor   searchMan   =   (ManInfor)this.manInforList[i];  
  if(   searchMan.manInforID.Equals(   getFriendID))  
  {  
  searchMan.Clicked   =   true;  
  searchMan.P2PShow();  
  break;  
  }  
  }  
  }  
  else  
  {  
  this.Show();  
  this.TopMost   =   true;  
  this.panel_Main.Refresh();  
  this.WindowState   =   System.Windows.Forms.FormWindowState.Normal;  
  }  
  }  
  break;  
  }    
  base.WndProc(ref   m   );  
  }  
   
  自己研究吧Top

相关问题

  • RegisterHotKey只能注册一个热键吗?
  • 请教一个有关C++ Builder5.0热键的问题
  • 在C++ Bulider中怎样屏闭系统热键F10
  • 如何通过RegisterHotKey函数动态注册热键?
  • 一个hwnd是不是只能RegisterHotKey一个热键?
  • 请问C#.net里面怎么实现 button的热键
  • 我想用RegisterHotKey设置系统热键,热键由THotKey控件获得,请问应该怎么做
  • 热键
  • 热键
  • 怎么将用RegisterHotkey定义的热键关连到特定的事件上?

关键词

  • .net
  • 注册
  • article
  • csdn
  • develop
  • dll
  • registerhotkey
  • 热键
  • winhotkey
  • bool

得分解答快速导航

  • 帖主:sun900
  • lucbesson
  • cnhgj
  • lucbesson

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo