CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

钩——拦截所有的事件(Mouse,Keyboard)

楼主tg123(T.G.)2001-07-30 23:42:53 在 VB / 基础类 提问

问题点数:88、回复次数:22Top

1 楼tg123(T.G.)回复于 2001-07-30 23:44:13 得分 0

先答对  
  还有分零  
  http://www.csdn.net/expert/topic/26/26219.shtmTop

2 楼xyjdn(项有建^_^)回复于 2001-07-30 23:48:37 得分 0

gzTop

3 楼wyzegg(蛋)回复于 2001-07-30 23:51:41 得分 0

简单    
  The   SetWindowsHookEx   function   installs   an   application-defined   hook   procedure   into   a   hook   chain.   You   would   install   a   hook   procedure   to   monitor   the   system   for   certain   types   of   events.   These   events   are   associated   either   with   a   specific   thread   or   with   all   threads   in   the   system.    
   
  HHOOK   SetWindowsHookEx(  
      int   idHook,                 //   type   of   hook   to   install  
      HOOKPROC   lpfn,           //   address   of   hook   procedure  
      HINSTANCE   hMod,         //   handle   to   application   instance  
      DWORD   dwThreadId       //   identity   of   thread   to   install   hook   for  
  );  
     
  Parameters  
  idHook    
  Specifies   the   type   of   hook   procedure   to   be   installed.   This   parameter   can   be   one   of   the   following   values:   Value   Description    
  WH_CALLWNDPROC   Installs   a   hook   procedure   that   monitors   messages   before   the   system   sends   them   to   the   destination   window   procedure.   For   more   information,   see   the   CallWndProc   hook   procedure.    
  WH_CALLWNDPROCRET   Installs   a   hook   procedure   that   monitors   messages   after   they   have   been   processed   by   the   destination   window   procedure.   For   more   information,   see   the   CallWndRetProc   hook   procedure.    
  WH_CBT   Installs   a   hook   procedure   that   receives   notifications   useful   to   a   computer-based   training   (CBT)   application.   For   more   information,   see   the   CBTProc   hook   procedure.    
  WH_DEBUG   Installs   a   hook   procedure   useful   for   debugging   other   hook   procedures.   For   more   information,   see   the   DebugProc   hook   procedure.    
  WH_FOREGROUNDIDLE   Installs   a   hook   procedure   that   will   be   called   when   the   application's   foreground   thread   is   about   to   become   idle.   This   hook   is   useful   for   performing   low   priority   tasks   during   idle   time.   For   more   information,   see   the   ForegroundIdleProc   hook   procedure.      
  WH_GETMESSAGE   Installs   a   hook   procedure   that   monitors   messages   posted   to   a   message   queue.   For   more   information,   see   the   GetMsgProc   hook   procedure.    
  WH_JOURNALPLAYBACK   Installs   a   hook   procedure   that   posts   messages   previously   recorded   by   a   WH_JOURNALRECORD   hook   procedure.   For   more   information,   see   the   JournalPlaybackProc   hook   procedure.    
  WH_JOURNALRECORD   Installs   a   hook   procedure   that   records   input   messages   posted   to   the   system   message   queue.   This   hook   is   useful   for   recording   macros.   For   more   information,   see   the   JournalRecordProc   hook   procedure.    
  WH_KEYBOARD   Installs   a   hook   procedure   that   monitors   keystroke   messages.   For   more   information,   see   the   KeyboardProc   hook   procedure.    
  WH_KEYBOARD_LL   Windows   NT:   Installs   a   hook   procedure   that   monitors   low-level   keyboard   input   events.   For   more   information,   see   the   LowLevelKeyboardProc   hook   procedure.    
  WH_MOUSE   Installs   a   hook   procedure   that   monitors   mouse   messages.   For   more   information,   see   the   MouseProc   hook   procedure.    
  WH_MOUSE_LL   Windows   NT:   Installs   a   hook   procedure   that   monitors   low-level   mouse   input   events.   For   more   information,   see   the   LowLevelMouseProc   hook   procedure.    
  WH_MSGFILTER   Installs   a   hook   procedure   that   monitors   messages   generated   as   a   result   of   an   input   event   in   a   dialog   box,   message   box,   menu,   or   scroll   bar.   For   more   information,   see   the   MessageProc   hook   procedure.    
  WH_SHELL   Installs   a   hook   procedure   that   receives   notifications   useful   to   shell   applications.   For   more   information,   see   the   ShellProc   hook   procedure.    
  WH_SYSMSGFILTER   Installs   a   hook   procedure   that   monitors   messages   generated   as   a   result   of   an   input   event   in   a   dialog   box,   message   box,   menu,   or   scroll   bar.   The   hook   procedure   monitors   these   messages   for   all   applications   in   the   system.   For   more   information,   see   the   SysMsgProc   hook   procedure.    
   
   
  lpfn    
  Pointer   to   the   hook   procedure.   If   the   dwThreadId   parameter   is   zero   or   specifies   the   identifier   of   a   thread   created   by   a   different   process,   the   lpfn   parameter   must   point   to   a   hook   procedure   in   a   dynamic-link   library   (DLL).   Otherwise,   lpfn   can   point   to   a   hook   procedure   in   the   code   associated   with   the   current   process.    
  hMod    
  Handle   to   the   DLL   containing   the   hook   procedure   pointed   to   by   the   lpfn   parameter.   The   hMod   parameter   must   be   set   to   NULL   if   the   dwThreadId   parameter   specifies   a   thread   created   by   the   current   process   and   if   the   hook   procedure   is   within   the   code   associated   with   the   current   process.    
  dwThreadId    
  Specifies   the   identifier   of   the   thread   with   which   the   hook   procedure   is   to   be   associated.   If   this   parameter   is   zero,   the   hook   procedure   is   associated   with   all   existing   threads.    
  Return   Values  
  If   the   function   succeeds,   the   return   value   is   the   handle   to   the   hook   procedure.    
   
  If   the   function   fails,   the   return   value   is   NULL.   To   get   extended   error   information,   call   GetLastError.  
   
  Remarks  
  An   error   may   occur   if   the   hMod   parameter   is   NULL   and   the   dwThreadId   parameter   is   zero   or   specifies   the   identifier   of   a   thread   created   by   another   process.    
   
  Calling   the   CallNextHookEx   function   to   chain   to   the   next   hook   procedure   is   optional,   but   it   is   highly   recommended;   otherwise,   other   applications   that   have   installed   hooks   will   not   receive   hook   notifications   and   may   behave   incorrectly   as   a   result.   You   should   call   CallNextHookEx   unless   you   absolutely   need   to   prevent   the   notification   from   being   seen   by   other   applications.    
   
  Before   terminating,   an   application   must   call   the   UnhookWindowsHookEx   function   to   free   system   resources   associated   with   the   hook.    
   
  The   scope   of   a   hook   depends   on   the   hook   type.   Some   hooks   can   be   set   only   with   system   scope;   others   can   also   be   set   for   only   a   specific   thread,   as   shown   in   the   following   list:    
   
  Hook   Scope    
  WH_CALLWNDPROC   Thread   or   system    
  WH_CALLWNDPROCRET   Thread   or   system    
  WH_CBT   Thread   or   system    
  WH_DEBUG   Thread   or   system    
  WH_FOREGROUNDIDLE   Thread   or   system    
  WH_GETMESSAGE   Thread   or   system    
  WH_JOURNALPLAYBACK   System   only    
  WH_JOURNALRECORD   System   only    
  WH_KEYBOARD   Thread   or   system    
  WH_KEYBOARD_LL   Thread   or   system    
  WH_MOUSE   Thread   or   system    
  WH_MOUSE_LL   Thread   or   system    
  WH_MSGFILTER   Thread   or   system    
  WH_SHELL   Thread   or   system    
  WH_SYSMSGFILTER   System   only    
   
   
  For   a   specified   hook   type,   thread   hooks   are   called   first,   then   system   hooks.    
   
  The   system   hooks   are   a   shared   resource,   and   installing   one   affects   all   applications.   All   system   hook   functions   must   be   in   libraries.   System   hooks   should   be   restricted   to   special-purpose   applications   or   to   use   as   a   development   aid   during   application   debugging.   Libraries   that   no   longer   need   a   hook   should   remove   the   hook   procedure.    
   
  QuickInfo  
      Windows   NT:   Requires   version   3.1   or   later.  
      Windows:   Requires   Windows   95   or   later.  
      Windows   CE:   Unsupported.  
      Header:   Declared   in   winuser.h.  
      Import   Library:   Use   user32.lib.  
      Unicode:   Implemented   as   Unicode   and   ANSI   versions   on   Windows   NT.  
   
  See   Also  
  Hooks   Overview,   Hook   Functions,   CallNextHookEx,   CallWndProc,   CallWndRetProc,   CBTProc,   DebugProc,   ForegroundIdleProc,   GetMsgProc,   JournalPlaybackProc,   JournalRecordProc,   LowLevelKeyboardProc,   LowLevelMouseProc   KeyboardProc,   MouseProc,   MessageProc,   ShellProc,   SysMsgProc,   UnhookWindowsHookEx    
   
  Top

