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

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds