I'm working with an application where one of the options which I have to develop is to change Windows 10 cursor size. In my case it its important to change cursor size for the whole windows, not only for a specific java application window. Currently I'm able to change size of specific cursor type by modifying Windows registry attributes under HKEY_CURRENT_USER → Control Panel → Cursors directory.
Unfortunately, I need to set cursor size bigger than 32x32px.
Somewhere I've found a solution where there was a possibility to cover existing mouse cursor by a bitmap and just follow the position of a cursor, but I don't know how to start with the implementation.
I searched on the Internet and I've found some applications that allow user to modify size of cursor for whole Windows 10—for example, this was CursorFX.
Do you know how to increase cursor size programmatically?
You can set any size cursor you want using the SetSystemCursor API. You are not limited to the SM_CXCURSOR/SM_CYCURSOR metrics (cf. GetSystemMetrics function)—those just tell you the system's default cursor size, which is typically 32×32 (or 48×48 on high-DPI systems). I know for a fact that this works as far back as Windows XP; I'm pretty sure it works further back than that.
The key lies in how you load the cursor resource. As you probably already know, you need an HCURSOR object to pass to SetSystemCursor. This is a handle-to-cursor, in Windows API speak. The obvious way to load a cursor is by calling the LoadCursor API function, but that is a very old function, introduced with 16-bit Windows and it is limited to loading cursors of size SM_CXCURSOR×SM_CYCURSOR. So you don't want that†; you want to call LoadImage, which as the documentation indicates is the modern replacement function. It takes an enumerated integer parameter indicating which type of image to load: IMAGE_BITMAP (0), IMAGE_ICON (1), IMAGE_CURSOR (2), or IMAGE_ENHMETAFILE (3). Obviously, IMAGE_CURSOR is what you want to use here.
You can either load from a cursor resource embedded into your application's binary (as a Win32 resource), or you can load from a *.CUR/*.ANI file from the disk. To do the latter, pass the LR_LOADFROMFILE flag to the LoadImage function.
I don't know Java, so I can't translate this to Java with whatever syntax is required there to make native Windows API calls, but here is the code in C:
// Load from a CUR file, at C:\LargeCursor.cur, with a size of 64x64 pixels
HCURSOR hCursor = (HCURSOR)LoadImage(NULL,
"C:\\LargeCursor.cur"),
IMAGE_CURSOR,
64, 64,
LR_DEFAULTCOLOR | LR_LOADFROMFILE);
assert(hCursor != NULL); // verify that load was successful
BOOL result = SetSystemCursor(hCursor, OCR_NORMAL);
assert(result != FALSE); // verify that the change was successful
// Load from an embedded resource, IDC_CURSOR, with a size of 64x64 pixels
HCURSOR hCursor = (HCURSOR)LoadImage(GetModuleHandle(NULL),
IDC_CURSOR),
IMAGE_CURSOR,
64, 64,
LR_DEFAULTCOLOR);
assert(hCursor != NULL); // verify that load was successful
BOOL result = SetSystemCursor(hCursor, OCR_NORMAL);
assert(result != FALSE); // verify that the change was successful
Note that the SetSystemCursor requires one of the OCR_* constants to identify which system cursor type to change. These aren't included by default when you include Windows.h; you have to define OEMRESOURCE before including Windows.h. I'm assuming, though, that with Java, you're just defining the constants yourself as enumerated values. In that case, they're all available in the MSDN documentation for SetSystemCursor. For example, OCR_NORMAL is 32512.
Notice, though, that what we're doing here is loading a new cursor (i.e., image) of the desired size, and then setting that. That works fine. What you can't easily do is just expand the size of the existing cursor glyph. To do that, you'd have to retrieve the current cursor glyph, draw it onto a bitmap, scale that bitmap to the desired size, convert that bitmap to an HCURSOR, and then set that HCURSOR using SetSystemCursor. And, naturally, the problem with that is Windows cursor glyphs are just bitmaps, so they're not infinitely scalable. You will start losing resolution quickly, so this is not recommended. If you need a large-size cursor, you will need to provide your own image.
By "CursorFX", I believe you're thinking of AniFX (by the same fellow, Attila Kovrig, who wrote IcoFX). This is a cursor image editor and would be a great way to create the *.CUR/*.ANI file(s) you need. But you could just as easily use some other piece of software designed for creating cursors; there are myriad to choose from.
__
† Not that you wanted that function with SetSystemCursor anyway, since SetSystemCursor destroys the specified cursor by calling DestroyCursor. You would need to do LoadCursor and then CopyCursor before calling SetSystemCursor. This is all spelled out in the documentation for SetSystemCursor, but as I said, you don't need to worry about this anymore because you just use LoadImage (without the LR_SHARED flag).
I trying to find a method in java which could tell me when the mouse cursor has entered the borders of a folder or file component. Can anybody refer me to a good document or help me on this?
Mouse events happen within the context of the Java application (not your desktop). I don't think this is possible.
The best you can do is check if the cursor has left your Java application. As user BackSlash mentioned,
you can use PointerInfo to get the pointer coordinates, but you cannot
know if it has entered something that isn't part of your java
application.
http://docs.oracle.com/javase/7/docs/api/java/awt/PointerInfo.html
An alternative option is:
Add an AWTEventListener for focus events. As long as your app has
focus before the button is clicked you'll receive a focus lost event.
Then query for the pointer position.
The limitation is that, of course, your app loses focus. So depending
on what you are ultimately trying to achieve this might not be useful.
Source: https://stackoverflow.com/a/2420208/2498729
Is there a built in cursor that will show the "arrow plus hourglass" mouse pointer that is used when windows is working in the background, yet still allowing you to click on things?
I know about WAIT_CURSOR, but I don't see anything like this. Do I need to make a custom cursor to get the hourglass-pointer combo?
I don't see a built-in cursor that does this. All the pre-defined cursors reside here:
http://download.oracle.com/javase/7/docs/api/java/awt/Cursor.html
as you may well know.
You will need to create a custom cursor or find someone who has already done this. Here's a website showing you how to build your own custom cursor:
http://blog.codebeach.com/2008/02/using-custom-cursors-in-java.html
Goodluck
Is it possible to get a reference to Swing "no Drag "Cursor ,since it is OS Specific, or maybe override it
I think you might be looking for the DragSource class which has bunch of predefined cursors.
I would look into java.awt.Toolkit::createCustomCursor if you want a cursor that is not predefined in java.awt.Cursor
public Cursor createCustomCursor(Image cursor,
Point hotSpot,
String name);
From the Java 6 Documentation:
Creates a new custom cursor object. If the image to display is invalid, the cursor will be hidden (made completely transparent), and the hotspot will be set to (0, 0).
Note that multi-frame images are invalid and may cause this method to hang.
Is it possible to make Java program that will determine the absolute position (x,y on screen) of blinking keyboard cursor? That cursor can be in any text editor.
Not easily, since the position of a cursor on a screen of a program is merely a data point inside that program and rendering that cursor is a method running in the program. (I'm reading your question to mean that the program/editor in question is a wholly separate process from your Java program, right?)
You can theoretically do it if:
The program explicitly exports via some API calls the cursor location
You capture the actual screengrabs of that program very fast, analyze the image difference, and deduce cursor location from appearing/disappearing rectangle or short line in case the screen of the program didn't change save for cursor blink.
If you need relative (e.g. in # of chars instead of # of pixels) location in an editor, then somehow use edge recognition to detect editor size, some advanced image processing magic to deduce font size, and compute character-based offsets.
If the editor is using standard OS (e.g. Windows) APIs to draw both editing window AND the cursor, it might theoretically be plausible to hook into the system to intercept those calls - i don't posess nearly the amount of knowledge of what those APIs might be or if such even exist, how possible it is to intercept them, and whether Java programs are able to do that even if it's possible theoretically.
The question here is not whatever is possible or not, the question is for what purpose should i want to do this? Frankly, i don't see any reason, and i am sick of annoying mini-apps who act like spyware. Are u trying to duplicate the existent app into another form of mass terror?
I beg your pardon if u find my comment offensive, but this is my answer. Another question : why?