View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default capturing mouse positions at any moment

Be aware of 1 thing though:

When you use the coords from this api (or an office.commandbar) these
will be given with a actual screenres of 96ppi.

Excel's coordinates from say .cells(3).Left will be given with a default
of 72ppi ... more like pixels :(

this means that any coords you use to get or set directly from excel in
'POINTS' need to be multiplied by 96/72

Also Excel's coord (0.0) from say a worksheet start in the usable area
(depending on whether toolbars are docked etc)

'Get the starting point of the xlDesktop (Usable Area)
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As
Long, lpPoint As POINTAPI) As Long

dim p as pointapi
dim lhnd as long
dim lret as long
lhnd = application.hWnd 'This works for xlXP and newer
lRet = ClientToScreen(lHnd, p) 'This fills p


hth...



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote:

Hi Shrinu,

Here is some code to return the mouse position as a simple function .

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Sub test()
Dim pPosition As POINTAPI
Dim lReturn As Long

lReturn = GetCursorPos(pPosition)
MsgBox "Cursor position is:" & vbCrLf & _
"x co-ordinate: " & pPosition.x & vbCrLf & _
"y co-ordinate: " & pPosition.y

End Sub

I also have some code that dynamically returns the mouse position into
the status bar. Post back if that would be useful.