Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:04:18+00:00 2026-06-08T20:04:18+00:00

I want to load an animated cursor stored in .ani format, which is described

  • 0

I want to load an animated cursor stored in .ani format, which is described to be a RIFF archive/container, from memory without writing the memory to a temporary file. Thus far I am able to parse the .ani file structure and load the individual frames as a normal icon with the aid of CreateIconFromResourceEx LookupIconIdFromDirectoryEx

One of the problems that proofs difficult is the actual composition of these frames and the animation data (jiffy-rate etc) as there appears to be no entries in the Windows API to do so. Documentation or written knowledge over the subject seems to be limited to loading non-animated icons/cursors from memory.

Similar questions such as ‘Load an embedded animated Cursor from the Resource’ express the desire to load an animated cursor from an embeddable resource. However i am not able to reproduce a workable solution from that either. Partly because the resource compiler in visual studio 2008 & 2010 doesn’t support .ani (only ico and cur) files and therefor embedding it simply results in a 1:1 copy of the bytes as they were in the original file as opposed to .cur and .ico files which get decomposed into multiple resources. The subsequent call to CreateIconFromResource as shown in both answers does not work because the data it expects is the icon/cursor data of a single directive in a icon archive and not a RIFF-based file structure.

To summarize I’m interested in any information regarding the structures of animated cursors (in memory) or otherwise relevant pointers that could assist me in pursuing my goal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:04:19+00:00Added an answer on June 8, 2026 at 8:04 pm

    After re-evaluating loading an animated cursor from an embeddable resource as pointed out by mfc I have found a solution that allows me to load the cursors from an arbitrary memory address.

    Data from an embeddable resource and data read from a file into memory are exactly identical. Therefor it suggests that CreateIconFromResource should work on normal regular memory as well. However there is one fundamental difference. Memory of the embeddable resources reside in special sections in the executable which are often padded to the nearest 4096-byte boundary. Memory allocated at runtime contains garbage values.

    Now the solution that I found working exploits this by simply allocating a guard-band of zero-filled bytes. In my own test cases I have found that 8 is the minimum which also happens to be the size of a chunk in the riff container. Coincidence? What i suspect is that this is a bug and the algorithm happens to work for embeddable resources due to it’s alignment restrictions within the dll/executable.

    const int guardbandSize = 8;
    FILE* fs = fopen("action.ani", "rb");
    fseek(fs, 0,SEEK_END); int dwSize = ftell(fs); fseek(fs, 0,SEEK_SET);   
    char* memory = new char[dwSize + guardbandSize];
    fread(memory, 1, dwSize, fs); memset(memory + dwSize, 0, guardbandSize);
    fclose(fs);
    cursor = (HCURSOR)CreateIconFromResource((PBYTE)memory,dwSize,FALSE,0x00030000);        
    delete memory;
    

    Here is an overview of various ways to load an animated cursors.

    #include <Windows.h>
    #include <stdio.h>
    #include "resource2.h"
    
    void* hWnd;
    bool  visible = true;
    bool  running = true;
    LRESULT CALLBACK WndProcInternal(   HWND hWnd, UINT uMsg, WPARAM    wParam, LPARAM  lParam) ;
    HCURSOR cursor = 0;
    
    void main()
    {   
        //Setup configuration
        const int Width  = 640, Height = 480;
        const int Method = 4;
    
        //Setup window class 
        WNDCLASS wcd;
        wcd.style           = CS_PARENTDC | CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 
        wcd.lpfnWndProc     = (WNDPROC)WndProcInternal;         
        wcd.cbClsExtra      = 0;                                
        wcd.cbWndExtra      = 0;                                
        wcd.hInstance       = GetModuleHandle(NULL);            
        wcd.hIcon           = LoadIcon(NULL, IDI_WINLOGO);      
        wcd.hCursor         = LoadCursor(NULL, IDC_ARROW);      
        wcd.hbrBackground   = (HBRUSH)COLOR_BACKGROUND;                             
        wcd.lpszMenuName    = NULL;                             
        wcd.lpszClassName   = TEXT("AnimatedIcon");             
    
        //Register the window class
        if(!RegisterClass(&wcd)) 
        {
            MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"),MB_ICONEXCLAMATION | MB_OK);
            FatalExit(-1);
        }
    
        //Create a window
        if (!(hWnd=CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("AnimatedIcon"), TEXT("AnimatedIcon"), 
            WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_SYSMENU,
            0, 0, Width, Height, NULL, NULL, NULL, NULL)))                          
        {
            MessageBoxA(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            FatalExit(-1);
        }   
    
        if( Method == 1 )
        {
            //Method 1: Load cursor directly from a file
            cursor = LoadCursorFromFileA("action.ani");
        }
        if( Method == 2 )
        {
            //Method 2: Load cursor from an resource section in the executable.
            cursor = LoadCursor(0, MAKEINTRESOURCE(IDR_ANICURSORS1));
        }
        if( Method == 3 )
        {
            //Method 3: Manually locate the resource section in the executable & create the cursor from the memory.
            HINSTANCE hInst=GetModuleHandle(0);
            HRSRC hRes=FindResourceA(hInst,MAKEINTRESOURCEA(IDR_ANICURSORS1),"ANICURSORS");
            DWORD dwSize=SizeofResource(hInst,hRes);
            HGLOBAL hGlob=LoadResource(hInst,hRes);
            LPBYTE pBytes=(LPBYTE)LockResource(hGlob);
            cursor = (HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);
        }
        if( Method == 4 )
        {
            //Method 4: Load the cursor from a file into memory & create the cursor from the memory.
            const int guardbandSize = 8;
            FILE* fs = fopen("action.ani", "rb");
            fseek(fs, 0,SEEK_END); int dwSize = ftell(fs); fseek(fs, 0,SEEK_SET);   
            char* memory = new char[dwSize + guardbandSize];
            fread(memory, 1, dwSize, fs); memset(memory + dwSize, 0, guardbandSize);
            fclose(fs);
            cursor = (HCURSOR)CreateIconFromResource((PBYTE)memory,dwSize,FALSE,0x00030000);        
            delete memory;
        }
    
        //Set the cursor for the window and display it.
        SetClassLong((HWND)hWnd, GCL_HCURSOR, (LONG)cursor);        
        while (running)     
        {
            MSG wmsg;
            if (PeekMessage(&wmsg, (HWND)hWnd, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&wmsg);
                DispatchMessage(&wmsg);
            }           
        }   
    }
    
    LRESULT CALLBACK WndProcInternal(   HWND hWnd, UINT uMsg, WPARAM    wParam, LPARAM  lParam) 
    {
        if( uMsg == WM_DESTROY )
        {
            PostQuitMessage(1); 
            running = false;
        }
    
        return (long)DefWindowProc((HWND)hWnd,uMsg,(WPARAM)wParam,(LPARAM)lParam);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm retrieving files like so (from the Internet Archive): <files> <file name=Checkmate-theHumanTouch.gif source=derivative> <format>Animated
I used - (BOOL)presentPreviewAnimated:(BOOL)animated; to load the doc, then I want to take the
I want to load data from MySql database to a HTTP form When I
I want to load PNG-file from resources. There is a roughly MFC-way (with CResourceStream
I want to load a palette from a bitmap file I have created. The
I used to show a splash screen which in background load some data from
I want to use UIImagePickerController to load photos from the photolibrary of the IPad
I have 3 UIImageViews for which I want to load an image. For 1
I have a situation where I want to return an animated gif from an
at first sorry my bad English I want load model in my plugin controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.