Option
Explicit
Private
Declare
PtrSafe
Function
WindowFromPoint
Lib
"user32"
( _
ByVal
xPoint
As
Long
,
ByVal
yPoint
As
Long
)
As
LongPtr
Private
Declare
PtrSafe
Function
GetWindowRect
Lib
"user32"
( _
ByVal
hWnd
As
LongPtr, lpRect
As
RECT)
As
Long
Private
Declare
PtrSafe
Function
SetCursorPos
Lib
"user32"
( _
ByVal
x
As
Long
,
ByVal
y
As
Long
)
As
Long
Private
Declare
PtrSafe
Function
GetCursorPos
Lib
"user32"
( _
lpPoint
As
POINTAPI)
As
Long
Private
Declare
PtrSafe
Function
GetClientRect
Lib
"user32"
( _
ByVal
hWnd
As
LongPtr, lpRect
As
RECT)
As
Long
Private
Declare
PtrSafe
Function
ClientToScreen
Lib
"user32"
( _
ByVal
hWnd
As
LongPtr, lpPoint
As
POINTAPI)
As
Long
Private
Type POINTAPI
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
Sub
Test_SetzeMauscursor()
Dim
RECT1
As
RECT, Pt
As
POINTAPI
XlsPos2ScreenPos RECT1
With
RECT1
GetCursorPos Pt
If
Pt.x > .Left
And
Pt.y > .Top
And
Pt.x < (.Left + .Right)
And
Pt.y < (.Top + .Bottom)
Then
Application.Cursor = xlNorthwestArrow
Else
Application.Cursor = xlDefault
End
If
End
With
End
Sub
Function
XlsPos2ScreenPos(tCRect
As
RECT)
As
Boolean
Dim
Pt
As
POINTAPI, cZoom
As
Currency
Dim
Px
As
Long
, Py
As
Long
, i
As
Integer
cZoom = ActiveWindow.Zoom * 0.016666666
GetClientRect Application.hWnd, tCRect
Pt.x = tCRect.Left: Pt.y = tCRect.Top
ClientToScreen Application.hWnd, Pt
Px = Pt.x
Py = Pt.y + CommandBars(
"Ribbon"
).Controls(1).Height
If
Application.DisplayFormulaBar =
True
Then
_
Py = Py + 15 + 24 * Application.FormulaBarHeight + 15
With
ActiveWindow
If
.DisplayHeadings =
True
Then
Px = Px + 0.37 * .Zoom
Py = Py + 0.23 * .Zoom
End
If
Px = Px + Selection.Left * cZoom
For
i = 1
To
Selection.Column
If
i < .ScrollColumn
Then
_
Px = Px - Columns(i).Width * cZoom
Next
i
Py = Py + Selection.Top * cZoom
For
i = 1
To
Selection.Row
If
i < .ScrollRow
Then
_
Py = Py - Rows(i).Height * cZoom
Next
i
End
With
With
tCRect
.Left = Px - 1: .Top = Py - 1
.Right = Selection.Width * cZoom
.Bottom = Selection.Height * cZoom
End
With
End
Function