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();
 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


Download demo project – 40 Kb

More by Author

Must Read