[Home]   [Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

 

Available Now

Search

Google
 

Search WWW             

Search delphiforfun.org

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Help support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

Google
 

Search WWW

Search delphiforfun.org

 

 

Someone asked for help the other day in loading animated cursors as a resource.  I had never used them, but I did find out how to do it, so thought I'd pass it along here.  

A previous Customized Cursors page here in Delphi Techniques introduced the concepts for embedding cursors in a resource file and extracting and using them in a program.   For animated cursors. the process is similar, except that there is no predefined resource type for animated cursors, so we'll create a "User defined" resource - I called mine ANICURSOR, but any name will do.   

Here's a summary of the procedure:

  1. Get your cursors.

  2. Build an RC file used as input to the Resource Compiler.  Each line contains the Resource Name, the Resource Type and the Filename where the resource is located.  Here's my MyAniCursors.RC file for the demo:

    GLOBE ANICURSOR Globe.ani
    COFFEE ANICURSOR Coffee.ani

  3. Build a .bat file to invoke the Resource Compiler.  The demo  MakeRes.bat file contains this line: 

    brcc32.exe MYAniCurors.RC

    When run, the compile generates a file named MyAniCursors.RES

  4. Include the .res file from Step 3 in the program.  I inserted the line 

    {$R MyAniCursors.res} 

     immediately after the {$R *.res} line in  U_AniResDemo.pas   in AniResDemo program. 

  5. Define constants for the cursors.  Mine are:

     const

        AniGlobe = 1;
        AniCoffee= 2;

     

  6. At FormCreate time, load the resource into a cursor.  Here is the primary difference for animated cursors, there is no procedure to directly load an animated cursor resource into the Cursors array.  So we must create a temporary file, save the animated cursor to it, load the file as a cursor, and delete the file.   See  U_AniResDemo.pas for the code.

  7. Finally, when you want to use the cursor,  just assign it as you would any other cursor, e.g.

    procedure TForm1.GlobeBtnClick(Sender: TObject);
        begin
            Cursor := AniGlobe;
        end;

Browse/Download Programs 

  • I've included source for two demo programs: 

    • AniFileDemo loads animated cursors from .ani cursor files.

    • AniResDemo loads animated cursors from MyAniCursors.res resource file as described above. 

  • Download source

Caution:   Unlike mountain climbing or ice cream for breakfast, "because you can" is not a valid reason to inflict gratuitous animations on the user.   

Modified: February 01, 2007


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2008, Gary Darby    All rights reserved.