如何从 Java 按钮隐藏手形光标?

How hide hand cursor from Java buttons?

我想在 Java 具有虚拟键盘的桌面应用程序中隐藏 hand 光标,当鼠标光标悬停在每个数字上时,光标变为 风格.

我尝试使用透明图像(.cur 文件)作为资源使用以下代码,但无法隐藏 hand 光标。

是否可以将光标隐藏到这种元素?

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.

参考this,我了解到:

java 代码对某些游标有自己的管理,然后在这种情况下,“手”游标与系统不同并且具有特殊行为。


版次:

为方便起见从参考中提取:

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.