Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Offset Cursor x-y Position from a Shape 1

Status
Not open for further replies.

jadadad

Technical User
Jun 2, 2004
12
US
I have drawn an irregular rectangle shape using “Lines” in Excel 2000. I have assigned a macro titled “WhereAmI” (see below) to that shape that outputs the x and y position of the cursor. And it works just fine. But, I need to set x = 0 and y = 0 at the lower left corner of this irregular rectangle shape and reference (or offset) the cursor position from that lower left corner position. This shape is not in a userform, it’s just placed on top of a worksheet.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Sub WhereAmI()
Dim pTargetPoint As POINTAPI
Dim lRetVal As Long
lRetVal = GetCursorPos(pTargetPoint)
MsgBox "My Position:" & vbLf & pTargetPoint.x & "," & pTargetPoint.y
End Sub
 
Generally, the Y-value is inverted when windows reports the mouse position, i.e. top is zero and increases as you go down the screen. You should be able to do the math and convert to something like
LocalY = Height-Y
LocalX = X
and work with the converted values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top