我用SPY++看了鼠标左键按下拖动的过程,我想用程序自己模拟,但是我做了4天,没出来,我快崩溃了? 我单独的鼠标移动和按键已经好了,本来我以为只要双方组合就可以了,可是我到现在还没调试出来,头已经晕了,高人来指点一下,masterz等? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// mouse movement eventPOINT pt;GetCursorPos(&pt);x=pt.x;y=pt.y;if( (input_data[1]&0x80)==0x80){ input_data[1]=(~input_data[1]+1)&0x7f; y+=input_data[1];}else y-=input_data[1];x+=input_data[0];SetCursorPos(x,y);/// left button eventif((input_data[2]&0x1)==0x1) ////left button DOWN////{ buttoninfo[0]=1; if(buttoninfo[0]==1) { Input.type=INPUT_MOUSE; Input.mi.dwFlags=MOUSEEVENTF_LEFTDOWN; SendInput(1,&Input,sizeof(Input)); }}else if( ((input_data[2]&0x1)==0) && buttoninfo[0]==1 ) ////left button UP, ////这个条件是区别初始状态{ buttoninfo[0]=0; { Input.type=INPUT_MOUSE; Input.mi.dwFlags=MOUSEEVENTF_LEFTUP; SendInput(1,&Input,sizeof(Input)); }}其中input_data[0],[1]分别是x,y的偏移量上面的功能我测试过,可以的,但是按键拖动就不行 while(TRUE){ while(Peek.... { //我想你会的。 } if(ToEnd) break; //计算坐标,SetCursorPos(x,y);} 处理你的窗口的WM_LBUTTONDOWN消息CYourWnd::OnLButtonDown(UINT nFlags , CPoint point){ ::SendMessage(m_hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);}Good Luck. to : Clineyuan(营营) 不明白你的意思,能不能详细点to : wanglei888(阿笨猫) 既然是模拟的话,我不想用到WINDOWS本身的标准消息 你是想模拟鼠标移动还是想模拟SPY++的这项功能? 如果模拟鼠标拖动我想这样应该可以先mouse_event模拟鼠标左键按下,然后循环使用SetCursorPos来移动鼠标指针然后再mouse_event模拟鼠标鼠标左键松开 因为我的设备WINDOWS不认为是鼠标,但是我要用他实现鼠标的全部功能,就是这样啊 因为我的设备WINDOWS不认为是鼠标,但是我要用他实现鼠标的全部功能.1。你的设备是什么?2。鼠标的功能是操作系统实现的,不好自己实现吧。建议:AVI seeWindow Finder OLE Control http://www.codeguru.com/misc/WinFinder.shtml 向你要拖动的东东发送被鼠标拖动的消息同时用SetCursorPos来移动鼠标指针最后向你要拖动的东东发送鼠标拖动结束的消息这和拖动无标题栏的窗口有点像。 建议你把鼠标移动也用SendInput而不是SetCursorPos来做,里面可以设置鼠标移动dx,dy的同时设置dwFlags的按键状态。 太简单了。我给你个全部的代码:去我的主页:http://www.webdiy.org/srg/下载页:http://www.webdiy.org/srg/other/soft.htm找软件:ShowPw v1.0 网上有一片关于USB鼠标的制作,你看看它的源代码,也许有用,在GOOGLE上搜一下,一定能搜到的! 我不知道你究竟要做什么,但可以肯定,它涉及到进程间通讯。通过以上各位仁兄的介绍的简单方法,你是不可能打破进程间壁垒的!(因为每个进程都在自己独立的4G虚拟地址空间内运行!)如果你具备以下三方面知识,你可以做出一个Spy++那样的东西来,它们是: 1.创建动态连接库; 2.HOOK函数集的运用;(MSDN中有介绍) 3.内存映射文件。 你为HOOK函数创建的动态连接库代码可以注射到其它进程的虚拟地址空间内运行,这样你就可以拦截其进程的消息为你所用。有两个HOOK函数是专门拦截鼠标消息的。 void CHDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CWnd* pWnd = ChildWindowFromPoint(point); if (pWnd && pWnd->GetSafeHwnd() == m_stcMagnifyingGlass.GetSafeHwnd()) { SetCapture(); SetCursor(m_hMagGlassCursor); m_stcMagnifyingGlass.SetIcon(m_hMagGlassBlank); m_bIsCapturing = TRUE; } CDialog::OnLButtonDown(nFlags, point);}void CHDlg::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (m_bIsCapturing) { StopCapture(); } CDialog::OnLButtonUp(nFlags, point);}void CHDlg::StopCapture(){ if (m_bIsCapturing) { ReleaseCapture(); m_bIsCapturing = FALSE; SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));// m_stcMagnifyingGlass.SetIcon(m_hMagGlassIcon); }}BOOL CHDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class BOOL bHandledMsg = FALSE; switch (pMsg->message) { case WM_KEYDOWN: { switch (pMsg->wParam) { case VK_ESCAPE: if (m_bIsCapturing) { StopCapture(); bHandledMsg = TRUE; } break; default: break; } // switch (pMsg->wParam) } break; default: break; } // switch (pMsg->message) return CDialog::PreTranslateMessage(pMsg);} to In355Hz(好象一条狗) :我这样试过了,还是不可以 TO mengxihe(蒙溪河);你能不能说明白点 其实上面的已经说了,用mouse_event来模拟鼠标的动作。下面给你一段模拟的代码:void ProcessMessages() //处理消息队列中的消息{ MSG Msg; while(PeekMessage(&Msg,NULL,0,0, PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); }}void SimulateMose(HWND hBtn) //模拟鼠标的一段代码{ RECT Rect; DWORD dwInfo; dwInfo = GetMessageExtraInfo(); GetWindowRect(hBtn, &Rect); SetCursorPos((Rect.left+Rect.right)/2, (Rect.top +Rect.bottom)/2); //将鼠标移到Button的中间 //模拟在Button上按下鼠标 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, dwInfo); ProcessMessages(); Sleep(200); for(int n=0; n<100; n++) { //模拟移动鼠标位置(向右移) mouse_event(MOUSEEVENTF_MOVE, 2, 0, 0, dwInfo); //每次移动时暂停一下,让用户看到移动的过程 ProcessMessages(); Sleep(20); } for(int n=0; n<100; n++) { //模拟移动鼠标位置(向右移),移回原来的位置 mouse_event(MOUSEEVENTF_MOVE, -2, 0, 0, dwInfo); //每次移动时暂停一下,让用户看到移动的过程 ProcessMessages(); Sleep(20); } //模拟在Button上松开鼠标,触发Button的Click事件 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, dwInfo);} TO jishiping(JSP 季世平) :你这样实现不了鼠标按键拖动的功能 在cjlib中CCJDockContext类好像有类似的代码,你可以看看StartDragDockBar, TrackDockBar等方法 实际上你可以在DOS下先做作试验,然后再移植到Windows上来。 应该是可以的,这是我用SendInput做的实验,假设从ptA拖到PtB,不显示拖动过程,注意移动时dwFlags为MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_MOVEINPUT input[4];ZeroMemory(input, sizeof(INPUT[4]));input[0].type = INPUT_MOUSE;input[0].mi.dx = ptA.x;input[0].mi.dy = ptA.y;input[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;input[1].type = INPUT_MOUSE;input[1].mi.dx = ptA.x;input[1].mi.dy = ptA.y;input[1].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;input[2].type = INPUT_MOUSE;input[2].mi.dx = ptB.x;input[2].mi.dy = ptB.y;input[2].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_MOVE;input[3].type = INPUT_MOUSE;input[3].mi.dx = ptB.x;input[3].mi.dy = ptB.y;input[3].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP; SendInput(4, input, sizeof(INPUT)); 不知道你到底想怎么样!如果是想用鼠标来寻找窗口的话,我有个例程,如果想要的话,发邮件到[email protected] Edit能自绘么? 如何让CTreeCtrl响应CheckBox的状态改变 开发邮件系统如何连接上服务器??急 Winpcap获取网卡ID 急~做一个web的dll与本地exe通信,获取数据 如何在单文档中嵌入一个对话框? vc++ 如何进行好的界面开发 请问何处有杀“125K”的病毒的杀毒工具? 网络抓包,通过解析HTTP包得到网页内容的问题 MFC写完之后,在别的计算机运行不了 简单的问题,《Com技术内幕》上看到com程序可以简单配置后成为远程调用的Dcom程序,请问如何作?? 如何进行精确的延时????(VC)
POINT pt;
GetCursorPos(&pt);
x=pt.x;
y=pt.y;
if( (input_data[1]&0x80)==0x80)
{
input_data[1]=(~input_data[1]+1)&0x7f;
y+=input_data[1];
}
else y-=input_data[1];
x+=input_data[0];
SetCursorPos(x,y);/// left button event
if((input_data[2]&0x1)==0x1) ////left button DOWN////
{
buttoninfo[0]=1;
if(buttoninfo[0]==1)
{
Input.type=INPUT_MOUSE;
Input.mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
SendInput(1,&Input,sizeof(Input));
}
}
else if( ((input_data[2]&0x1)==0) && buttoninfo[0]==1 ) ////left button UP, ////这个条件是区别初始状态
{
buttoninfo[0]=0;
{
Input.type=INPUT_MOUSE;
Input.mi.dwFlags=MOUSEEVENTF_LEFTUP;
SendInput(1,&Input,sizeof(Input));
}
}
其中input_data[0],[1]分别是x,y的偏移量上面的功能我测试过,可以的,但是按键拖动就不行
while(TRUE)
{
while(Peek....
{
//我想你会的。
}
if(ToEnd)
break;
//计算坐标,SetCursorPos(x,y);
}
{
::SendMessage(m_hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}Good Luck.
不明白你的意思,能不能详细点to : wanglei888(阿笨猫)
既然是模拟的话,我不想用到WINDOWS本身的标准消息
我想这样应该可以先
mouse_event
模拟鼠标左键按下,然后循环使用
SetCursorPos
来移动鼠标指针
然后再
mouse_event
模拟鼠标鼠标左键松开
2。鼠标的功能是操作系统实现的,不好自己实现吧。建议:AVI
Window Finder OLE Control
http://www.codeguru.com/misc/WinFinder.shtml
同时
用SetCursorPos来移动鼠标指针
最后
向你要拖动的东东发送鼠标拖动结束的消息这和拖动无标题栏的窗口有点像。
http://www.webdiy.org/srg/下载页:
http://www.webdiy.org/srg/other/soft.htm找软件:ShowPw v1.0
1.创建动态连接库;
2.HOOK函数集的运用;(MSDN中有介绍)
3.内存映射文件。
你为HOOK函数创建的动态连接库代码可以注射到其它进程的虚拟地址空间内运行,这样你就可以拦截其进程的消息为你所用。有两个HOOK函数是专门拦截鼠标消息的。
{
// TODO: Add your message handler code here and/or call default
CWnd* pWnd = ChildWindowFromPoint(point);
if (pWnd && pWnd->GetSafeHwnd() == m_stcMagnifyingGlass.GetSafeHwnd())
{
SetCapture();
SetCursor(m_hMagGlassCursor);
m_stcMagnifyingGlass.SetIcon(m_hMagGlassBlank); m_bIsCapturing = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}void CHDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bIsCapturing)
{
StopCapture();
}
CDialog::OnLButtonUp(nFlags, point);
}
void CHDlg::StopCapture()
{
if (m_bIsCapturing)
{
ReleaseCapture();
m_bIsCapturing = FALSE;
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
// m_stcMagnifyingGlass.SetIcon(m_hMagGlassIcon);
}
}BOOL CHDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
BOOL bHandledMsg = FALSE;
switch (pMsg->message)
{
case WM_KEYDOWN:
{
switch (pMsg->wParam)
{
case VK_ESCAPE:
if (m_bIsCapturing)
{
StopCapture();
bHandledMsg = TRUE;
}
break;
default: break;
} // switch (pMsg->wParam)
}
break;
default: break;
} // switch (pMsg->message)
return CDialog::PreTranslateMessage(pMsg);
}
我这样试过了,还是不可以
你能不能说明白点
模拟的代码:
void ProcessMessages() //处理消息队列中的消息
{
MSG Msg; while(PeekMessage(&Msg,NULL,0,0,
PM_REMOVE)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}void SimulateMose(HWND hBtn) //模拟鼠标的一段代码
{
RECT Rect;
DWORD dwInfo; dwInfo = GetMessageExtraInfo();
GetWindowRect(hBtn, &Rect);
SetCursorPos((Rect.left+Rect.right)/2, (Rect.top
+Rect.bottom)/2); //将鼠标移到Button的中间
//模拟在Button上按下鼠标
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, dwInfo);
ProcessMessages(); Sleep(200);
for(int n=0; n<100; n++) {
//模拟移动鼠标位置(向右移)
mouse_event(MOUSEEVENTF_MOVE, 2, 0, 0, dwInfo);
//每次移动时暂停一下,让用户看到移动的过程
ProcessMessages(); Sleep(20);
}
for(int n=0; n<100; n++) {
//模拟移动鼠标位置(向右移),移回原来的位置
mouse_event(MOUSEEVENTF_MOVE, -2, 0, 0, dwInfo);
//每次移动时暂停一下,让用户看到移动的过程
ProcessMessages(); Sleep(20);
}
//模拟在Button上松开鼠标,触发Button的Click事件
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, dwInfo);
}
你这样实现不了鼠标按键拖动的功能
你可以看看StartDragDockBar, TrackDockBar等方法
ZeroMemory(input, sizeof(INPUT[4]));input[0].type = INPUT_MOUSE;
input[0].mi.dx = ptA.x;
input[0].mi.dy = ptA.y;
input[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
input[1].type = INPUT_MOUSE;
input[1].mi.dx = ptA.x;
input[1].mi.dy = ptA.y;
input[1].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
input[2].type = INPUT_MOUSE;
input[2].mi.dx = ptB.x;
input[2].mi.dy = ptB.y;
input[2].mi.dwFlags =
MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_MOVE;
input[3].type = INPUT_MOUSE;
input[3].mi.dx = ptB.x;
input[3].mi.dy = ptB.y;
input[3].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
SendInput(4, input, sizeof(INPUT));
如果是想用鼠标来寻找窗口的话,我有个例程,如果想要的话,发邮件到[email protected]