VB SendMessage问题 80

PrivateDeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByValhwndAsLong,ByVal... Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEMOVE = &H200

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "X:"; X, "Y:"; Y
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SendMessage Command1.hwnd, WM_MOUSEMOVE, ByVal 0&, ByVal 0&
End Sub

以上代码为何debug有显示(坐标X:0,Y:0),但是CommandButton却无反应?在线等回答。

如需修改,不要模拟鼠标(mouse_event)与键盘(keybd_event)
感谢xiaoyuemt,但我要的不是这个效果。我的目的是在Label上移动鼠标时,按钮如下。
但是SendMessage虽然传送了WM_MouseMove,CommandButton也接收到了消息,但还是无法达到以下效果。
展开
 我来答
xiaoyuemt
2011-01-26 · TA获得超过1.6万个赞
知道大有可为答主
回答量:3202
采纳率:64%
帮助的人:1671万
展开全部
你的目的是要显示鼠标在label1上滑过的位置?
还是要在滑过时点击comamnd1?
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const MK_LBUTTON = &H1

Private Sub Command1_Click()
MsgBox "Click!"
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "X:"; X, "Y:"; Y
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'发送鼠标位置
SendMessage Command1.hwnd, WM_MOUSEMOVE, ByVal 0&, ByVal (X * &H10000) Or Y
'模拟单击command1
SendMessage Command1.hwnd, WM_LBUTTONDOWN, MK_LBUTTON, ByVal (5 * &H10000) Or 5
SendMessage Command1.hwnd, WM_LBUTTONUP, 0, ByVal (5 * &H10000) Or 5
End Sub
你原来的是sendmessage最后的位置参数不对。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ljl88900
2011-01-26 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2624万
展开全部
不知道你说的有反应是不是点击效果?
改成Postmessage就会有反应:
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
'仅供MouseClick调用
Private Sub Command1_Click()
MsgBox "ok"
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Debug.Print "X:"; x, "Y:"; y
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
PostMessage Command1.hwnd, WM_MOUSEMOVE, ByVal 0&, ByVal 0&
PostMessage Command1.hwnd, WM_LBUTTONDOWN, 0, 0& '模拟按下左键
PostMessage Command1.hwnd, WM_LBUTTONUP, 0, 0&
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Juncox
2011-01-29 · TA获得超过1638个赞
知道大有可为答主
回答量:1904
采纳率:0%
帮助的人:1593万
展开全部
WM_SETFOCUS

设置焦点???
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式