rbulph Posted July 18, 2009 Posted July 18, 2009 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 Quote
Leaders snarfblam Posted July 19, 2009 Leaders Posted July 19, 2009 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. Quote [sIGPIC]e[/sIGPIC]
rbulph Posted July 20, 2009 Author Posted July 20, 2009 Thanks, that seems better. I'll let you know if I run into any problems. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.