Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Display Animated Cursors stored in Resources

0.00/5 (No votes)
14 Dec 1999 1  
Demonstrates how to use an animated gif stored in your resource file as an animated cursor
  • Download demo project - 21 Kb
  • Download source files - 1 Kb
  • This article describes how you can display an animated cursor that is created from an animated gif and stored in your applications resources.

    Before you can display it, you must import the animated gif into your resource file. You do this by declaring the animated gif file as a new user defined resource named "ANICURSOR" within your resource file.

    /////////////////////////////////////////////////////////////////////////////
    
    //
    
    // ANICURSORS
    
    //
    
    
    IDR_HORSE_CURSOR        ANICURSORS DISCARDABLE  "res\\horse.ani"
    

    You then use the following function which loads the gif and displays it as an animated cursor:

     
    //
    
    // LoadAnimatedCursor: Loads an animated gif from the resource as an cursor
    
    //
    
    HCURSOR LoadAniCursor(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 display the cursor, call SetCursor(LoadAniCursor(ID_ANIMATED_HORSE))

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here