用sendmessage或postmessage模拟鼠标消息WM_MOUSEMOVE(在线等)

miky131499 2004-12-31 02:22:13
我想使用sendmessage()模拟鼠标动作
简单说明:
HWND hwnd
CPoint point;
::SendMessage(hwnd,WM_MOUSEMOVE,1,MAKELPARAM(point.x,point.y));
::SendMessage(hwnd,WM_LBUTTONDOWN,1 ,MAKELPARAM(point.x,point.y));
::SendMessage(hwnd,WM_LBUTTONUP,1 ,MAKELPARAM(point.x,point.y));

但不能达到预期,目的,请高手们指点一下,谢谢了
...全文
2366 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2004-12-31
  • 打赏
  • 举报
回复
那是由于在LPINPUT的声明之前有一个条件判断宏
#if (_WIN32_WINNT > 0x0400)
即判断你的操作系统的版本号,版本号定义如下:
Windows 95 and Windows NT 4.0 WINVER=0x0400
Windows 98 and Windows NT 4.0 _WIN32_WINDOWS=0x0410 and WINVER=0x0400
Windows NT 4.0 _WIN32_WINNT=0x0400 and WINVER=0x0400
Windows 98 and Windows 2000 WINVER=0x0500
Windows 2000 _WIN32_WINNT=0x0500 and WINVER=0x0500
Internet Explorer 3.0 _WIN32_IE=0x0300
Internet Explorer 4.0 _WIN32_IE=0x0400
Internet Explorer 5.0 _WIN32_IE=0x0500

而你的stdafx.h最前面添加宏
#define _WIN32_WINNT 0x0500
在将WINUSER.H包含进去
寻开心 2004-12-31
  • 打赏
  • 举报
回复
#include <WinAble.h>
不用winuser.h即可
HunterForPig 2004-12-31
  • 打赏
  • 举报
回复
同意 用 mouse_event
作远程控制 ?兄台
寻开心 2004-12-31
  • 打赏
  • 举报
回复
http://www.codeproject.com/cpp/togglekeys.asp
miky131499 2004-12-31
  • 打赏
  • 举报
回复
加了以后没出现未命名提示了,但是出现了
#error WINDOWS.H already included. MFC apps must not #include <windows.h>
的错误~~~
miky131499 2004-12-31
  • 打赏
  • 举报
回复
不行啊
miky131499 2004-12-31
  • 打赏
  • 举报
回复
啊哦。我再看看
DentistryDoctor 2004-12-31
  • 打赏
  • 举报
回复
用mouse_event或者SendInput这个API
INPUT在WinUser.h中定义,包含windows.h,可能需要安装PlatformSDK.
miky131499 2004-12-31
  • 打赏
  • 举报
回复
请帮我看下怎么不能编译啊。其中一个错误是说INPUT是未声明的标识符
CPoint point;
point.x=500;
point.y=500;
INPUT input[2];

//定义左建按下的input
input[0].type=INPUT_MOUSE;
input[0].mi.dx=point.x;
input[0].mi.dy=point.y;
input[0].mi.mouseData=0;
input[0].mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
input[0].mi.time=0;
input[0].mi.dwExtraInfo=0;
//定义左建拿起的input

input[1].type=INPUT_MOUSE;
input[1].mi.dx=point.x;
input[1].mi.dy=point.y;
input[1].mi.mouseData=0;
input[1].mi.dwFlags=MOUSEEVENTF_LEFTUP;
input[1].mi.time=0;
input[1].mi.dwExtraInfo=0;
miky131499 2004-12-31
  • 打赏
  • 举报
回复
能给我来一个SendInput的详细点的例子吗?朋友们
miky131499 2004-12-31
  • 打赏
  • 举报
回复
还是没有OK
老夏Max 2004-12-31
  • 打赏
  • 举报
回复
::SendMessage(hwnd,WM_SYSCOMMAND,MAKEWPARAM(WM_LBUTTONUP,0) ,MAKELPARAM(point.x,point.y));
miky131499 2004-12-31
  • 打赏
  • 举报
回复
谢谢vcleaner的回答,我忘了补充,就是不用mouse_event完成
danyueer 2004-12-31
  • 打赏
  • 举报
回复
用mouse_event或者SendInput这个API

SendInput
The SendInput function synthesizes keystrokes, mouse motions, and button clicks.

UINT SendInput(
UINT nInputs, // count of input events
LPINPUT pInputs, // array of input events
int cbSize // size of structure
);
老夏Max 2004-12-31
  • 打赏
  • 举报
回复
mouse_event

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