A little improvement on VC writing mouse global hook [Source code]

xiaoxiao2021-03-06  59

My VB programmer's VC coding experience / ************************************************ **************************** / / * file name: mymousehook.cpp * // * * // * Function: Standard DLL - --- right mouse global hook to achieve double-click paste function * // // * * * author: Rae (booolee) time: 2004.9.18 * // * * // * BLOG: http: //blog.9cbs. Net / boolee * // ********************************************************************** *********************** /

// Export function list // StartHook // stophook // About

#define _win32_winnt 0x0500 // Set the system version, make sure you can use the underlying mouse hook

#include "windows.h" #include

// Global variable hinstance g_hinstance = null; // module instance handle hHOOK G_HHHOOK = NULL; // hook handle

// the DLL entry function BOOL APIENTRY DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {// save module instance handle g_hInstance = (HINSTANCE) hModule; unloading hook switch (ul_reason_for_call) // when the process ends or thread ends {case DLL_PROCESS_ATTACH : Break; Case DLL_THREAD_ATTACH: BREAK; CASE DLL_PROCESS_DETACH: CASE DLL_THREAD_DETACH: IF (g_hhook! = Null) UnHookWindowsHookex (g_hhook); Break;} returnography;

// bottom mouse hook function LRESULT CALLBACK MouseHookProc (int nCode, WPARAM wParam, LPARAM lParam) {LPMOUSEHOOKSTRUCT pMouseHook = (MOUSEHOOKSTRUCT FAR *) lParam; if (nCode> = 0) {// double right mouse paste if (wParam = = WM_RBUTTONDBLCLK) {HWND GLHTARGETWND = PMousehook-> hWnd; if (GLHTARGETWND! = NULL) {SendMessage (GlhtargetWnd, WM_PASTE, 0, 0); Return True;}} // Click the mouse button for data copy IF (WPARAM = = WM_MBUTTONUP) {HWND glhTargetWnd = pMouseHook-> hwnd; LPTSTR tmpstr = NULL; char buf [100]; SendMessage (glhTargetWnd, WM_GETTEXT, sizeof (buf) / sizeof (char), (LPARAM) (void *) buf); int DWLENGTH = 100; // To copy the string length Handle HglobalMemory = GlobalAlloc (GHND, DWLENGTH 1); // Assign Memory LPBYTE LPGLOBALMORY = (lpbyte) Globalock (HglobalMemory); // Lock memory for (int i = 0; I

/ ************************************************** ****************** / / * Install the mouse hook * // * parameter: (none) * // * Return value: true success, FALSE failed * // * *********************************************************** ***************** / BOOL WINAPI STARTHOK () {// Returns false if (g_hhook! = Null) Return False; // Install the underlying mouse hook g_hook = setwindowshookex (wh_mouse, mousehookproc, g_hinstance, null); if (g_hhook == null) Return False; MessageBox (null, "start successfully! / n / n replication function: Click Mouse button (wheel) to copy data to scrapbook Board / n paste function: Double-click the right mouse button to automatically remove rice and flat meter units when paste data / n replication, "BOBO mouse attachment 1.1", MB_OK); return true;} / ******** *********************************************************** ********** // * Uninstall the mouse hook * /// * // * parameter: (none) * // * * // * Return value: true success, False failed * // ** *********************************************************** **************** / BOOL WINAPI StopHook () {// Uninstall Hook IF (UnHookWindowsHooKex (g_hhook == 0) Return False; g_hook = null; MessageBox (null, "Uninstall Success! "," BOBO mouse attachment ", MB_OK; Return True;}

BOOL WINAPI About () {MessageBox (NULL, "Author: Rae / n function: fast clipboard operations / n date by mouse: 2004.9.25 / n Mail: booolee@yahoo.com.cn", "About BOBO mouse Pastelers 1.1 ", MB_OK); Return True;}

转载请注明原文地址:https://www.9cbs.com/read-113058.html

New Post(0)