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

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds