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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds