SPI_SETCURSORS := 0x57
result := DllCall("SystemParametersInfo", "UInt", SPI_SETCURSORS, "UInt", 0, "UInt", 0, "UInt", '0')
MsgBox Error Level: %ErrorLevel% `nLast error: %A_LastError%`nresult: %result%
翻译成 C#:
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
const int SPI_SETCURSORS = 0x0057;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDCHANGE = 0x02;
调用它:
SystemParametersInfo(SPI_SETCURSORS, 0, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
更改为默认的Windows光标
现在是棘手的部分。如果您查看HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Control Panel\Schemes,您会注意到“Windows Default”被定义为“,,,,,,,,,,,,,”或者换句话说没有指向实际光标的指针!
现在该怎么办?不用担心。您所要做的就是将不同的光标类型设置为空字符串,然后像往常一样进行SystemParametersInfo调用。事实上,您可以在任何方案中将任何光标类型设置为空字符串,并且Windows将其默认为“Windows Default”方案中的等效光标。
REF:
https://thebitguru.com/articles/programmatically-changing-windows-mouse-cursors/3
Cursor.cur
文件以加载自定义光标。在 MouseLeave
事件中将表单的默认光标设置为默认值。public static Cursor ActuallyLoadCursor(String path)
{
return new Cursor(LoadCursorFromFile(path));
}
[DllImport("user32.dll")]
private static extern IntPtr LoadCursorFromFile(string fileName);
Button btn = new Button();
btn.MouseLeave += Btn_MouseLeave;
btn.Cursor = ActuallyLoadCursor("Cursor.cur");
private static void Btn_MouseLeave(object sender, EventArgs e)
{
this.Cursor = Cursors.Default;
}