04/05/2012, 13:01
Kod:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long
[code]
Kod:
Public Function SetCursorPosition(Window As Object, xPos As _
Long, yPos As Long) As Boolean
'AUTHOR: FreeVBCode.com (http://www.freevbcode.com)
'Usage: Window = window for which you want
'to set the cursof for (form or control)
'window must support hwnd property; function will
'return false if it doesn't (e.g., won't work
'with labels)
'x = xPosition in twips
'y = yPosition in twips
'if you are not using twips as your scale mode
'you must convert the value to pixels from your
'metric. There is a function on FreeVBCode.com
'that does this, under the System/API
'category
On Error GoTo errorhandler
Dim x As Long, y As Long
Dim lRet As Long
Dim lHandle As Long
Dim typPoint As POINTAPI
lHandle = Window.hwnd
With Screen
x = CLng(xPos / .TwipsPerPixelX)
y = CLng(yPos / .TwipsPerPixelY)
End With
typPoint.x = x
typPoint.y = y
lRet = ClientToScreen(lHandle, typPoint)
lRet = SetCursorPos(typPoint.x, typPoint.y)
SetCursorPosition = (lRet <> 0)
Exit Function
errorhandler:
SetCursorPosition = False
Exit Function
End Function