ansijiu

开发过程中发现需要用到改变鼠标样式(就是光标的样子),但是在网上找了很多资料,都是介绍在程序中使用,我需要的效果时在系统级使用。现在找到了,分享给大家。

 

 1         [DllImport("user32")]
 2         private static extern IntPtr LoadCursorFromFile(string fileName);
 3 
 4         [DllImport("User32.DLL")]
 5         public static extern bool SetSystemCursor(IntPtr hcur, uint id);
 6         public const uint OCR_NORMAL = 32512;
 7 
 8         [DllImport("User32.DLL")]
 9         public static extern bool SystemParametersInfo(uint uiAction, uint uiParam,IntPtr pvParam, uint fWinIni);
10 
11         public const uint SPI_SETCURSORS = 87;
12         public const uint SPIF_SENDWININICHANGE = 2;
13 
14         private void button_Click(object sender, RoutedEventArgs e)
15         {
16             //设置
17             IntPtr iP = LoadCursorFromFile(@"D:\My Files\图片\cursor.cur");
18             SetSystemCursor(iP, OCR_NORMAL);
19         }
20 
21         private void button1_Click(object sender, RoutedEventArgs e)
22         {
23             //恢复
24             SystemParametersInfo(SPI_SETCURSORS, 0, IntPtr.Zero, SPIF_SENDWININICHANGE);
25         }

 

分类:

技术点:

相关文章:

  • 2021-12-06
  • 2021-10-06
  • 2022-01-17
  • 2022-12-23
  • 2021-08-02
  • 2021-04-29
  • 2022-02-10
猜你喜欢
  • 2021-12-20
  • 2021-12-26
  • 2021-12-12
  • 2021-12-26
  • 2021-08-25
相关资源
相似解决方案