古詩詞大全網 - 成語查詢 - vb , ClipCursor 為什麽單擊之後失效

vb , ClipCursor 為什麽單擊之後失效

應該是改變了窗口的RECT信息導致失效。

可以進壹步限制,使鼠標不能碰到窗體邊界,試試如下代碼:

'倆command

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 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 Sub Command1_Click() '限制鼠標

Dim client As RECT

Dim upperleft As POINT

GetClientRect Me.hWnd, client

upperleft.x = client.left

upperleft.y = client.top

ClientToScreen Me.hWnd, upperleft

OffsetRect client, upperleft.x, upperleft.y

ClipCursor client

End Sub

Private Sub Command2_Click() '取消限制

ClipCursor ByVal 0&

End Sub

Private Sub Form_Unload(Cancel As Integer) '釋放

ClipCursor ByVal 0&

End Sub