Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

c# - How can i change the cursor (image) in the whole windows OS

I need to change the cursor in all windows, not just in the application, i have try this:

this.Cursor = Cursors.WaitCursor;

And this:

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

But it only changes the cursor in my application.

Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you have your own cursor file (.cur) to apply you could hack this.

First you will have to change thje default Arrow cursor in the Registry, then you will need to call some P-Invoke to allow the OS to update the current sytem paramerters so the cursor actually changes.

Somthing like:

    private void ChangeCursor(string curFile)
    {
        Registry.SetValue(@"HKEY_CURRENT_USERControl PanelCursors", "Arrow", curFile);
        SystemParametersInfo(SPI_SETCURSORS, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); 
    }

    const int SPI_SETCURSORS = 0x0057; 
    const int SPIF_UPDATEINIFILE = 0x01; 
    const int SPIF_SENDCHANGE = 0x02; 

    [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
    public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint? pvParam, uint fWinIni);

Usage:

 ChangeCursor(@"C:MyCursor.cur");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...