鼠标点击句柄(Mouse clicks handle)

编程入门 行业动态 更新时间:2024-10-19 05:25:16
鼠标点击句柄(Mouse clicks handle)

我正在尝试在屏幕上(客户端窗口之外)处理鼠标事件。 我使用纯Win32 API。 我用SetWindowHookEx函数创建了单独的DLL,并将其引用到我的Win32应用程序。 但它只处理窗口事件,当鼠标在窗口或窗口之外不活动时没有任何反应。

//Hook.h

#ifndef _DEFINED_44E531B1_14D3_11d5_A025_006067718D04 #define _DEFINED_44E531B1_14D3_11d5_A025_006067718D04 #if _MSC_VER > 1000 #pragma once #endif #ifdef __cplusplus extern "C" { #endif // __cplusplus #ifdef _COMPILING_44E531B1_14D3_11d5_A025_006067718D04 #define LIBSPEC __declspec(dllexport) #else #define LIBSPEC __declspec(dllimport) #endif // _COMPILING_44E531B1_14D3_11d5_A025_006067718D04 LIBSPEC BOOL InstallHook(HWND hWnd); LIBSPEC BOOL UnInstallHook(HWND hWnd); #undef LIBSPEC #ifdef __cplusplus } #define UWM_MOUSEMOVE_MSG (L"UWM_MOUSEMOVE_USER_MSG") #define UWM_MOUSELBUTTONUP_MSG ( L"UWM_MOUSELBUTTONUP_USER_MSG" ) #define UWM_MOUSELBUTTONDOWN_MSG ( L"UWM_MOUSELBUTTONDOWN_USER_MSG" ) #define UWM_MOUSERBUTTONUP_MSG ( L"UWM_MOUSERBUTTONUP_USER_MSG" ) #define UWM_MOUSERBUTTONDOWN_MSG ( L"UWM_MOUSERBUTTONDOWN_USER_MSG" ) #define UWM_MOUSELDBCLICK_MSG ( L"UWM_MOUSERBUTTONDOWN_USER_MSG" ) #endif // __cplusplus #endif // _DEFINED_44E531B1_14D3_11d5_A025_006067718D04

//Hook.cpp

// Hook.cpp:定义DLL应用程序的导出函数。 //

#include "stdafx.h" #include "Hook.h" #pragma data_seg() #pragma comment(linker, "/section:.Segment,rws") HWND hWndServer = NULL; UINT UWM_MOUSEMOVE; UINT UWM_MOUSELBUTTONUP; UINT UWM_MOUSELBUTTONDOWN; UINT UWM_MOUSERBUTTONUP; UINT UWM_MOUSERBUTTONDOWN; UINT UWM_MOUSELDBCLICK; HINSTANCE hInst; //HWND hWndServer = NULL; HHOOK hook; static LRESULT CALLBACK MouseMsgProc(UINT nCode, WPARAM wParam, LPARAM lParam) { if(nCode < 0) { CallNextHookEx(hook, nCode, wParam, lParam); return 0; } LPMSG msg = (LPMSG)lParam; switch( msg->message ) { case WM_LBUTTONDBLCLK: SendMessage( hWndServer, UWM_MOUSELDBCLICK, 0 , 0); break; case WM_MOUSEMOVE: SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0); break; case WM_NCMOUSEMOVE: SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0); break; case WM_LBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSELBUTTONDOWN, 0 , 0 ); break; case WM_NCLBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSELBUTTONDOWN, 0 , 0); break; case WM_LBUTTONUP: SendMessage( hWndServer, UWM_MOUSELBUTTONUP, 0 , 0 ); break; case WM_NCLBUTTONUP: SendMessage( hWndServer, UWM_MOUSELBUTTONUP, 0 , 0); break; case WM_RBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSERBUTTONDOWN, 0 , 0 ); break; case WM_NCRBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSERBUTTONDOWN, 0 , 0); break; case WM_RBUTTONUP: SendMessage( hWndServer, UWM_MOUSERBUTTONUP, 0 , 0 ); break; case WM_NCRBUTTONUP: SendMessage( hWndServer, UWM_MOUSERBUTTONUP, 0 , 0); break; default: break; } return CallNextHookEx(hook, nCode, wParam, lParam); } __declspec(dllexport) BOOL InstallHook( HWND hWndParent) { if(hWndServer != NULL) return FALSE; // already hooked! hook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)MouseMsgProc, hInst, 0); if(hook != NULL) { hWndServer = hWndParent; return TRUE; } return FALSE; } __declspec(dllexport) BOOL UnInstallHook( HWND hWndParent ) { if(hWndParent != hWndServer || hWndParent == NULL) return FALSE; BOOL unhooked = UnhookWindowsHookEx(hook); if(unhooked) hWndServer = NULL; return unhooked; return TRUE; } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: hInst = hModule; UWM_MOUSEMOVE = ::RegisterWindowMessage(UWM_MOUSEMOVE_MSG); UWM_MOUSELBUTTONUP = ::RegisterWindowMessage(UWM_MOUSELBUTTONUP_MSG); UWM_MOUSELBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSELBUTTONDOWN_MSG); UWM_MOUSERBUTTONUP = ::RegisterWindowMessage(UWM_MOUSERBUTTONUP_MSG); UWM_MOUSERBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSERBUTTONDOWN_MSG); UWM_MOUSELDBCLICK = ::RegisterWindowMessage(UWM_MOUSELDBCLICK_MSG); case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }

