vb 屏蔽鼠标左键功能

让该窗体运行时屏蔽鼠标左键的点击,结束运行时恢复正常。请写源码!!... 让该窗体运行时屏蔽鼠标左键的点击,结束运行时恢复正常。请写源码!! 展开
 我来答
bo...g@163.com
2012-01-21
知道答主
回答量:38
采纳率:0%
帮助的人:15.8万
展开全部
这个问题我可以帮你解决。请速联系我。
追问
说说看,怎么解决?请写源码。
追答
Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

Private Sub Form_Load()
ShowCursor 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
ShowCursor 1
End Sub

主人为什么不给我悬赏分呢。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
九天狼
2012-01-21 · TA获得超过526个赞
知道小有建树答主
回答量:468
采纳率:0%
帮助的人:180万
展开全部
是屏蔽在这个窗口内的左键,还是屏蔽系统中的?
追问
是窗口内的左键
追答
楼上的,那个是把鼠标隐藏了。。不能实现楼主的要求。
以下代码可以完美实现要求,还可以屏蔽其它键:
首先,建一个模块,把下面代码放里边:
Option Explicit

Private Const HC_ACTION = 0
Private Const HC_NOREMOVE = 3
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public hHook As Long

Public Function MouseProc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = HC_ACTION Then
If (wParam = WM_LBUTTONDOWN) Or (wParam = WM_LBUTTONDBLCLK) Then ’把这里的LBUTTON改为RBUTTON,则可以屏蔽右键。或者同样的加上两个Or的条件,可以屏蔽左右键。
MouseProc = 1
Exit Function
End If
End If

MouseProc = CallNextHookEx(hHook, ncode, wParam, ByVal lParam)
End Function

然后,把下面代码放窗体代码里:
Option Explicit

Private Const WH_MOUSE = 7
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Private Sub Form_Load()
hHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, 0, App.ThreadID)
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub

即可实现楼主的要求
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式