Ooops
October 28, 2020, 06:42:22 AM

Author Topic: [bb] LockPointerToWindow by Xaymar [ 1+ years ago ]  (Read 1153 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] LockPointerToWindow by Xaymar [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
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
  1. ;----------------------------------------------------------------
  2. ;-- Userlib
  3. ;----------------------------------------------------------------
  4. ;.lib "User32.dll"
  5. ;User32_ClientToScreen%(hwnd%, point*):"ClientToScreen"
  6. ;User32_ClipCursor%(rect*):"ClipCursor"
  7. ;User32_GetSystemMetrics%(index%):"GetSystemMetrics"
  8. ;----------------------------------------------------------------
  9.  
  10. ;----------------------------------------------------------------
  11. ;-- Types
  12. ;----------------------------------------------------------------
  13. Type Rectangle
  14.         Field X,Y,X2,Y2
  15. End Type
  16.  
  17. Type Point
  18.         Field X,Y
  19. End Type
  20. ;----------------------------------------------------------------
  21.  
  22. ;----------------------------------------------------------------
  23. ;-- Global
  24. ;----------------------------------------------------------------
  25. Global Utility_Rect.Rectangle = New Rectangle
  26. Global Utility_Point.Point = New Point
  27. ;----------------------------------------------------------------
  28.  
  29. ;----------------------------------------------------------------
  30. ;-- Functions
  31. ;----------------------------------------------------------------
  32. Function Utility_LockPointerToWindow(hwnd=0)
  33.         If hwnd = 0 Then
  34.                 Utility_RectX = 0
  35.                 Utility_RectY = 0
  36.                 Utility_RectX2 = User32_GetSystemMetrics(78)
  37.                 Utility_RectY2 = User32_GetSystemMetrics(79)
  38.                 User32_ClipCursor(Utility_Rect)
  39.         Else
  40.                 ;Grab TopLeft
  41.                 Utility_PointX = 0
  42.                 Utility_PointY = 0
  43.                 User32_ClientToScreen(hwnd, Utility_Point)
  44.                 Utility_RectX = Utility_PointX
  45.                 Utility_RectY = Utility_PointY
  46.                
  47.                 ;Grab BottomRight
  48.                 Utility_PointX = GraphicsWidth()
  49.                 Utility_PointY = GraphicsHeight()
  50.                 User32_ClientToScreen(hwnd, Utility_Point)
  51.                 Utility_RectX2 = Utility_PointX
  52.                 Utility_RectY2 = Utility_PointY
  53.                
  54.                 User32_ClipCursor(Utility_Rect)
  55.         EndIf
  56. End Function
  57. ;----------------------------------------------------------------


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal