VB判断鼠标是否按下

在鼠标不在窗体上的情况下判断鼠标左键是否按下。最好是api方法。... 在鼠标不在窗体上的情况下判断鼠标左键是否按下。最好是api方法。 展开
 我来答
匿名用户
2013-11-18
展开全部
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_USER = &H400
Public Const WM_MBUTTONDBLCLK = &H209
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public OldWindowProc As Long
Public Myform As Form
Public AA As Long
Public Sub CheckMouse(A As Form)
Set Myform = A
OldWindowProc = GetWindowLong(Myform.hwnd, GWL_WNDPROC)
SetWindowLong Myform.hwnd, GWL_WNDPROC, AddressOf NewWindowProc
End Sub
Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_LBUTTONUP
Form1.Text1 = "LBUTTONUP"
Case WM_LBUTTONDOWN
Form1.Text1 = "LBUTTONDOWN"
Case WM_LBUTTONDBLCLK
Form1.Text1.Enabled = True
Case WM_RBUTTONDBLCLK
Form1.Text1.Enabled = False
Case WM_RBUTTONDOWN
Form1.Text1.Text = "RBUTTONDOWN"
Case WM_RBUTTONUP
Form1.Text1.Text = "RBUTTONUP"
End Select
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Function

Private Sub Form_Load()
CheckMouse Form1
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式