RAD Studio VCL Reference
|
Lists the cursors available to the application.
property Cursors [Index: Integer]: HCURSOR;
__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.
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. */ Graphics::TBitmap *bmpMask, *bmpColor; TIconInfo *iconInfo; const crMyCursor = 5; void __fastcall TForm1::Button2Click(TObject *Sender) { bmpMask = new Graphics::TBitmap(); bmpColor = new Graphics::TBitmap(); 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); Screen->Cursor = crMyCursor; delete bmpMask; delete bmpColor; delete iconInfo; }
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) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|