4 楼xyjdn(项有建^_^)回复于 2001-07-30 23:51:45 得分 0

这就不好了!Top

5 楼tg123(T.G.)回复于 2001-07-30 23:56:09 得分 0

不好意思,C语言我说得不好哦Top

6 楼xyjdn(项有建^_^)回复于 2001-07-30 23:59:56 得分 0

对不起,这句"这就不好了!   "是和tg123(T.G.)说的.Top

7 楼tg123(T.G.)回复于 2001-07-31 08:39:21 得分 0

难道118分少吗Top

8 楼lou_df(ldf)回复于 2001-07-31 08:49:10 得分 0

王国荣关于API的书上讲得比较详细,而且给了例子和程序。Top

9 楼tg123(T.G.)回复于 2001-07-31 13:52:12 得分 0

书在那里,书在那里!(我是穷人)Top

10 楼lou_df(ldf)回复于 2001-07-31 16:32:50 得分 0

到书店找一找。书不大,比较厚,带cd盘。Top

11 楼ExitWindows(void)回复于 2001-07-31 17:16:49 得分 0

upTop

12 楼ExitWindows(void)回复于 2001-07-31 23:44:48 得分 0

upTop

13 楼xyjdn(项有建^_^)回复于 2001-08-01 10:37:42 得分 0

