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.
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:
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))