In my app I have
Screen.Cursor := crHourGlass;
Application.ProcessMessages;
try
...
finally
Screen.Cursor := crDefault;
Application.ProcessMessages;
end;
But this simply isn't working as expected. It seems to immediately change back to crDefault when it is processing.
After some Googling I decided to try Windows.SetCursor() - but I've searched the MSDN and I can't find the list of cursor types.
Update I thought I found the solution (using SetSystemCursor(Screen.Cursors[crHourGlass], OCR_NORMAL);) but I can't seem to then change the cursor back to normal :(.
I think I have the solution:
Here is how to change the cursor for 'the whole desktop' - not just for your application:
SetSystemCursor(Screen.Cursors[crDefault], OCR_NORMAL);
But be warned: any other applications/windows that want to change cursors will do so - so this is only effective if your user doesn't mess around with other applications while YOUR application is busy. As an over-ride, you could temporarily change all your systems default cursors to the cursor you want - and change them all back after the process.
I am still disappointed at the MSDN for not providing its cursor types for SetCursor - but fortunately I didn't end up having to use it.
Update: This seems to be the right track, but I can't seem to change the cursor back after SetSystemCursor(Screen.Cursors[crHourGlass], OCR_NORMAL); If anybody's reading this, I would appreciate if you take a moment to provide me with some working code - that 1. Sets the System Cursor to an hourglass, and then back to an arrow.
edit: Sample code for reverting back to default cursor:
procedure TForm1.Button1Click(Sender: TObject);
var
cArrow, cHour: HCURSOR;
begin
cArrow := CopyImage(Screen.Cursors[crArrow], IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE);
cHour := CopyImage(Screen.Cursors[crHourGlass], IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE);
if (cArrow <> 0) and (cHour <> 0) and SetSystemCursor(cHour, OCR_NORMAL) then
try
// do processing
finally
SetSystemCursor(cArrow, OCR_NORMAL);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With