home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 April / VPR0204A.ISO / OLS_XP / WHEELLAYERED / WheelLayered.lzh / WheelLayeredSrc.lzh / WheelLayered / WheelLayeredDll.c < prev    next >
C/C++ Source or Header  |  2001-10-16  |  2KB  |  70 lines

  1. //--------------------------------------------------------
  2. #include    <windows.h>
  3. #include    <windowsx.h>
  4. #include    <zmouse.h>
  5. #include    "WheelLayered.h"
  6.  
  7. #define        PUSHED                    0x8000
  8.  
  9. #pragma data_seg(".sdata")
  10. HINSTANCE    DLLInst = NULL;
  11. HHOOK         hHook = NULL;
  12. HWND        hPostWnd = NULL;
  13. #pragma data_seg()
  14.  
  15. LRESULT CALLBACK GetMsgProc(int, WPARAM, LPARAM);
  16. BOOL SetHook(HWND);
  17. VOID FreeHook(VOID);
  18.  
  19. //--------------------------------------------------------
  20. BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
  21. {
  22.     DLLInst = hInstance;
  23.     return TRUE;
  24. }
  25.  
  26. //--------------------------------------------------------
  27. BOOL SetHook(HWND hWnd)
  28. {
  29.     hHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, DLLInst, 0);
  30.     if(hHook == NULL){
  31.         MessageBox(NULL, "Hook Error!", APP_NAME, MB_OK);
  32.         return FALSE;
  33.     }
  34.     hPostWnd = hWnd;            // メインのhWnd保存
  35.     return TRUE;
  36. }
  37.  
  38. //--------------------------------------------------------
  39. VOID FreeHook(VOID)
  40. {
  41.     if(hHook != NULL){
  42.         UnhookWindowsHookEx(hHook);        // Hook解除
  43.         hHook = NULL;
  44.     }
  45. }
  46.  
  47. //--------------------------------------------------------
  48. LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
  49. {
  50.     SHORT sState;
  51.     PMSG pMsg;
  52.  
  53.     if(nCode == HC_ACTION){
  54.         pMsg = (PMSG)lParam;
  55.         switch(pMsg->message){
  56.         case WM_MOUSEWHEEL:                                // Wheel
  57.             sState = GetKeyState(VK_RBUTTON);
  58.             if(sState & PUSHED){                        // 右押し
  59.                 if((short)HIWORD(pMsg->wParam) < 0)        // 回転方向
  60.                     PostMessage(hPostWnd, WM_USER, (WPARAM)FALSE, 0);
  61.                 else
  62.                     PostMessage(hPostWnd, WM_USER, (WPARAM)TRUE, 0);
  63.             }
  64.             break;
  65.         }
  66.     }
  67.     return(CallNextHookEx(hHook, nCode, wParam, lParam));
  68. }
  69.  
  70.