锁定鼠标是最好的方法!!! 'Example Name:ClipCursor Private Type RECT left As Long top As Long right As Long bottom As Long End Type Private Type POINT x As Long y As Long End Type Private Declare Sub ClipCursor Lib "user32" (lpRect As Any) Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT) Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) Private Sub Form_Load() 'KPD-Team 1999 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Command1.Caption = "Limit Cursor Movement" Command2.Caption = "Release Limit" End Sub Private Sub Command1_Click() 'Limits the Cursor movement to within the form. Dim client As RECT Dim upperleft As POINT 'Get information about our wndow GetClientRect Me.hWnd, client upperleft.x = client.left upperleft.y = client.top 'Convert window co?rdinates to screen co?rdinates ClientToScreen Me.hWnd, upperleft 'move our rectangle OffsetRect client, upperleft.x, upperleft.y 'limit the cursor movement ClipCursor client End Sub Private Sub Command2_Click() 'Releases the cursor limits ClipCursor ByVal 0& End Sub Private Sub Form_Unload(Cancel As Integer) 'Releases the cursor limits ClipCursor ByVal 0& End Sub
干脆让Window不接受键盘输入及Mouse Click:Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click() Call EnableWindow(Me.hwnd, 0) Me.Caption = "现在拒绝KeyPress, MouseClick" Dim i As Long For i = 1 To 100 Call Sleep(100) DoEvents '虽有DoEvents,会发现,按Form的任何地方都没有反应 Next i Me.Caption = "现在解除了" Call EnableWindow(Me.hwnd, 1) End Sub 不过Mouse仍可自由的移动,若要让Mouse也不能动,就使用JournalPlayBack Hook,而不是使用本方法。
'Example Name:ClipCursor
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Command1.Caption = "Limit Cursor Movement"
Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
'Get information about our wndow
GetClientRect Me.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Convert window co?rdinates to screen co?rdinates
ClientToScreen Me.hWnd, upperleft
'move our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub Command2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
楼主要的话我可以给你做一个。 :)
BlockInput 0 ' 活过来
注意Ctrl+Alt+Del可以立即取消BlockInput的效果。而且当执行BlockInput时当前窗口不属同一进程时,不会产生任何效果。
BlockInput 0 ' 活过来
注意Ctrl+Alt+Del可以立即取消BlockInput的效果。而且当执行BlockInput时当前窗口不属同一进程时,不会产生任何效果。
如果想麻烦,需要安装 WH_KEYBOARD_LL 钩子, VB就算了吧
(我见有文章这样说,我个人没用过)
先得到桌面窗口的句柄和任务栏的句柄,用Enablewindow来禁用桌面及任务栏
或者干脆用Sendmessage发送一个SW_HIDE来隐藏窗口,Progman 任务栏类名
然后隐藏任务栏
FindWindow ("Shell_TrayWnd",NULL) '找到任务栏的句柄
showwindow(hwnd,false)
注意最好是锁定鼠标,用系统热键呼叫解锁程序
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()
Call EnableWindow(Me.hwnd, 0)
Me.Caption = "现在拒绝KeyPress, MouseClick"
Dim i As Long
For i = 1 To 100
Call Sleep(100)
DoEvents '虽有DoEvents,会发现,按Form的任何地方都没有反应
Next i
Me.Caption = "现在解除了"
Call EnableWindow(Me.hwnd, 1)
End Sub
不过Mouse仍可自由的移动,若要让Mouse也不能动,就使用JournalPlayBack Hook,而不是使用本方法。