Am I limited to the cursor numbers defined in Controls.pas under Delphi 7?

I am using Delphi 7 under Windows 7 to download files.

I want to change the cursor at boot time.

I set Screen.Cursor := crHourGlass; but looking at the constant cursor numbers in Controls.pas , I was wondering if there are other numbers that I can use to change the cursor in (I don't want to add a cursor to my resource file, I just want to use standard numbers that I can use without adding resources).

+1
delphi cursor delphi-7
source share
3 answers

produce other values ​​full cursors

Not. Numbers other than the built-in cursor constants will create a default cursor that is identical to TCursor(crDefault) (in other terms, HCURSOR(Screen.Cursors[crDefault]) ). These built-in cursors reside in application resources and are preloaded when VCL starts. To add a custom cursor, you HAVE to add a CURSOR resource, and then load it and add it to VCL.

 procedure TForm1.FormCreate(Sender: TObject); platform; const crCustom = 42; var Cursor: HCURSOR; begin Cursor := LoadCursor(HInstance, 'CUSTOM'); Win32Check(Cursor <> 0); // required error check Screen.Cursors[crCustom] := Cursor; { Done, newly added crCustom is ready to use } Self.Cursor := crCustom; // for example - lets show custom cursor { also, TScreen object will manage resource handle } { and perform cleanup for you, so DestroyCursor call is unnecessary } end; 

A more complex example with an indirect NB cursor construction : the example has many drawbacks: 1) DestroyIcon call is wrong 2) they noticed this if there was a validation error after all API calls

+2
source share

"Standard numbers" ( crHourglass , crDefault , etc.) are predefined cursors provided by Delphi VCL. You can define your own and load them into an application from a resource or from a file using the Windows API, but there are no unpublished unpublished TCursor definitions (or stray numbers) that mean anything. Trying to set Screen.Cursors [] to an unknown number without first loading the cursor will result in an array error from outside the minimum, and access violation at worst will cause the cursor to display by default (see TScreen.GetCursors in Forms.pas ).

Short Description: TCursorRec is defined in the VCL source as a record containing a pointer to the next record, index, and cursor pointer ( HCURSOR ). This is basically a single-linked list, and when you request a cursor by accessing the Cursors list, the VCL scans the list starting at the first element and steps over it sequentially until it finds the index corresponding to the one you requested (at this point it sets the cursor to this HCURSOR value) or determines that the index you requested is not assigned, in which case it returns the default cursor.

+1
source share

crHourGlass is of type TCursor, which is an integer alias (more or less). This is an index that you can use to position the cursor from stock.

You can add cursors using

 Screen.Cursors[Number] := ... needs to be a HCURSOR. 

So, if you have a new cursor handle, you can use it in Delphi.

Note that the constants crXXX - type TCursor are defined in the controls, and the Screen class is defined in Forms. So you can see the code for yourself.

0
source share

All Articles