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也接收到了消息,但还是无法达到以下效果。 展开
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也接收到了消息,但还是无法达到以下效果。 展开
3个回答
展开全部
你的目的是要显示鼠标在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最后的位置参数不对。
还是要在滑过时点击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最后的位置参数不对。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不知道你说的有反应是不是点击效果?
改成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
改成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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
WM_SETFOCUS
设置焦点???
设置焦点???
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询