Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get mouse position

4 views
Skip to first unread message

Thomas Wormser

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
Hello,
does anyone know, how to get the mouse position when adding a shape by menu
item.
What I want is to get information about x and y position after adding a line
or a circle.

Thanks in advance and bye

Thomas

Jake Marx

unread,
Mar 29, 2000, 3:00:00 AM3/29/00
to
Hi Thomas,

You can use the GetWindowPos API function to do this. Here's an example:

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

Public Type POINTAPI
x As Long
y As Long
End Type

Public Sub DisplayMousePosition()
Dim uPoint As POINTAPI

If GetCursorPos(uPoint) Then
MsgBox "X: " & CStr(uPoint.x) & " points" & vbLf _
& "Y: " & CStr(uPoint.y) & " points", vbInformation, _
"Mouse Coordinates"
Else
MsgBox "Error retrieving coordinates."
End If
End Sub


Regards,
Jake Marx

Thomas Wormser <comp...@nbg.netdiscounter.de> wrote in message
news:egkAAPam$GA.256@cppssbbsa05...

Thomas Wormser

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
Hello Jake,
first of al thank you very much. Your code ist exactly what I am searching
for.
The function GetCursorPos gives me every clicked position on sheet.
Perhaps I am standing behind moon - but why I don't get a message when
adding a line or other objects ?

Have a nice day!

Thomas


Tom Ogilvy

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
You won't get the position unless the code runs that returns it. It sounds
like you have it in the worksheet_selectionChange event. If so, that only
fires when a cell is selected - not when anything is selected.

Regards,
Tom Ogilvy
MVP Excel

Thomas Wormser <comp...@nbg.netdiscounter.de> wrote in message

news:#Qxc2atm$GA....@cppssbbsa02.microsoft.com...

Jake Marx

unread,
Mar 31, 2000, 3:00:00 AM3/31/00
to
Hi Thomas,

I'm not sure exactly what you're looking for here. I was thinking you'd
want to know where the cursor was at any given moment. To do that, you'd
probably want to assign a shortcut (e.g. Ctrl+Shift+P) to the routine I gave
you before to display the current cursor position.

Here's another routine that might help you out. Basically, it will give you
the coordinates of any selected shape.

If this is not what you want either, you need to post back with more detail
so we know what you are looking for.

Regards,
Jake Marx


Sub GetShapeCoordinates()
Dim nLeft As Integer
Dim nRight As Integer
Dim nTop As Integer
Dim nBottom As Integer

On Error GoTo ErrHandler

If TypeOf Selection Is Object Then
With Selection
nLeft = .Left
nRight = nLeft + .Width
nTop = .Top
nBottom = nTop + .Height
End With

MsgBox "Left: " & CStr(nTop) & vbLf & _
"Right: " & CStr(nRight) & vbLf & _
"Top: " & CStr(nTop) & vbLf & _
"Bottom: " & CStr(nBottom), _
vbInformation, "Shape " & _
Selection.Name & " Coordinates"
End If

ExitRoutine:
Exit Sub
ErrHandler:
MsgBox "You must select a shape before running " & _
"this routine.", vbExclamation, "Error"
Resume ExitRoutine
End Sub


Regards,
Jake Marx


Thomas Wormser

unread,
Apr 1, 2000, 3:00:00 AM4/1/00
to
Hi Jake,
first of all thanks for the time you spend for me. And you are really excel
specialist, too.
Your last routine gives me e.g. the 2 points of a selected line. That's ok.

But I think, I have to tell you the context.
If it sounds complicated to you, then it's my bad English. I will do my
best.
OK!
In the past months I have made a mechanical calculation software. It's
programmed with Borland's Delphi.
With this software you can calculated the price of every sheet metal part
is this the correct definition? ).
This software is based on a big database and has also the CAD-possibilities
(drawing lines,circles,polygons and other objects).
The calculation works quit exactly, but for end-user it's not so easy to
understand.

At all the past rainy weekends I discovered EXCEL and little VBA
programming. You see, Jake, I am a beginner on this terrain.
The cell-functions of Excel I like very much, because they are quite easy.
So I started to make a "quick and easy" calculation. The excel file has to
sheets ("Calcul" and "Data").
Calcul takes user-prompts and shows results. Data sheet holds a small
"database".

My idea is to design the sheet metall parts in Excel.
A easy sheet metal part could look like this:

Now you see what I want to do.
In my opinion, I only can get positions, if it' possible to declare user
events on a worksheet. ( probably the events OnMouseDown and OnMouseUp )

If I can get each point (x,y position) of a line so I write them in an
array.
Afterwards I have to calculate the length of each line and sum up all lines.
The result of this crazy thing is to get the whole figure-size in inch
"mm" in Gemany).

Parts like the above one have to be manufactured on laser-cutting machines.
If I know the figure size of this part, I know the running time on the laser
machine.

That's the reason for all sleepless nights.

Perhaps You can help me.

Bye,
Thomas

0 new messages