北京海淀图书城电子科技书店网上书市Top

14 楼tg123(T.G.)回复于 2001-08-01 12:16:01 得分 0

最好有代码Top

15 楼xyjdn(项有建^_^)回复于 2001-08-01 14:42:21 得分 0

In   Form  
   
  Option   Explicit  
   
  Private   Sub   Form_Load()  
          On   Error   Resume   Next  
   
          SetKeyboardHook   Me.hWnd,   WM_USER  
   
          If   Err.Number   <>   0   Then  
                  MsgBox   "请先将   KeybHook.dll   复制到   Windows   的所在路径!",   vbCritical  
                  End  
          End   If  
          On   Error   GoTo   0  
           
          prevWndProc   =   GetWindowLong(Me.hWnd,   GWL_WNDPROC)  
          SetWindowLong   Me.hWnd,   GWL_WNDPROC,   AddressOf   WndProc  
  End   Sub  
   
  Private   Sub   Form_Unload(Cancel   As   Integer)  
          ReleaseKeyboardHook  
           
          SetWindowLong   Me.hWnd,   GWL_WNDPROC,   prevWndProc  
  End   Sub  
   
  In   Module  
  Option   Explicit  
   
  Public   Const   GWL_WNDPROC   =   (-4)  
  Public   Const   WM_USER   =   &H400  
   
  Declare   Function   CallWindowProc   Lib   "user32"   Alias   "CallWindowProcA"   (ByVal   lpPrevWndFunc   As   Long,   ByVal   hWnd   As   Long,   ByVal   Msg   As   Long,   ByVal   wParam   As   Long,   ByVal   lParam   As   Long)   As   Long  
  Declare   Function   GetWindowLong   Lib   "user32"   Alias   "GetWindowLongA"   (ByVal   hWnd   As   Long,   ByVal   nIndex   As   Long)   As   Long  
  Declare   Function   SetWindowLong   Lib   "user32"   Alias   "SetWindowLongA"   (ByVal   hWnd   As   Long,   ByVal   nIndex   As   Long,   ByVal   dwNewLong   As   Long)   As   Long  
   
  Declare   Function   SetKeyboardHook   Lib   "KeybHook"   (ByVal   hwndPost   As   Long,   ByVal   Msg   As   Long)   As   Long  
  Declare   Function   ReleaseKeyboardHook   Lib   "KeybHook"   ()   As   Long  
   
  Public   prevWndProc   As   Long  
   
  Function   WndProc(ByVal   hWnd   As   Long,   ByVal   Msg   As   Long,   ByVal   wParam   As   Long,   ByVal   lParam   As   Long)   As   Long  
          If   Msg   =   WM_USER   Then  
                  Form1.List1.AddItem   "wParam="   &   wParam   &   ",   lParam="   &   Hex(lParam)  
                  Form1.List1.ListIndex   =   Form1.List1.NewIndex  
          End   If  
          WndProc   =   CallWindowProc(prevWndProc,   hWnd,   Msg,   wParam,   lParam)  
  End   Function  
  Top

16 楼wbdx(碳离子)回复于 2001-08-01 14:50:57 得分 0

注意调试,容易死掉Top

17 楼tg123(T.G.)回复于 2001-08-01 19:14:53 得分 0

xyjdn(项有建^_^)   
  KeybHook.dll在那里????Top

18 楼huangguanshu()回复于 2001-08-01 19:49:15 得分 0

我给你一个类模块吧,可以拦截鼠标和键盘。Top

19 楼tg123(T.G.)回复于 2001-08-01 23:04:38 得分 0

谢了  
  huangguanshu()  
  tg123@sina.comTop

20 楼huangguanshu()回复于 2001-08-01 23:30:15 得分 88

我已经发了。Top

21 楼tg123(T.G.)回复于 2001-08-02 00:40:40 得分 0

http://www.csdn.net/expert/topic/26/26219.shtm  
  签到还可以领30分Top

22 楼tg123(T.G.)回复于 2001-08-02 00:41:16 得分 0

请huangguanshu()   
  http://www.csdn.net/expert/topic/26/26219.shtm  
  签到还可以领30分   Top

相关问题

  • 拦截所有的事件(Mouse,Keyboard)
  • 普通钩子拦截操作
  • 如何通过钩子hook拦截windows中的消息?
  • 怎样用钩子拦截自定义消息
  • 用vb做系统钩子,拦截所有api给分1000
  • 一个关于拦截菜单消息的钩子的问题
  • 大家来讨论API钩子反拦截
  • 求 拦截窗体消息的钩子(hook)(50分)
  • 谁提供几个运用钩子拦截消息的例子
  • API问题:给键盘下完钩子后,如何拦截键盘消息?????????????

关键词

  • .net
  • csdn
  • me
  • byval
  • hook
  • gwl
  • wndproc
  • setwindowlong
  • hwnd
  • shtm

得分解答快速导航

  • 帖主:tg123
  • huangguanshu

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

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