Displaying Animated Cursors from a Resource File

After I could not locate a method for displaying animated cursors from a resource, I found a way myself.

Essentially (with error checking removed), here's the code path.


HCURSOR LoadAnimatedCursor(UINT nID 
{
 HINSTANCE hInst=AfxGetInstanceHandle();
 HRSRC hRes=FindResource(hInst,MAKEINTRESOURCE(nID),"ANICURSORS");
 DWORD dwSize=SizeofResource(hInst,hRes);
 HGLOBAL hGlob=LoadResource(hInst,hRes);
 LPBYTE pBytes=(LPBYTE)LockResource(hGlob); 

 return (HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);
}
To import an .ANI file to the resource script:

  1. Insert->Resource->Import: Load the .ANI file
  2. Select the new resource into a user defined type named: ANICURSORS

Downloads

Download demo project - 40 Kb



Comments

  • The effect seems to be unavailable on Win32 application

    Posted by Legacy on 12/19/2003 12:00am

    Originally posted by: Grant

    What can I do to make it apply also to Win32 application
    not just on dialog? Thanx.

    Reply
  • 1 solution, 1 problem

    Posted by Legacy on 03/02/2002 12:00am

    Originally posted by: Sibilant

    if you manually edit your resource (.rc) file and add
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // 21
    //

    IDR_ANIMATED_CURSOR_NAME 21 DISCARDABLE "res\\AnimatedCursorName.ani"

    your project will now contain a resource of an animated cursor.(As long as you put it in your res file folder) I dont know what the 21 means but I saw it in another project. So you dont have to use:

    HCURSOR LoadAnimatedCursor(UINT nID
    {
    HINSTANCE hInst=AfxGetInstanceHandle();
    HRSRC hRes=FindResource(hInst,MAKEINTRESOURCE(nID),"ANICURSORS");
    DWORD dwSize=SizeofResource(hInst,hRes);
    HGLOBAL hGlob=LoadResource(hInst,hRes);
    LPBYTE pBytes=(LPBYTE)LockResource(hGlob);

    return (HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);
    }

    to load it as a resource.

    My problem is after a few seconds of using the animated cursor, it disappears. I'm running XP and VC++ 6 SP5.
    Any suggestions would be appreciated.

    Sibilant


    Reply
  • LOL, better solution then paying ...

    Posted by Legacy on 01/08/2002 12:00am

    Originally posted by: az

    man It is stupid to pay for a thing that works on one operationg system better then the one on which it isnt working ... it is better to get Windows NT from a friend then paying for such a thing...or get Windows XP, it is something like win98+winNT ... it is working on it:)

    Reply
  • This function returns NULL

    Posted by Legacy on 01/27/2000 12:00am

    Originally posted by: Dennis Woo

    Hi,

    I traced the codes and every lines looked fine except that the return value for the function is zero. Furthermore GetLastError() gave me zero.

    Any ideas why?

    Thanks.

    Regards

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds