Search code examples
c++windowsmousegdi

Draw mouse pointer icon?


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?


Solution

  • 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!