[bb] LockPointerToWindow by Xaymar [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : LockPointerToWindow
Author : Xaymar
Posted : 1+ years ago

Description : Utility_LockPointerToWindow( hwnd=0 )
This function locks the Windows cursor into the client area of a window(hwnd not 0) or unlocks it completely(hwnd is 0). This works by using the User32.dll to transfrom from client area space to desktop space and the calling ClipCursor with the rectangle we now have.


Code :
Code (blitzbasic) Select
;----------------------------------------------------------------
;-- Userlib
;----------------------------------------------------------------
;.lib "User32.dll"
;User32_ClientToScreen%(hwnd%, point*):"ClientToScreen"
;User32_ClipCursor%(rect*):"ClipCursor"
;User32_GetSystemMetrics%(index%):"GetSystemMetrics"
;----------------------------------------------------------------

;----------------------------------------------------------------
;-- Types
;----------------------------------------------------------------
Type Rectangle
Field X,Y,X2,Y2
End Type

Type Point
Field X,Y
End Type
;----------------------------------------------------------------

;----------------------------------------------------------------
;-- Global
;----------------------------------------------------------------
Global Utility_Rect.Rectangle = New Rectangle
Global Utility_Point.Point = New Point
;----------------------------------------------------------------

;----------------------------------------------------------------
;-- Functions
;----------------------------------------------------------------
Function Utility_LockPointerToWindow(hwnd=0)
If hwnd = 0 Then
Utility_RectX = 0
Utility_RectY = 0
Utility_RectX2 = User32_GetSystemMetrics(78)
Utility_RectY2 = User32_GetSystemMetrics(79)
User32_ClipCursor(Utility_Rect)
Else
;Grab TopLeft
Utility_PointX = 0
Utility_PointY = 0
User32_ClientToScreen(hwnd, Utility_Point)
Utility_RectX = Utility_PointX
Utility_RectY = Utility_PointY

;Grab BottomRight
Utility_PointX = GraphicsWidth()
Utility_PointY = GraphicsHeight()
User32_ClientToScreen(hwnd, Utility_Point)
Utility_RectX2 = Utility_PointX
Utility_RectY2 = Utility_PointY

User32_ClipCursor(Utility_Rect)
EndIf
End Function
;----------------------------------------------------------------


Comments : none...