home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2004 September / maximum-cd-2004-09.iso / Software / Extras / nbeep03.exe / Source / hookdll.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-02  |  1.4 KB  |  64 lines

  1. #include <windows.h>
  2. #include <process.h>
  3.  
  4. BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
  5. {
  6.     return TRUE;
  7. }
  8.  
  9.  
  10. #pragma data_seg("ShrdSeg")
  11. HHOOK hHook=NULL;
  12. int state=0;
  13. HWND hwndParent=NULL;
  14. #pragma data_seg()
  15.  
  16. __declspec( dllexport ) int get()
  17. {
  18.   int n=state;
  19.   state=0;
  20.   return n;
  21. }
  22.  
  23. __declspec( dllexport ) void quit()
  24. {
  25.     if (hHook) UnhookWindowsHookEx(hHook);
  26.     hHook=0;
  27. }
  28.  
  29. __declspec( dllexport ) void init(HWND hwnd, HINSTANCE hinst)
  30. {
  31.   hwndParent=hwnd;
  32.     hHook = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC) 
  33.     GetProcAddress(hinst,"_Hook1Proc@12"),
  34.     hinst,0);
  35. }
  36.  
  37. __declspec( dllexport ) LRESULT CALLBACK Hook1Proc(int nCode,WPARAM wParam,LPARAM lParam)    
  38. {
  39.   MSG *msg=(MSG *)lParam;
  40.   if (
  41.     msg->message == WM_COMMAND ||
  42.     msg->message == WM_ACTIVATE ||
  43.     msg->message == WM_NCACTIVATE ||
  44.     msg->message == WM_SETFOCUS ||
  45.     msg->message == WM_ERASEBKGND ||
  46.     msg->message == WM_PAINT ||
  47.     msg->message == WM_LBUTTONDOWN ||
  48.     (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN) ||
  49.     0) 
  50.   {
  51.     int up=1;
  52.     if (msg->message == WM_PAINT)
  53.     {
  54.       RECT r;
  55.       GetUpdateRect(msg->hwnd,&r,FALSE);
  56.       if ((r.right-r.left)*(r.bottom-r.top) < 4000)
  57.         up=0;
  58.     }
  59.     if (up && msg->hwnd != hwndParent && GetParent(msg->hwnd) != hwndParent) state++;      
  60.   }
  61.   return CallNextHookEx(hHook,nCode,wParam,lParam);    
  62. }
  63.  
  64.