Trying to change Windows mouse cursor icon from java through jni call

假如想象 提交于 2019-12-08 00:04:50

问题


In my java application, i m trying to change the mouse cursor with an argb 32bit bmp file with transparency.

I want to make a jni call to change it from Windows because changing the cursor in java gives me a really bad mouse cursor (all the transparency is either 0x00 or 0xFF)

At the moment i'm trying to use the function SetClassLong with as parameters:

  • the hWnd from java (i got it following that method http://download.oracle.com/javase/1.3/docs/guide/awt/AWT_Native_Interface.html )
  • GCL_HCURSOR
  • and a cursor made from a raw argb 32bit bmp buffer

That piece of code works in a sample win32 atl windows test program:

HBITMAP hBitmap = (HBITMAP)CreateBitmap(32, 32, 1, 32, pRawBmpData); 
BITMAP bmp;
::GetObject(hBitmap, sizeof(BITMAP), &bmp);

HBITMAP hMask = ::CreateCompatibleBitmap(::GetDC(NULL), bmp.bmWidth, bmp.bmHeight);

ICONINFO ii = {0};
ii.fIcon = FALSE;
ii.hbmColor = hBitmap;
ii.hbmMask = hMask;
ii.xHotspot = 0;
ii.yHotspot = 0;

HCURSOR cursor = ::CreateIconIndirect(&ii);

SetCursor(cursor);
SetClassLong(hWnd, GCL_HCURSOR, (DWORD)cursor);

But not in a dll called from java through jni

If somebody has a better approach or solution to this case, thanks

Cheers


回答1:


Was there something you wanted to do that was not possible with java.awt.Cursor?



来源:https://stackoverflow.com/questions/6220810/trying-to-change-windows-mouse-cursor-icon-from-java-through-jni-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!