RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TScreen.Cursors Property

Lists the cursors available to the application.

Pascal
property Cursors [Index: Integer]: HCURSOR;
C++
__property HCURSOR Cursors[int Index];

Use Cursor to access a particular cursor for use by the application or by a control within the application. TScreen includes several built-in cursors that are indexed by symbolic cursor constants. The image associated with the built-in cursors constants can be changed by setting the Cursors property. 

Custom cursors can be added to the Cursors property for use by the application or any of its controls. To add a custom cursor to an application: 

1Create the cursor resource using a resource editor. 

2Declare a cursor constant with a value that does not conflict with an existing cursor constant. 

3Use the Windows API function LoadCursor to obtain a handle to the new cursor.  

4Set the Cursors property, indexed by the newly declared cursor constant, to the handle obtained from LoadCursor.

Note: Don't call the Windows API function DestroyCursor when finished with a custom cursor; it is handled automatically.
 

C++ Examples: 

 

/*
This example shows how to add custom cursors to an
application.  The following code makes this cursor available
to the application via the constant crMyCursor, and sets it
as the global cursor to the application.
*/

#include <memory>       //for STL auto_ptr class

const crMyCursor = 5;

  void __fastcall TForm1::Button2Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> bmpMask(new Graphics::TBitmap);
  std::auto_ptr<Graphics::TBitmap> bmpColor(new Graphics::TBitmap);
  std::auto_ptr<TIconInfo> iconInfo(new TIconInfo);

  bmpMask->LoadFromFile("../SquareMask.bmp");
  bmpColor->LoadFromFile("../Square.bmp");

  iconInfo->fIcon = false;
  iconInfo->xHotspot = 15;
  iconInfo->yHotspot = 15;
  iconInfo->hbmMask = bmpMask->Handle;
  iconInfo->hbmColor = bmpColor->Handle;

  Screen->Cursors[crMyCursor] = CreateIconIndirect(iconInfo.get());

  Screen->Cursor = crMyCursor;
}

 

Delphi Examples: 

{
This example shows how to add custom cursors to an
application.  The following code makes this cursor available
to the application via the constant crMyCursor, and sets it
as the global cursor to the application.
} 
var
  bmpMask : TBitmap;
  bmpColor : TBitmap;
  iconInfo : TIconInfo;
const
  crMyCursor = 5;

procedure TForm1.Button2Click(Sender: TObject);
begin
  bmpMask := TBitmap.Create;
  bmpColor := TBitmap.Create;

  bmpMask.LoadFromFile('SquareMask.bmp');
  bmpColor.LoadFromFile('Square.bmp');

  with iconInfo do
  begin
    fIcon := false;
    xHotspot := 15;
    yHotspot := 15;
    hbmMask := bmpMask.Handle;
    hbmColor := bmpColor.Handle;
  end;

  Screen.Cursors[crMyCursor] := CreateIconIndirect(iconInfo);
  
  Screen.Cursor := crMyCursor;

  bmpMask.Free;
  bmpColor.Free;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DestroyIcon(Screen.Cursors[crMyCursor]);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!