Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to get hold of basic information about the screen cursor. But the following doesn't work at all. What am I doing wrong?

 

Public Class Form1
   Private Declare Function GetCursorInfo Lib "user32.dll" (ByVal pc As CURSORINFO) As Long
   'Idea to only click when cursor is a hand. Can't get it to work in .net. Works OK in VB6 though.
   Structure CURSORINFO
       Dim cbsize As Long
       Dim flags As Long
       Dim hCUrsor As Long
       Dim p As Point
   End Structure

   Structure PointAPI
       Dim X As Long
       Dim Y As Long
   End Structure
   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Dim ff As New CURSORINFO

       ff.cbsize = System.Runtime.InteropServices.Marshal.SizeOf(GetType(CURSORINFO))
       GetCursorInfo(ff)
       With ff
           'All of the following just show zero.
           Label1.Text = .p.X
           Label2.Text = .p.Y
           Label3.Text = .hCUrsor
       End With

   End Sub

End Class

  • Leaders
Posted

This is probably what your declarations should look like:

   Private Declare Function GetCursorInfo Lib "user32.dll" ([color="Red"]ByRef [/color]pc As CURSORINFO) As [color="Red"]Integer[/color]

   Structure CURSORINFO
       Dim cbsize As [color="Red"]Integer[/color]
       Dim flags As [color="Red"]Integer[/color]
       Dim hCUrsor As [color="Red"]Integer[/color]
       Dim p As [color="Red"]PointAPI[/color]
   End Structure

   Structure PointAPI
       Dim X As [color="Red"]Integer[/color]
       Dim Y As [color="Red"]Integer[/color]
   End Structure

It seems like on the webs, most Windows API function declarations for VB are for VB6. A VB6 Long is the same thing as a DotNet Integer: 32-bits. A DotNet Long is 64-bits.

 

Also, the GetCursor function wants a pointer to the CURSORINFO (that is what the "p" in "pc" stands for). When you pass it ByRef, VB passes a pointer (i.e. "reference") to the object. If you pass it ByVal, it would be read-only and the function would be unable to return any data to you.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...