2017-01-18 38 views

回答

2

如果要更改默认的鼠标指针主题:

enter image description here

你可以改变它在注册表中:

有迹象表明,发挥作用的三个主要注册表项。

  1. 注册表项HKEY_CURRENT_USER \控制面板\游标含有活性用户光标

    1a)中的值的下方这是不同类型的游标
    1b)中的方案来源指定光标方案的类型目前正在使用。

    不同的值是:

    “0” - Windows默认
    “1” - 用户计划
    “2” - 系统方案

  2. 注册表项HKEY_CURRENT_USER \控制面板\游标包含用户定义的游标方案(即方案来源= 1)

  3. 注册表项HKEY_LOCAL_MACHINE \ SOFTWA RE \ Microsoft \ Windows \ CurrentVersion \ Control Panel \ Schemes包含系统光标方案(即,计划源= 2)

enter image description here

如果你已经改变了路径在HKCU \控制面板\游标游标类型之一,并意识到它没有做任何事情。你是对的,只是更新一个键 - 例如HKCU \ Control Panel \ Cursors \ Arrow是不够的。你必须告诉窗口加载新的光标。

这就是SystemParametersInfo这个呼叫的来源。试试这个,让我们继续并将HKCU \ Control Panel \ Cursors \ Arrow更改为C:\ WINDOWS \ Cursors \ appstar3.ani(假设你有这个图标),然后调用SystemParametersInfo。

在AutoHotkey的脚本:

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默认”方案中的游标类型。

REF:

https://thebitguru.com/articles/programmatically-changing-windows-mouse-cursors/3

https://social.msdn.microsoft.com/Forums/vstudio/en-US/977e2f40-3222-4e13-90ea-4e8d0cdf289c/faq-item-how-to-change-the-systems-cursor-using-visual-cnet?forum=csharpgeneral

+0

我试图改变这个值,但没有任何反应,它仍然是默认光标 –

+0

看到更新 - 你需要调用SystemParametersInfo –

+0

我在这里得到了一些错误:http://i.imgur.com/Agns2vV.png。 pvParam不接受空值。我尝试将pvParam值更改为“0”,它工作正常。非常感谢! –

1
using System; 
using System.ComponentModel; 
using System.Drawing; 
using System.Windows.Forms; 
using System.IO; 
using System.Runtime.InteropServices; 

namespace WindowsFormsApplication1 { 
    public partial class Form1 : Form { 
    public Form1() { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) { 
     Bitmap bmp = Properties.Resources.Image1; 
     bmp.MakeTransparent(Color.White); 
     IntPtr hIcon = bmp.GetHicon(); 
     Icon ico = Icon.FromHandle(hIcon); 
     Cursor cur = new Cursor(hIcon); 
     using (FileStream fs = new FileStream(@"c:\temp\test.cur", FileMode.Create, FileAccess.Write)) 
     ico.Save(fs); 
     cur.Dispose(); 
     ico.Dispose(); 
     DestroyIcon(hIcon); 

     // Test it 
     cur = new Cursor(@"c:\temp\test.cur"); 
     this.Cursor = cur; 
    } 
    [DllImport("user32.dll")] 
    extern static bool DestroyIcon(IntPtr handle); 
    } 
} 

REF:https://social.msdn.microsoft.com/Forums/windows/en-US/9ea0bf74-760f-4f40-b64c-0cf7b0a56939/save-custom-cursor?forum=winforms

+0

感谢您的回复,但我想改变这一切的鼠标光标(手,箭,忙,帮助选择...)不仅为当前光标 –

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; 
    } 
+0

我想改变所有的窗口游标不仅为窗体。谢谢你的帮助! –

相关问题