作者:捷克先生2012_929 | 来源:互联网 | 2023-09-23 09:51
方法参考博客:https:gameinstitute.qq.comcommunitydetail118295usingSystem.Runtime.InteropS
方法参考博客:https://gameinstitute.qq.com/community/detail/118295
using System.Runtime.InteropServices;public class CursorTools
{[DllImport("User32.DLL")]public static extern IntPtr LoadCursorFromFile(string fileName);[DllImport("User32.DLL")]public static extern bool SetSystemCursor(IntPtr hcur, uint id);public const uint OCR_NORMAL = 32512;[DllImport("User32.DLL")]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;private static string CursorPath(string fileName){return Path.Combine(Application.streamingAssetsPath, "Cursors", fileName) + ".cur";}public static void Reset2NormalCursor(){SystemParametersInfo(SPI_SETCURSORS, 0, IntPtr.Zero, SPIF_SENDWININICHANGE);}public static void SetDragCursor(){IntPtr hcur_drag = LoadCursorFromFile(CursorPath("aero_move"));SetSystemCursor(hcur_drag, OCR_NORMAL);}
}
以拖拽功能为例,想拖拽的时候调用:
CursorTools.SetDragCursor();
用完记得把指针变回来:
CursorTools.Reset2NormalCursor();
C:\Windows\Cursors文件夹下面有很多Windows默认鼠标资源。