// Win32应用程序main.cpp

#include "stdafx.h" #include "stdafx.h" #include <sstream> #include "strsafe.h" #include "../Hook/Hook.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); //Mouse Events static UINT UWM_MOUSEDBCLICK = ::RegisterWindowMessage( UWM_MOUSELDBCLICK_MSG ); static UINT UWM_MOUSELBUTTONUP = ::RegisterWindowMessage(UWM_MOUSELBUTTONUP_MSG);; static UINT UWM_MOUSELBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSELBUTTONDOWN_MSG); static UINT UWM_MOUSERBUTTONUP = ::RegisterWindowMessage(UWM_MOUSERBUTTONUP_MSG); static UINT UWM_MOUSERBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSERBUTTONDOWN_MSG); static UINT UWM_MOUSEMOVE = ::RegisterWindowMessage(UWM_MOUSEMOVE_MSG); // int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_ACTIONX, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ACTIONX)); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ACTIONX)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_ACTIONX); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); BOOL result=InstallHook(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; //Global Mouse Move Handle if(message==UWM_MOUSEMOVE){ MessageBox( NULL, (LPCWSTR)L"Resource not available\nDo you want to try again?", (LPCWSTR)L"Account Details", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2 ); return 0; } switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_PLAY: PlayMouse(); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }

I'm trying to handle mouse events on my screen(outside of client window). I use pure Win32 API. I have created separate DLL with SetWindowHookEx function and reference this to my Win32 Application. But its handle only window event, and when mouse is outside of window or window is not active nothing happens.

//Hook.h

#ifndef _DEFINED_44E531B1_14D3_11d5_A025_006067718D04 #define _DEFINED_44E531B1_14D3_11d5_A025_006067718D04 #if _MSC_VER > 1000 #pragma once #endif #ifdef __cplusplus extern "C" { #endif // __cplusplus #ifdef _COMPILING_44E531B1_14D3_11d5_A025_006067718D04 #define LIBSPEC __declspec(dllexport) #else #define LIBSPEC __declspec(dllimport) #endif // _COMPILING_44E531B1_14D3_11d5_A025_006067718D04 LIBSPEC BOOL InstallHook(HWND hWnd); LIBSPEC BOOL UnInstallHook(HWND hWnd); #undef LIBSPEC #ifdef __cplusplus } #define UWM_MOUSEMOVE_MSG (L"UWM_MOUSEMOVE_USER_MSG") #define UWM_MOUSELBUTTONUP_MSG ( L"UWM_MOUSELBUTTONUP_USER_MSG" ) #define UWM_MOUSELBUTTONDOWN_MSG ( L"UWM_MOUSELBUTTONDOWN_USER_MSG" ) #define UWM_MOUSERBUTTONUP_MSG ( L"UWM_MOUSERBUTTONUP_USER_MSG" ) #define UWM_MOUSERBUTTONDOWN_MSG ( L"UWM_MOUSERBUTTONDOWN_USER_MSG" ) #define UWM_MOUSELDBCLICK_MSG ( L"UWM_MOUSERBUTTONDOWN_USER_MSG" ) #endif // __cplusplus #endif // _DEFINED_44E531B1_14D3_11d5_A025_006067718D04

//Hook.cpp

// Hook.cpp : Defines the exported functions for the DLL application. //

