Click here to Skip to main content
Click here to Skip to main content
Go to top

Display Animated Cursors stored in Resources

, 14 Dec 1999
Rate this:
Please Sign up or sign in to vote.
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
  • <!-- Article Starts -->

    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

    Share

    About the Author

    Bernd Wißler

    Germany Germany
    No Biography provided

    Comments and Discussions

     
    GeneralCreateIconFromResource() Always failed !!! PinsussHomles Chen21-Sep-00 23:10 
    GeneralWorking great but.... PinsussKishk9110-Mar-00 9:21 
    GeneralWorking great but.... PinsussKishk9110-Mar-00 9:21 
    GeneralNot a GIF, but a simple ANI cursor! PinsussPPEscher22-Jan-00 13:14 
    Why animated gifs? You use simple animated cursors

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web02 | 2.8.140921.1 | Last Updated 15 Dec 1999
    Article Copyright 1999 by Bernd Wißler
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid