Using custom cursors (Views: 100)


How can I use custom cursors in my application?


To use custom cursors in your application you have to follow these steps:

1. Create the cursors and save them in a resource file. You can use the Image Editor that comes with Delphi for this purpose.

2. In the interface section of any unit of your project declare the constants to refer to your cursors in code. This is not required,    but it will improve the readability of your code, so it is higly recommended.

These constans must be possitive integers (0 and negative values are reserved for the standard cursors). For example:

  crFinger = 1;
  crPower = 2;

3. In the initialization section of this unit, or anywhere in your    project before you attempt to use your cursors, you have to load    the cursors from the resource file. For example:

{$R Cursors.res}
Screen.Cursors[crFinger] := LoadCursor(hInstance, 'FINGER');
Screen.Cursors[crPower] := LoadCursor(hInstance, 'POWER');

Here we assumed "Cursors.res" is the resource file where you saved    your cursors, and that FINGER and POWER are the names you saved    them under.

This is it. You can use these cursors in the same you would use the predefined cursors. For example:

procedure TForm1.FormCreate(Sender: TObject);
  Self.Cursor := crPower;
  Label1.Cursor := crFinger;

You can also set the Cursor and DragCursor properties of a component at design-time using the Object Inspector. The only drawback is that you can't use the constants names (for example crFinger and crPower) but their values (for example 1 and 2).

Copyright (c) 2001 Ernesto De Spirito
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

<< Back to main page