GetCursorPos function... how to use?

E

expvb

Willian F. Lopes said:
Hi!

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

1) A create 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?

That code is for VB6, which use different data types. Long in VB6 is 32
bits, while it's 64 bits in VB.Net, so use Integer instead.

Also, you are supposed to use the .Net library if it already has that
functionality instead of the API, so your code can run on other platforms,
not just Windows. See System.Windows.Forms.Control.MousePosition.
 
W

Willian F. Lopes

Hi!

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

1) A create 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
 
W

Willian F. Lopes

Wow! It's very different: I used VB6 years ago and I was using Delphi now...
and I want learn VB.NET.... is very different. Thanks for help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top