Back


Loading cursors into your projects!


To add a cursor to your application you need to create a .res file with the cursors in it.

For this example I used  Borlands Image Editor program that comes with Delphi.
 
 

First open Image Editor.

Next go to File | New | Resource File (.res).

Right-click on the word Contents which is in the new .res file window (Currently Untitled.res) and then go to New and click on Cursor.

Double-click on the word Cursor1 and the image editor appears.

You can draw your own cursor or you can open a cursor file and select all, copy and then paste this into the .res cursor image space.

After you have your first cursor you can create a second cursor.

I named the cursors for this example:

  • CURONE
  • CURTWO
And then I saved the .res file as extras.res, this was saved into the same directory as the project example.

Below is all the code used in this example.

First we add these constants:

const crCurone = 1;
const crCurtwo = 2;

We must also add extras.res so that the .res is loaded.
Here is how we do it:

 {$R extras.res}

In the example code below we use Button2 to load and set the cursor to the first cursor, CURONE, and Button3 to load and set CURTWO.

Button1 is used to set the cursor back to the default cursor crDefault.

As you can see from the code you shouldn't have any problems trying out this example.
 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const crCurone = 1;
const crCurtwo = 2;

var Form1: TForm1;

implementation {$R *.DFM} {$R extras.res}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Screen.Cursor := crDefault;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Screen.Cursors[crCurone] := LoadCursor(hInstance, 'CURONE');
  Screen.Cursor := crCurone;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Screen.Cursors[crCurtwo] := LoadCursor(hInstance, 'CURTWO');
  Screen.Cursor := crCurtwo;
end;

end.
 


Back