How to get global cursor info using GetCursorInfo

I was not able to call GetCursorInfo method in the "user32" lib in VBCODE. Can the expert please show how this method can be implemented in a vb project
Thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shiju SasidharanSenior IT DeveloperCommented:

here is an example that uses GetCursorInfo
u can Download  Source code from this link

GetCursorInfo Function


The GetCursorInfo function retrieves information about the global cursor.


BOOL GetCursorInfo(          PCURSORINFO pci

[out] Pointer to a CURSORINFO structure that receives the information. Note that you must set CURSORINFO.cbSize to sizeof(CURSORINFO) before calling this function.
Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Function Information

Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 98, Windows  
Option Explicit

Private Type POINTAPI
    x As Long
    y As Long
End Type

    cbSize As Long
    flags As Long
    hCursor As Long
    ptScreenPos As POINTAPI
End Type

Private Declare Function GetCursorInfo Lib "user32.dll" (ByRef pci As PCURSORINFO) As Long
Private Sub Form_Load()
    typCI.cbSize = Len(typCI)
    If GetCursorInfo(typCI) <> 0 Then
        Debug.Print typCI.flags, typCI.hCursor, typCI.ptScreenPos.x & "," & typCI.ptScreenPos.y
    End If
End Sub
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

GetCursor will return a handle to the current cursor which you could then compare with a standard pointer to see which it is

GetCursorInfo returns a CURSORINFO struct which also includes if it is visible and its position.

To test which sort of pointer is being shown, you could use CopyImage to copy the selected cursor's image and CopyImage on system cursor (which you load using LoadCursor) then compare the bits of the image...

manish_tgAuthor Commented:
Thanks zzzzzooc . Your code was what I was requiring and it worked perfectly thanks.

Can you tell we what FLAGS and HCURSOR values means.

Actually I am using this information to find whether the mouse is being handled exclusively by some directX application or it is under the control of the window OS.

When i using any normal windows application, i get Flag=1 and HCURSOR=5254

but when I am using a Fulscreen Game Application that uses DirectX, i get Flag=0 and HCURSOR=0

Can i assume that whenever Flag and HCURSOR are zero, it means the mouse is being accessed exclusively by some directX application? Thanks for your code
The below is documentation on the structure.

"CURSORINFO Structure"

>> it means the mouse is being accessed exclusively by some directX application
As the link above mentions, Flag will be 0 if the cursor is hidden and hCursor will be 0 if the current cursor has no handle to a loaded cursor. Usually for DirectX games, they'll use their own cursors and hide the current one, so it's safe to use this method. You may want to test different games, though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manish_tgAuthor Commented:
Thanks buddy. A very useful comments and you have solved by big problem cheers!!!. This should work on NT and XP too....right, I have tested on 98.
"Minimum operating systems Windows 98, Windows NT 4.0 SP6"

Worked for me on Win2k Pro. Good luck. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.