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
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...
"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.
|
|