■ 마우스 위치를 폼 내부로 제한하는 방법을 보여준다.
▶ 예제 코드 (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Option Explicit Private Declare Function ClientToScreen& Lib "user32" (ByVal pWindowHandle As Long, pPOINT As POINT) Private Declare Function ClipCursor& Lib "user32" (pRECT As RECT) Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal pRECT As Long) Private Declare Function SetCursorPos& Lib "user32" (ByVal X As Long, ByVal Y As Long) Private Type POINT X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Sub Form_Load() Me.ScaleMode = 3 ' 픽셀 End Sub Private Sub btnStart_Click() Dim pRECT As RECT Dim pPOINT As POINT pPOINT.X = 0 pPOINT.Y = 0 ClientToScreen& Me.hwnd, pPOINT pRECT.Top = pPOINT.Y pRECT.Left = pPOINT.X pRECT.Right = pRECT.Left + Me.ScaleWidth pRECT.Bottom = pRECT.Top + Me.ScaleHeight ClipCursor& pRECT End Sub Private Sub btnRestore_Click() ClipCursorBynum& 0 End Sub |