If all you need to do is display a preview, then DrawIconEx
is all you need.
You can create a background thread to step through the frames
every so many milliseconds. You have to be careful not to block the
user interface during the playback. The Net Framework has an Animate
class that is designed for animated .gifs which you could use to model
your animation class.
As far as creating in memory .ani cursors, the cursor is already in memory.
If the cursor was not animated, using GetIconInfo would give you the
masked bitmaps. Additionally, the HCURSOR is a global memory
handle to the actual resource. Per the documentation, using LockResource
on this handle would give you a CURSORSHAPE header followed by
the masked bitmaps. However, I could not get this to work.
Perhaps I needed to follow the "How to" in this MSDN article:
http://msdn.microsoft.com/msdnmag/issues/01/10/Cursor/default.aspx
This is a great article. It may solve your problem on how to get this
HCURSOR when it could be changed at any time.
I would not go over board. Simply use DrawIconEx as is to display
all of your cursors animated or not in a preview window. You could
create an Animated cursor class like the one in the .Net Framework
to do the job without blocking the user interface.
Post by dc2000Yes, I apologize I didn't state what I'm trying to do. I have a DLL module
that is a part of another program (that I don't have access to). My DLL gets
all the input from it. One of the fields is a cursor handle. What I need to
do in my DLL is to display that cursor in some sort of a preview window. It
works absolutely fine with regular cursors but when its an animated cursor
only first frame is displayed. Recently we got request from a customer to
display animation too as it confuses them in some way or another. So low and
behold I won't be able to get access to a resource where the animated cursor
was loaded from -- all I have is a handle, which to make matters worse could
be changed asyncronously in the main program, thus I have to make a copy of
it in my DLL.
Your previous post helped a lot, by the way, but there're still questions.
What I learned is that I can step through all the frames in the animated
cursor and create bitmaps of each frame using DrawIconEx and DIB sections.
What stays unclear though is how to create an animated cursor from memory.
Somehow CreateIconIndirect API does not support more than one frame. I'm
really stumped here. It looks like the only way around would be to save it on
disk as .ANI file and load it back using LoadCursorFromFile? Please help me
out here. I really don't want to use it as such way would put a huge overhead
on DLL.
Thank you very much for your constructive replies...
Dennis
Post by Michael Phillips, Jr.You never stated what your goal really is.
If you want to copy an animated cursor for your own
use, this is not the way to go.
Animated cursors (.ani) are in Microsoft RIFF format.
They can exist as a .ani file or as a resource in another
file.
They are usually loaded as a resource. The resource
can be located in a .dll or some other file.
If you know the file where the animated cursor is located,
you can use a program like resource hacker to copy
the resource from the dll file.
DrawIconEx allows you to step into each frame and
draw that cursor frame. It does not allow you to pull
out the timing for the animation of each frame.
Recreating the And and Xor bitmaps for each cursor
frame is not for the faint of heart and I don't recommend
it in this case.
Microsoft's MSDN web site has numerous articles on
icons, cursors and bitmaps along with sample code.
Post by dc2000Thank you Michael!
I'm not quite familiar with DIB sections and all that DC drawing. Can you
clue me in to some sample code please?
Post by dc2000HCURSOR hNewCursor = (HCURSOR)CopyImage(hCursor, IMAGE_CURSOR, 0, 0, 0);
HCURSOR hNewCursor = (HCURSOR)CopyImage(hCursor, IMAGE_CURSOR, 0, 0,
LR_COPYFROMRESOURCE);
The above assumes that you loaded the original animated cursor from
your
own
file or resource.
If you did not load the animated cursor yourself, then you have to use
DrawIconEx to draw each frame
and then create the bitmaps from the device context using
CreateDIBSection.
Post by dc2000I'm trying to copy an animated cursor using CopyCursor (and now using
CopyImage) but somehow all I get is just one frame. Unfortunately I cannot
reload the cursor as all I have is just a handle.
HCURSOR hNewCursor = (HCURSOR)CopyImage(hCursor, IMAGE_CURSOR, 0, 0, 0);
Please, if anyone knows, what am I doing wrong?