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: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds