Determine cursor size of currently selected theme

2019-09-06 20:07发布

问题:

I want to show a custom mouse cursor, in a size that matches the current settings (in the control panel) of the user.

Doing Cursor.Current.Size always returns 32x32 (as I guess they always are technically, though not visually), no matter what the control panel settings, which are correctly reflected by smaller or bigger cursor appearances.

So how do I figure out the size?

回答1:

For what I have found out, you have to get the Icon for the cursor (probably with some win32-API) and then using ICONINFO to find out the mask bitmap. After that you can check the pixels of the icon and count until you find the transparent color and that way find out the real size.

I have seen a couple of answers on other sites that point to this direction, but I cant find a complet solution, just fragments here and there..

This stackoverflow question have a good answer about the bitmap masks used by the cursor and from there maybe you can work your way to the solution.

C# - Capturing the Mouse cursor image

This question is old, I have seen this question on other sites from year 2003, so if you have success, then please put the answer here, many would be glad to se the solution to this question.