tags:

views:

366

answers:

1

How do you get the cursor type (hand, arrow, etc.) as enum (int) or Bitmap?

It should work globally, not only in the application's forms. I believe, Cursor.Current doesn't work if the mouse is outside of the application scope. I've looked at interopping Win32 GetCursorInfo() and GetCursor(), but don't understand how to use these to get the cursor type.

Thanks in advance.

A: 

If you can get the cursor bitmap, you can easily compare it with the standard bitmap for known system cursors. Simply check and see if they are the same dimensions - if they are, loop through the pixels and quit if any aren't equal. If you're able to loop through the entire bitmap, and all pixels match, then you know you have two cursors that are identical. Cursors are usually something like 24x24 so this should not be a huge performance issue - there might be a faster way to compare bitmap equality but that's another question you might ask.

There are some possible problems with this approach:

  • Cursor might be a custom cursor (think Photoshop's tools)
  • Cursor might be animated
  • Cursor might change rapidly as it moves about the screen

As an addendum, what are you hoping to accomplish with this process? It's very likely that there's a completely orthogonal approach you might not have considered.

Charlie Salts