#include "stdafx.h" #include "Hook.h" #pragma data_seg() #pragma comment(linker, "/section:.Segment,rws") HWND hWndServer = NULL; UINT UWM_MOUSEMOVE; UINT UWM_MOUSELBUTTONUP; UINT UWM_MOUSELBUTTONDOWN; UINT UWM_MOUSERBUTTONUP; UINT UWM_MOUSERBUTTONDOWN; UINT UWM_MOUSELDBCLICK; HINSTANCE hInst; //HWND hWndServer = NULL; HHOOK hook; static LRESULT CALLBACK MouseMsgProc(UINT nCode, WPARAM wParam, LPARAM lParam) { if(nCode < 0) { CallNextHookEx(hook, nCode, wParam, lParam); return 0; } LPMSG msg = (LPMSG)lParam; switch( msg->message ) { case WM_LBUTTONDBLCLK: SendMessage( hWndServer, UWM_MOUSELDBCLICK, 0 , 0); break; case WM_MOUSEMOVE: SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0); break; case WM_NCMOUSEMOVE: SendMessage( hWndServer, UWM_MOUSEMOVE, 0, 0); break; case WM_LBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSELBUTTONDOWN, 0 , 0 ); break; case WM_NCLBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSELBUTTONDOWN, 0 , 0); break; case WM_LBUTTONUP: SendMessage( hWndServer, UWM_MOUSELBUTTONUP, 0 , 0 ); break; case WM_NCLBUTTONUP: SendMessage( hWndServer, UWM_MOUSELBUTTONUP, 0 , 0); break; case WM_RBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSERBUTTONDOWN, 0 , 0 ); break; case WM_NCRBUTTONDOWN: SendMessage( hWndServer, UWM_MOUSERBUTTONDOWN, 0 , 0); break; case WM_RBUTTONUP: SendMessage( hWndServer, UWM_MOUSERBUTTONUP, 0 , 0 ); break; case WM_NCRBUTTONUP: SendMessage( hWndServer, UWM_MOUSERBUTTONUP, 0 , 0); break; default: break; } return CallNextHookEx(hook, nCode, wParam, lParam); } __declspec(dllexport) BOOL InstallHook( HWND hWndParent) { if(hWndServer != NULL) return FALSE; // already hooked! hook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)MouseMsgProc, hInst, 0); if(hook != NULL) { hWndServer = hWndParent; return TRUE; } return FALSE; } __declspec(dllexport) BOOL UnInstallHook( HWND hWndParent ) { if(hWndParent != hWndServer || hWndParent == NULL) return FALSE; BOOL unhooked = UnhookWindowsHookEx(hook); if(unhooked) hWndServer = NULL; return unhooked; return TRUE; } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: hInst = hModule; UWM_MOUSEMOVE = ::RegisterWindowMessage(UWM_MOUSEMOVE_MSG); UWM_MOUSELBUTTONUP = ::RegisterWindowMessage(UWM_MOUSELBUTTONUP_MSG); UWM_MOUSELBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSELBUTTONDOWN_MSG); UWM_MOUSERBUTTONUP = ::RegisterWindowMessage(UWM_MOUSERBUTTONUP_MSG); UWM_MOUSERBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSERBUTTONDOWN_MSG); UWM_MOUSELDBCLICK = ::RegisterWindowMessage(UWM_MOUSELDBCLICK_MSG); case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }

//Win32 Application main.cpp

#include "stdafx.h" #include "stdafx.h" #include <sstream> #include "strsafe.h" #include "../Hook/Hook.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); //Mouse Events static UINT UWM_MOUSEDBCLICK = ::RegisterWindowMessage( UWM_MOUSELDBCLICK_MSG ); static UINT UWM_MOUSELBUTTONUP = ::RegisterWindowMessage(UWM_MOUSELBUTTONUP_MSG);; static UINT UWM_MOUSELBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSELBUTTONDOWN_MSG); static UINT UWM_MOUSERBUTTONUP = ::RegisterWindowMessage(UWM_MOUSERBUTTONUP_MSG); static UINT UWM_MOUSERBUTTONDOWN = ::RegisterWindowMessage(UWM_MOUSERBUTTONDOWN_MSG); static UINT UWM_MOUSEMOVE = ::RegisterWindowMessage(UWM_MOUSEMOVE_MSG); // int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_ACTIONX, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ACTIONX)); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ACTIONX)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_ACTIONX); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); BOOL result=InstallHook(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; //Global Mouse Move Handle if(message==UWM_MOUSEMOVE){ MessageBox( NULL, (LPCWSTR)L"Resource not available\nDo you want to try again?", (LPCWSTR)L"Account Details", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2 ); return 0; } switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_PLAY: PlayMouse(); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }

最满意答案

使用WH_MOUSE挂钩仅挂钩鼠标消息。

几点建议:

确保挂钩安装成功(SetWindowsHookEx返回非NULL值) 确保传递给挂钩过程的消息(将断点设置为这些点或使用跟踪功能) 您需要将目标窗口的HWND发送到每个进程或发送广播消息 对于Windows Vista及更高版本,具有较低权限的进程无法使用更高权限发送消息。 您需要使用ChangeWindowMessageFilter将必要的消息添加到过滤器 使用PostMesssage而不是SendMessage,无论如何都不需要阻止调用

Use WH_MOUSE hook to hook mouse messages only.

Few suggestions:

Ensure you hook installed successfully (SetWindowsHookEx returned non-NULL value) Ensure messages delivered to hook procedure (Set breakpoint to these points or use trace functions) You either need to send HWND of target window to the each process or send broadcast message For Windows Vista and later processes with lower privileges cannot send messages to process with higher privileges. You need to use ChangeWindowMessageFilter to add necessary messages to the filter Use PostMesssage instead of SendMessage, you don't need blocking calls here anyway

更多推荐

本文发布于:2023-07-23 18:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:句柄   鼠标点击   Mouse   clicks   handle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!