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

GetCursorPos in VB.NET. How to use it?

977 views
Skip to first unread message

Willian F. Lopes

unread,
Feb 1, 2009, 7:20:39 PM2/1/09
to
Hi!

I'm trying to use the GetCursorPos function. I did this:

1) A created Module. In this module I have this code:

Public Structure POINTAPI
Public x As Long
Public y As Long
End Structure

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

2) In my main form I put a timer and it tick event I have this code:

Dim p As POINTAPI
Dim l As Long

' Get pointer position.
l = GetCursorPos(p)

' Display information.
Me.Text = CStr(p.x) + ", " + CStr(p.y)

My problem is that my mouse coordinates are always 0 ("0,0"). Where is my
error?

Thanks,

Willian

Bill McCarthy

unread,
Feb 1, 2009, 8:11:51 PM2/1/09
to
Hi Willian,

In VB.NET the definition of Long is a 64 bit integer, compared to a 32 bit
integer in VB6. Your code looks like VB6 code that hasn't been upgraded.
Try replacing "Long" with "Int32". Also for VB.NEt questions best to ask in
a dotnet group such as :
microsoft.public.dotnet.languages.vb

"Willian F. Lopes" <profw...@ig.com.br> wrote in message
news:OStFMPMh...@TK2MSFTNGP04.phx.gbl...

Kevin Provance

unread,
Mar 12, 2009, 8:03:18 PM3/12/09
to
Yeah, this isn't a .NET group, so please do not clutter up this group and
the archives with misposted information.

"John Couture" <John Cou...@discussions.microsoft.com> wrote in message
news:E9F53873-2F9C-479D...@microsoft.com...
| Hi William,
|
| A couple of things.
|
| 1. If using the GetCurosorPos, Declare the point in the API function call
| "ByRef"
| Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As
| POINTAPI) As Long
|
| 2. If you want to get away from the API call all together, try using
| Windows.Forms.Cursor.Position
|
| Example:
| Debug.Print(Windows.Forms.Cursor.Position.X.ToString & ", " &
| Windows.Forms.Cursor.Position.Y.ToString)
|
| Hope this helps.
|
| John.
|
|


0 new messages