鼠标单击变双击补丁(含C++代码)

鼠标单击变双击了怎么办?难道只能换鼠标吗?下面这个程序可以在一定程度上解决这个问题。程序和代码可以在这里下载。


原理一看便知,代码如下:

/*
 *  @file  : MouseClickHotfix.cpp
 *  @author: shilyx
 *  @date  : 2014-04-13 19:33:42.540
 *  @note  : Generated by SlxTemplates
 */

#include <Windows.h>
#pragma warning(disable: 4786)
#include <tchar.h>
#include "resource.h"

#define CLASS_NAME TEXT("__MouseClickHotfix")

LRESULT CALLBACK LowLevelMouseProc(
    int nCode,
    WPARAM wParam,
    LPARAM lParam
    )
{
    if (nCode == HC_ACTION)
    {
        if (WM_LBUTTONDOWN == wParam && 0 != lParam)
        {
            static POINT s_lastPt = {-1, -1};
            static DWORD s_lastTickCount = 0;

            LPMSLLHOOKSTRUCT lpHookStruct = (LPMSLLHOOKSTRUCT)lParam;

            if (lpHookStruct->pt.x == s_lastPt.x &&
                lpHookStruct->pt.y == s_lastPt.y
                )
            {
                if (GetTickCount() - s_lastTickCount < 155)
                {
                    return 1;
                }
            }

            s_lastPt = lpHookStruct->pt;
            s_lastTickCount = GetTickCount();
        }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_CREATE:
        return 0;

    case WM_CLOSE:
        DestroyWindow(hWnd);
        return 0;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;

    default:
        break;
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

void Run(HINSTANCE hInstance)
{
    WNDCLASSEX wcex = {sizeof(wcex)};

    wcex.lpszClassName  = CLASS_NAME;
    wcex.hInstance      = hInstance;
    wcex.lpfnWndProc    = WndProc;
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINFRAME));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);

    if (RegisterClassEx(&wcex))
    {
        HWND hWindow = CreateWindowEx(
            0,
            CLASS_NAME,
            CLASS_NAME,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
            );

        if (IsWindow(hWindow))
        {
//             ShowWindow(hWindow, SW_SHOW);
//             UpdateWindow(hWindow);

            HHOOK hHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, hInstance, 0);

            MSG msg;

            while (TRUE)
            {
                int nRet = GetMessage(&msg, NULL, 0, 0);

                if (nRet <= 0)
                {
                    break;
                }

                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }

            UnhookWindowsHookEx(hHook);
        }
    }
}

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
    if (IsWindow(FindWindow(CLASS_NAME, CLASS_NAME)))
    {
        MessageBox(NULL, TEXT("已经在运行!"), NULL, MB_SYSTEMMODAL | MB_ICONEXCLAMATION);
        return 0;
    }

    Run(hInstance);

    return 0;
}

#if !defined(_DEBUG) && _MSC_VER < 1300

#pragma comment(linker, "/Entry:s")
#pragma comment(linker, "/Opt:NoWin98")

void s()
{
    ExitProcess(_tWinMain(GetModuleHandle(NULL), NULL, NULL, 0));
}

#endif


鼠标单击变双击补丁(含C++代码),布布扣,bubuko.com

鼠标单击变双击补丁(含C++代码)

上一篇:VC++ / python 如何获取工程当前路径及对应的其相关路径


下一篇:java中数组的定义及使用