Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6.  
  7. #define delta360 960 //total delta around the wheel
  8. #define len360 7.0 //cm
  9. #define deltaToCm len360/delta360
  10.  
  11. const char g_szClassName[] = "myWindowClass";
  12. HHOOK hook;
  13. bool running = false;
  14. float total = 0.0;
  15. int totalcm, leftover, meter;
  16.  
  17. // Step 4: the Window Procedure
  18. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  19. {
  20. switch(msg)
  21. {
  22. case WM_QUIT:
  23. case WM_CLOSE: {
  24. running = false;
  25. }break;
  26.  
  27. default:
  28. return DefWindowProc(hwnd, msg, wParam, lParam);
  29. }
  30. return 0;
  31. }
  32.  
  33.  
  34. // Step 4: the Window Procedure
  35. LRESULT CALLBACK hookProc(int code, WPARAM wParam, LPARAM lParam) {
  36. switch(wParam) {
  37. case WM_MOUSEWHEEL: {
  38.  
  39. int meter = 0;
  40. int decimeter = 0;
  41. short delta = GET_WHEEL_DELTA_WPARAM( lParam );
  42. int ticks = delta;
  43. if (ticks < 0 ) ticks = -ticks;
  44. total+=ticks;
  45. leftover = (int)(deltaToCm*total);
  46.  
  47. if (leftover >= 100){
  48. meter = leftover/100;
  49. leftover -= (leftover/100)*100;
  50.  
  51. }
  52. if (leftover >= 10){
  53. decimeter = leftover/10;
  54. leftover -= (leftover/10)*10;
  55. }
  56.  
  57. printf("%d meter, %d decimeter, %d centimeter scrolled\n", meter, decimeter, leftover);
  58. break;
  59. }
  60. }
  61. return CallNextHookEx(hook, code, wParam, lParam);
  62. }
  63.  
  64. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  65. LPSTR lpCmdLine, int nCmdShow)
  66. {
  67. WNDCLASSEX wc;
  68. HWND hwnd;
  69. MSG Msg;
  70. //Step 1: Registering the Window Class
  71. wc.cbSize = sizeof(WNDCLASSEX);
  72. wc.style = 0;
  73. wc.lpfnWndProc = WndProc;
  74. wc.cbClsExtra = 0;
  75. wc.cbWndExtra = 0;
  76. wc.hInstance = hInstance;
  77. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  78. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  79. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  80. wc.lpszMenuName = NULL;
  81. wc.lpszClassName = g_szClassName;
  82. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  83.  
  84. if(!RegisterClassEx(&wc))
  85. {
  86. MessageBox(NULL, "Window Registration Failed!", "Error!",
  87. MB_ICONEXCLAMATION | MB_OK);
  88. return 0;
  89. }
  90. // Step 2: Creating the Window
  91. hwnd = CreateWindowEx(
  92. WS_EX_CLIENTEDGE,
  93. g_szClassName,
  94. "test",
  95. WS_OVERLAPPEDWINDOW,
  96. CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
  97. NULL, NULL, hInstance, NULL);
  98.  
  99. if(hwnd == NULL)
  100. {
  101. MessageBox(NULL, "Window Creation Failed!", "Error!",
  102. MB_ICONEXCLAMATION | MB_OK);
  103. return 0;
  104. }
  105.  
  106. ShowWindow(hwnd, nCmdShow);
  107. // -----------------------------------------------
  108. // (3): Hooka din app att lyssna på mouse events globalt
  109. // -----------------------------------------------
  110. hook = SetWindowsHookEx(WH_MOUSE_LL, hookProc, GetModuleHandle(0), 0);
  111. running = true;
  112. while(running){
  113. while(PeekMessage(&Msg, hwnd, 0, 0, PM_REMOVE)){
  114. TranslateMessage(&Msg);
  115. DispatchMessage(&Msg);
  116. }
  117. Sleep(10);
  118. }
  119. UnhookWindowsHookEx(hook);
  120.  
  121. return 0;
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement