I want hide hand cursor from a Java desktop application that have a virtual keyboard where when mouse cursor is over each number, the cursor is changed to hand style.
I tried the followiing code using a transparent image (.cur file) as resource, but not worked to hide hand cursor.
Is possible hide hand cursor to this kind of element?
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
{$R 'mycursor.res'}
uses
Windows,
Messages,
SysUtils;
procedure MyShowCursor(Show: Boolean);
const
OCR_HELP = 32651;
var
xCursor: HCURSOR;
begin
if Show then
SystemParametersInfo(SPI_SETCURSORS, 0, 0, WM_SETTINGCHANGE or SPIF_UPDATEINIFILE)
else
begin
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_NORMAL);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_APPSTARTING);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_CROSS);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_HAND);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_HELP);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_IBEAM);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_NO);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_SIZEALL);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_SIZENESW);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_SIZENS);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_SIZENWSE);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_SIZEWE);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_UP);
xCursor := LoadCursor(HInstance, 'XCURSOR');
SetSystemCursor(xCursor, OCR_WAIT);
end;
end;
begin
try
MyShowCursor(False);
Sleep(15000);
MyShowCursor(True);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
From this reference, i understood that:
java code has its own management to some cursor's, and then in this case "hand" cursor is different of system and have a special behavior.
Edition:
Extracted from reference for convenience:
Here is my problem: I have a frame with a button in it. On this button, I make a
bouton.setCursor(new Cursor(Cursor.HAND_CURSOR));
when I start my program, the frame has the default cursor (the arrow) and the button in the "hand". On this frame I have a second button on which I have a listener. When I click on this button I call on a library which modifies the Windows cursors by calling the method:
BOOL WINAPI SetSystemCursor(
_In_ HCURSOR hcur,
_In_ DWORD id
);
//OCR_HAND = 32649
SetSystemCursor(chemin_de_mon_image, 32649);
//OCR_NORMAL = 32512
SetSystemCursor(chemin_de_mon_image, 32512 );
...
So after having clicked on button 2, I have all the cursors on my Windows which are changed to "my image", even the "hand" cursor on Google links for example. On my Java application, all the cursor are changed except the "hand". Java doesn't seem to use wintow's native cursor for the "hand", but why? If anyone has a solution to this problem I am interested in it, or an explanation.
try to put something other than the hand to see if this new cursor is redrawn or not with your method. The idea is to see if it is the hand that has a special behavior or the cursor used for the bouron .....
Thank you for your ludomacho response. I tried with the other cursors (wait, cross, ...) and I manage to change the cursor, only the "main" cursor does not work. When we take a good look at the "main" cursor it looks like it is different from the "main" cursor of the system (no shading), while for the other cursors they are the same. There is a very simple test to do to find out, just create a frame with 2 buttons. On the first one we do: button1.setCursor (new Cursor (Cursor.WAIT_CURSOR)); On the second one we do: button2.setCursor (new Cursor (Cursor.HAND_CURSOR)); Then we go to the Windows settings and we modify the appearance of the "hand" and "wait" cursor. Only the "wait" cursor will have been modified in the application.
The java code has its own management of the "main" cursor. To display the "main" cursor of the system (Windows Seven) you must modify the JRE and recompile it.