Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #define delta360 960 //total delta around the wheel
- #define len360 7.0 //cm
- #define deltaToCm len360/delta360
- const char g_szClassName[] = "myWindowClass";
- HHOOK hook;
- bool running = false;
- float total = 0.0;
- int totalcm, leftover, meter;
- // Step 4: the Window Procedure
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_QUIT:
- case WM_CLOSE: {
- running = false;
- }break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- // Step 4: the Window Procedure
- LRESULT CALLBACK hookProc(int code, WPARAM wParam, LPARAM lParam) {
- switch(wParam) {
- case WM_MOUSEWHEEL: {
- int meter = 0;
- int decimeter = 0;
- short delta = GET_WHEEL_DELTA_WPARAM( lParam );
- int ticks = delta;
- if (ticks < 0 ) ticks = -ticks;
- total+=ticks;
- leftover = (int)(deltaToCm*total);
- if (leftover >= 100){
- meter = leftover/100;
- leftover -= (leftover/100)*100;
- }
- if (leftover >= 10){
- decimeter = leftover/10;
- leftover -= (leftover/10)*10;
- }
- printf("%d meter, %d decimeter, %d centimeter scrolled\n", meter, decimeter, leftover);
- break;
- }
- }
- return CallNextHookEx(hook, code, wParam, lParam);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- //Step 1: Registering the Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- "test",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
- NULL, NULL, hInstance, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- // -----------------------------------------------
- // (3): Hooka din app att lyssna på mouse events globalt
- // -----------------------------------------------
- hook = SetWindowsHookEx(WH_MOUSE_LL, hookProc, GetModuleHandle(0), 0);
- running = true;
- while(running){
- while(PeekMessage(&Msg, hwnd, 0, 0, PM_REMOVE)){
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- Sleep(10);
- }
- UnhookWindowsHookEx(hook);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement