求问使用SendMessage发送鼠标点击事件,为何需要发送两次
展开全部
然后又写了另外一个程序,来给这个测试程序发送鼠标点击消息。代码如下:
HWND hand_game = FindWindow(NULL,TEXT(测试文件));
HWND hand_button = FindWindowEx(hand_game,NULL,TEXT(Button),TEXT(点击));//得到按钮的句柄
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
上述代码是实现发送的程序中的一个按钮的响应代码,点击这个发送按钮后,发现测试程序中的按钮得到了焦点,但是为弹出MessageBox……再次点击发送消息的程序中的按钮,这次测试程序弹出了MessageBox,经测试发下,只有两次单击发送消息,或者将代码改成下面的样子:
HWND hand_game = FindWindow(NULL,TEXT(测试文件));
HWND hand_button = FindWindowEx(hand_game,NULL,TEXT(Button),TEXT(点击));//得到按钮的句柄
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
//发送两次:
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
HWND hand_game = FindWindow(NULL,TEXT(测试文件));
HWND hand_button = FindWindowEx(hand_game,NULL,TEXT(Button),TEXT(点击));//得到按钮的句柄
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
上述代码是实现发送的程序中的一个按钮的响应代码,点击这个发送按钮后,发现测试程序中的按钮得到了焦点,但是为弹出MessageBox……再次点击发送消息的程序中的按钮,这次测试程序弹出了MessageBox,经测试发下,只有两次单击发送消息,或者将代码改成下面的样子:
HWND hand_game = FindWindow(NULL,TEXT(测试文件));
HWND hand_button = FindWindowEx(hand_game,NULL,TEXT(Button),TEXT(点击));//得到按钮的句柄
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
//发送两次:
SendMessage(hand_button,WM_LBUTTONDOWN,0,MAKELPARAM(46,12));
SendMessage(hand_button,WM_LBUTTONUP,0,MAKELPARAM(46,12));
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询