EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.


C# change the system default mouse pointer

You may find a bunch of tutorials that tell you how to do it, but the effect they achieve will only take effect when you place your mouse on the window, and my method will show you how to take effect globally.

First, you need to prepare a .cur file, this is a file specifically used to show the mouse style. You can find a lot on the Internet.

Then, add these codes:

public static extern IntPtr LoadCursorFromFile(string fileName);

public static extern bool SetSystemCursor(IntPtr hcur, uint id);
public const uint OCR_NORMAL = 32512;

public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
public const uint SPI_SETCURSORS = 87;
public const uint SPIF_SENDWININICHANGE = 2;

If you are not a beginner, you should know where these codes should be added. I don't think I need to explain.

I am just telling you how to achieve your goal. As for the details, you need to explore it yourself.

Then, call this method:

//load .cur file and change system default cursor
IntPtr hcur_click = LoadCursorFromFile("01.cur");
SetSystemCursor(hcur_click, OCR_NORMAL);

If you want to restore to the original state:

//Restore to the system default cursor


[1] https://bbs.csdn.net/topics/350040718

[2] https://www.cnblogs.com/liang123/p/6325908.html

This article was last edited at 2020-11-25 16:01:14

* *