Animated Cursors in Resource

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 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.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

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

Search DelphiForFun.org only

 

 

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 

bullet

I've included source for two demo programs: 
bullet

AniFileDemo loads animated cursors from .ani cursor files.

bullet

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

bulletDownload 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: July 29, 2017

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