[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2985
  • Last Modified:

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
0
manish_tg
Asked:
manish_tg
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Shiju SasidharanCommented:
hi

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

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=50310&lngWId=1

;-)
Shiju
0
 
Mikal613Commented:
GetCursorInfo Function

--------------------------------------------------------------------------------

The GetCursorInfo function retrieves information about the global cursor.

Syntax

BOOL GetCursorInfo(          PCURSORINFO pci
);
Parameters

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  
0
 
zzzzzoocCommented:
Form1:
------------------------
Option Explicit

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type PCURSORINFO
    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()
    Dim typCI As PCURSORINFO
    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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mikal613Commented:
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...

0
 
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
0
 
zzzzzoocCommented:
The below is documentation on the structure.

"CURSORINFO Structure"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorstructures/cursorinfo.asp

>> 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.
0
 
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.
0
 
zzzzzoocCommented:
"Minimum operating systems Windows 98, Windows NT 4.0 SP6"

Worked for me on Win2k Pro. Good luck. :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now