5
votes

I am coding little fun gadget. I want to be able to draw second (or more) mouse pointer icons at different location than the original mouse but to move it according to move of original mouse.

I know how to track movement of the mouse but I dunno how to draw/redraw mouse pointer; can anyone help?

2

2 Answers

7
votes

You can use the following code:

CURSORINFO ci;
ci.cbSize = sizeof(CURSORINFO);
GetCursorInfo(&ci);

Next you can draw a cursor by calling:

DrawIcon(ContextDC, YourXPosition, YourYPosition, ci.hCursor);

If you need additional information about the cursor, like hotspot for example, check the ICONINFO structure:

ICONINFO ii;
GetIconInfo(ci.hCursor, &ii);
1
votes

This could be done like:

  1. grab the current mouse cursor from your application, using LoadCursor(). Just specify NULL, and the cursor you want. Or just load a bitmap for the cursor. Now, you have a bitmap.

  2. Next step is to get the Device context of your Desktop: GetWindowDC(NULL). This will give you the opportunity to draw on the desktop anywhere.

  3. There is a huge chance that you will need to apply CreateCompatibleBitmap() to the Image at #1 with the DC obtained at #2.

  4. Now, use some BitBlt() to copy bits OUT from the DC obtained at #2 into a save image (YOU will need to create these) from the position you want to put your cursor.

Now, put the image obtained at #3 onto the DC of the Desktop obtained at #2 at the position you want.

When the user moved the mouse restore the image on the desktop with the saved data at #4. Release all the stuff you don't need (yes, this is mandatory).

And restart from #1.

These two more links might help:

Bitmaps, Device Contexts and BitBlt

Capturing an Image

Good luck!