hot to create cursors in c#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

i want to create a cursor in c#. Basically i want to draw a rectangle whose
width changes dynamically. So i thought of creating a bitmap object of given
width and height and then get a graphics obejct out of it and fill the
rectangle with a specific color. So i will get an image object but i want to
create a cursor object from this one. Is there anyway to accomplish this?

thanks
vinod
 
You must use InteropServices for the GDI32 functions.

You may use the Windows function CreateIconIndirect
to create your cursor.

You must create 2 bitmaps. An AND bitmap and
a XOR bitmap.

Creating the AND bitmap is easy. It is a monochrome
bitmap where you set the color for those areas
that are transparent in your source bitmap and clear
the color for those areas that are not transparent.

The XOR bitmap is more work Once you have
drawn your source bitmap and decided what color
you want to be transparent, you create a bitmap
to represent the XOR mask. Copy your source
bitmap to the XOR bitmap using BitBlt(SRCCOPY).
Then you take your AND mask bitmap and copy it
to your XOR mask bitmap using BitBlt(SRCINVERT)
and finally take your AND mask bitmap and copy it
to your XOR mask bitmap using BitBlt(SRCAND).

You now have 2 bitmaps in the requisite format
necessary to create you cursor. Use CreatIconIndirect
specifying the HBITMAPS that you created.

The following articles will provide background:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnargdi/html/msdn_transblt.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;318876
 
Back
Top