| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1470 人关注过本帖
标题:控制鼠标反方向移动如果编译成可执行文件?
只看楼主 加入收藏
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:9 
控制鼠标反方向移动如果编译成可执行文件?
网上看到有控制鼠标反方向移动这个VC的代码,想编译成可执行文件,请哪位给编译一下?谢谢!

#define _WIN32_WINNT 0x400
#include <windows.h>
#pragma data_seg("Shared")
HHOOK NextHook = NULL;
SIZE Screen = {0, 0};
POINT pt = {0, 0};
#pragma data_seg()
HMODULE Module;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
Module = hModule;
return TRUE;
}
LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == 0)
{
PMSLLHOOKSTRUCT mhs = (PMSLLHOOKSTRUCT)lParam;

if (mhs->pt.x != pt.x || mhs->pt.y != pt.y)
{
pt.x = pt.x - (mhs->pt.x - pt.x);
pt.y = pt.y - (mhs->pt.y - pt.y);

if (pt.x < 0) pt.x = 0;
if (pt.y < 0) pt.y = 0;
if (pt.x >= Screen.cx) pt.x = Screen.cx - 1;
if (pt.y >= Screen.cy) pt.y = Screen.cy - 1;
SetCursorPos(pt.x, pt.y);
return TRUE;
}
}
return CallNextHookEx(NextHook, nCode, wParam, lParam);
}
__declspec(dllexport) void StartHook()
{
Screen.cx = GetSystemMetrics(SM_CXSCREEN);
Screen.cy = GetSystemMetrics(SM_CYSCREEN);
GetCursorPos(&pt);
NextHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, Module, 0);
}
__declspec(dllexport) void StopHook()
{
UnhookWindowsHookEx(NextHook);
}

 

 

急用这个,但不懂,哪位高手,帮助一下,编译成可执行文件吧,非常感谢!
搜索更多相关主题的帖子: 编译 文件 鼠标 
2009-12-28 22:27
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
收藏
得分:0 
不可行吗?
2009-12-29 22:53
yxwsbobo
Rank: 5Rank: 5
等 级:职业侠客
帖 子:345
专家分:306
注 册:2007-10-29
收藏
得分:0 
他这个只能编译成DLL 然后调用



用我的就可以了
程序代码:
#include "windows.h"

DWORD g_main_tid = 0;
HHOOK g_kb_hook = 0;

LRESULT CALLBACK ms_proc (int code, WPARAM w, LPARAM l)
{
    if(code < 0|| (int)w != 512)
        return CallNextHookEx (g_kb_hook, code, w, l);
    PMSLLHOOKSTRUCT p = (PMSLLHOOKSTRUCT)l;
    POINT CurrentPT;
    GetCursorPos(&CurrentPT);
    p->pt.x = CurrentPT.x -(p->pt.x-CurrentPT.x);
    p->pt.y = CurrentPT.y -(p->pt.y-CurrentPT.y);
    SetCursorPos(p->pt.x, p->pt.y);
    return 1;
}


int main (void)
{
    g_main_tid = GetCurrentThreadId ();
    //SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&con_handler, TRUE);
    g_kb_hook = SetWindowsHookEx (
            WH_MOUSE_LL,
            (HOOKPROC)&ms_proc,
            GetModuleHandle (NULL),
            0);
    if (g_kb_hook == NULL)
    {
        fprintf (stderr,
        "SetWindowsHookEx failed with error %d\n",
        ::GetLastError ());
        return 0;
    };
    // 消息循环是必须的,想知道原因可以查msdn
    MSG msg;
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    };
    UnhookWindowsHookEx (g_kb_hook);
    return 0;
};



[ 本帖最后由 yxwsbobo 于 2009-12-30 18:28 编辑 ]

How are you 怎么是你?
How old are you   怎么老是你?
2009-12-30 18:26
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
收藏
得分:0 
老大,你就直接帮我编译成可执行文件吧,谢谢你了!急啊急啊,编译不是这个错误就是那个错误 ,郁闷啊!
-------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(10) : error C2065: 'PMSLLHOOKSTRUCT' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(10) : error C2146: syntax error : missing ';' before identifier 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(10) : error C2065: 'p' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(10) : error C2146: syntax error : missing ';' before identifier 'l'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(13) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(13) : error C2228: left of '.x' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(13) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(13) : error C2228: left of '.x' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) : error C2228: left of '.y' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) : error C2228: left of '.y' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(15) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(15) : error C2228: left of '.x' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(15) : error C2227: left of '->pt' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(15) : error C2228: left of '.y' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(25) : error C2065: 'WH_MOUSE_LL' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(31) : error C2065: 'fprintf' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(31) : error C2065: 'stderr' : undeclared identifier
执行 cl.exe 时出错.

急啊,帮帮忙吧!

[ 本帖最后由 happymao 于 2009-12-30 23:13 编辑 ]
2009-12-30 22:01
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
收藏
得分:0 
哪位好心人或者高手,帮助一下吧,直接帮我编译成可执行文件吧,成不?
2009-12-30 23:14
yxwsbobo
Rank: 5Rank: 5
等 级:职业侠客
帖 子:345
专家分:306
注 册:2007-10-29
收藏
得分:0 
下载地址
http://d.


编译不通过2个头文件 都包含了吗
#include "windows.h"
#include "stdio.h"

How are you 怎么是你?
How old are you   怎么老是你?
2009-12-31 09:04
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
收藏
得分:0 
非常感谢楼上的老大,可惜,可能是动态链接库的原因,我这无法运行,提示:
由于应用程序配置不正确,应用程序未能启动。重新安装应用程序可能会纠正这个问题。
正在网上查找原因中……
2009-12-31 09:51
yxwsbobo
Rank: 5Rank: 5
等 级:职业侠客
帖 子:345
专家分:306
注 册:2007-10-29
收藏
得分:20 
http://d.

重编译了一下

How are you 怎么是你?
How old are you   怎么老是你?
2009-12-31 13:32
happymao
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-12-28
收藏
得分:0 
嗯,可以运行了,非常感谢
2009-12-31 14:56
lishi1122
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-1-19
收藏
得分:0 
能把源文件给我一份吗?
2010-01-19 11:48
快速回复:控制鼠标反方向移动如果编译成可执行文件?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018140 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved