home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / message / callmsgh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.3 KB  |  54 lines

  1. #include <windows.h>
  2. #include "callmsgh.h"
  3.  
  4. HANDLE   hTASK;
  5. FARPROC  lpfnMessageFilterHook;
  6. FARPROC  lpfnOldMessageFilterHook;
  7. HWND     hWnd;
  8.  
  9. /****************************************************************************/
  10. void FAR PASCAL InitHook (hTask)
  11. HANDLE hTask;
  12.   {
  13.   hTASK = hTask;
  14.   lpfnMessageFilterHook = MakeProcInstance ( (FARPROC)CallMsgMessageFilter,
  15.       LIBINST);
  16.   lpfnOldMessageFilterHook = SetWindowsHook (WH_MSGFILTER,
  17.       lpfnMessageFilterHook);
  18.   }
  19.  
  20.  
  21. /****************************************************************************/
  22.  
  23. BOOL FAR PASCAL KillHook ()
  24.   {
  25.   BOOL  fSuccess;
  26.  
  27.   fSuccess = UnhookWindowsHook (WH_MSGFILTER, lpfnMessageFilterHook);
  28.   if (fSuccess)
  29.     {
  30.     FreeProcInstance (lpfnMessageFilterHook);
  31.     MessageBox (GetFocus (), "Message filter Unhooked.",
  32.         "Hook", MB_OK);
  33.     }
  34.   return fSuccess;
  35.   }
  36.  
  37.  
  38. /****************************************************************************/
  39.  
  40. DWORD FAR PASCAL CallMsgMessageFilter (nCode, wParam, lParam)
  41. int    nCode;
  42. WORD  wParam;
  43. LONG  lParam;
  44.   {
  45.   if (nCode == HC_ACTION)
  46.     {
  47.     hWnd = FindWindow (NULL, "CallMsgFilter");
  48.     PostMessage (hWnd, WM_COMMAND, IDM_FROMMSGFILTER, 0L);
  49.     return TRUE;
  50.     }
  51.   else
  52.     return DefHookProc (nCode, wParam, lParam, &lpfnOldMessageFilterHook);
  53.   }
  54.