첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ 마우스 위치를 폼 내부로 제한하기

----------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요