Click here to Skip to main content
15,867,330 members
Articles / Multimedia / GDI

Display Animated Cursors stored in Resources

Rate me:
Please Sign up or sign in to vote.
4.33/5 (3 votes)
14 Dec 1999 125.9K   2.6K   18   17
Demonstrates how to use an animated gif stored in your resource file as an animated cursor

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.

C++
/////////////////////////////////////////////////////////////////////////////
//
// 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:

C++
//
// 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.


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHere is how to Prevent the Cursor Disappearing Pin
davesmills21-May-15 0:35
davesmills21-May-15 0:35 
QuestionCannot work in Multiple Documents dialog Pin
kevanphua27-May-07 16:40
kevanphua27-May-07 16:40 
QuestionLoading 256-color animated cursors? Pin
Bartosz Bien7-Jun-06 10:33
Bartosz Bien7-Jun-06 10:33 
QuestionWhere to put LoadAniCursor()? Pin
lasombra28-Nov-04 22:31
lasombra28-Nov-04 22:31 
QuestionMSFlexgrid distribute? Pin
José Luis Sogorb28-Nov-04 7:22
José Luis Sogorb28-Nov-04 7:22 
GeneralUne autre facon, qui marche sur toutes plateformes: Pin
joshu22-Mar-03 17:36
joshu22-Mar-03 17:36 
GeneralResource leak! Pin
19-Mar-02 21:01
suss19-Mar-02 21:01 
GeneralA different way... Pin
Sibilant1-Mar-02 15:44
Sibilant1-Mar-02 15:44 
GeneralCURSOR DISAPPEARS Pin
Sibilant1-Mar-02 7:55
Sibilant1-Mar-02 7:55 
GeneralHave a solution for Win9X Here Pin
figmo24-Oct-01 13:35
figmo24-Oct-01 13:35 
GeneralRe: Have a solution for Win9X Here Pin
24-Oct-01 14:15
suss24-Oct-01 14:15 
GeneralRe: Have a solution for Win9X Here Pin
5-Nov-01 22:45
suss5-Nov-01 22:45 
GeneralUsing the example code Pin
26-Nov-00 23:53
suss26-Nov-00 23:53 
GeneralCreateIconFromResource() Always failed !!! Pin
Member 192921-Sep-00 23:10
Member 192921-Sep-00 23:10 
GeneralWorking great but.... Pin
kishk9110-Mar-00 9:21
kishk9110-Mar-00 9:21 
GeneralWorking great but.... Pin
kishk9110-Mar-00 9:21
kishk9110-Mar-00 9:21 
GeneralNot a GIF, but a simple ANI cursor! Pin
PPEscher22-Jan-00 13:14
sussPPEscher22-Jan-00 13:14 

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

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