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. 

解决方案 »

  1.   

                     如何获得密码窗口的内容------揭开Hook的面纱                                           Pan Ying(zero world)  现在的不少程序都有取得密码窗口的内容的功能,你有没有想过是如何做到这一切的呢?我有一个同学就问过我这样一个问题,当时我也回答不出来,现在我研究了视窗的Hook函数之后总算有了一定的了解。下面就有我来揭开Hook函数的神秘面纱。   先来介绍Hook的含义: 
      Hook是指在程序正常运行中接受信息之前预先启动的函数,用来检查和修改传给该程序的信息。举例来说,当你在一个窗口上点击鼠标以后,首先接收信息的是相应的Hook函数,然后才传到相应的应用程序。   如何定义Hook函数: 
    SetWindowsHookEx: 
      用来装入新的Hook函数,其参数列表为下: 
    int idHook:装入Hook类型,有WH_MOUSE 等。 
    HOOKPROC lpfn:要装入的Hook函数地址。 
    HINSTANCE hMod:函数所在的进程,如果为全局Hook函数该函数必须在Dll中。 
    DWORD dwThreadId:装入哪个进程,如果为全局,则为0。 
      返回相应Hook标识。 
    HookProc: 
      您自定义的Hook函数,应具有的参数如下: 
    int nCode:传入的信息类型。 
    WPARAM wParam:短整型参数。 
    LPARAM lParam:长整型参数。 
      要在函数中调用CallNextHookEx把信息传给下一个Hook函数。 CallNextHookEx: 
      用于将信息传给下一个Hook函数,需要将得到的Hook标识和相应参数传入。 UnhookWindowsHookEx: 
      用于将装入的Hook函数从Hook链表中剔除,应传入得到的Hook标识。 
    下面我们来看一个例子: 
      例子原码的下载:HookTest.zip 本程序在Window98和Delphi5下通过。 
    一、调用LoadLibrary和GetProcAddress取得函数地址。 
      hinstDLL := LoadLibrary(LPCTSTR( 'hooktest.dll')); 
      @hkprcSysMsg:=GetProcAddress(hinstDLL, 'MouseProc'); 二、用SetWindowsHookEx将得到的函数装入。 
      hhk:= SetWindowsHookEx(WH_MOUSE,@hkprcSysMsg,hinstDLL, 0); 三、Windows会将函数装入到每一个进程中。 四、每当鼠标点击,自定义的Hook函数会将点击的窗口标题传给程序的标题。 
    if (nCode=HC_ACTION)and(WPARAM=WM_LBUTTONDOWN) 
     then 
      begin 
       MyMouse:=CPointer(lPARAM); 
       MyHandle2:=MyMouse^.hwnd; 
       GetMem(MyString,GetWindowTextlength(myhandle2)+1); 
       GetWindowText(MyHandle2,MyString,GetWindowTextlength(myhandle2)+1); 
       TempHandle:=myhandle2; 
       while (TempHandle<>0) do 
       begin 
        myHandle2:=TempHandle; 
        TempHandle:=GetParent(TempHandle); 
       end; 
       if (myhandle2<>0) 
       then 
        SetWindowText(myhandle2,MyString); 
       FreeMem(MyString); 
      end 
    就这样完成了得到密码窗口内容的功能。