none
Change a cursor in windows through a WPF app

Answers

All replies

  • That is the way windows works.  Imagine if my app changed your cursor in a way that you did not want.  Each application has the "right" to change the cursor but only within its scope.  You can change cursors on a system level (don't know how to do it other than thru Control Panel).

    LS


    Lloyd Sheen

    Wednesday, February 29, 2012 5:21 PM
  • Thanks Sqlguy, but i can't go into the control panel of each computer where my app will be. But if there are a way to upload a cursor in the windows cursor libraries then change the windows cursor, it could help me.

    I should probably explain a little more my need : I want to use the Kinect instead of my mouse on Windows, that is the easy part. But i need to use a WPF draw instead of the windows arrow cursor (for having my  cursor looklike ). I already have my cursor working all over windows, but it's reverting to the default cursor out of the app.

    It seem the only way is with the registry, but i don't find any clear explanation. 

    Thursday, March 01, 2012 8:59 AM
  • I found an explanation by googling on "windows registry mouse pointer"

    http://www.thebitguru.com/articles/14-Programmatically+Changing+Windows+Mouse+Cursors

    Thursday, March 01, 2012 12:13 PM
  • Thank you Andy. But i already read the explanation of Farhan Ahmad and it's really not a clear explanation. 

    I can show what i try to build with his tutorial

    namespace CursorControl
    {
    
    public partial class MainWindow : Window
     {
     [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
     public static extern bool SystemParametersInfo(uint uiAction, uint uiParam,
     IntPtr pvParam, uint fWinIni);
      
      private void cursorType_Changed(object sender, RoutedEventArgs e)
      {
      const int SPI_SETCURSORS = 0x0057;
      const int SPIF_UPDATEINIFILE = 0x01;
      const int SPIF_SENDCHANGE = 0x02;
      
     //Here i should put a Registry.SetValue("HKEY_CURRENT_USER\\Control Panel\\Cursors", "(Default)", ...something);
    
      SystemParametersInfo(SPI_SETCURSORS, 0, IntPtr.Zero,
      SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
      }
     }
    }
    I have to change uint pvParal by IntPtr pvParal beacause uint don't accept null. 




    Thursday, March 01, 2012 3:58 PM
  • The guy says his code in the first post + suggested changes work

    http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=80020

    Thursday, March 01, 2012 4:21 PM
  • We are temporarily marking this as "Answer", if you have any concerns or new findings; please feel free to let me know.

    Best regards.



    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 09, 2012 2:20 AM
  • I tried with Andy's post and it works.  But under XP and WIN7 there are some differences on the folders so you need some tweaks. Below is my code please check it out. 

     public partial class MainWindow : Window
        {
            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(int uAction, int uParam, string lpvParam, int fuWinIni);
    
            public MainWindow()
            {
                InitializeComponent();
                Loaded += (o, e) => 
                {
                    Registry.SetValue("HKEY_CURRENT_USER\\Control Panel\\Cursors\\Schemes", "(Default)", @",%SYSTEMROOT%\Cursors\youricon.cur,,,,,");
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cursors\\Schemes", "Windows Default", @",%SYSTEMROOT%\Cursors\youricon.cur,,,,,,,,");
                    SystemParametersInfo(SPI_SETCURSORS, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); 
                };
            }
        }

    Warm regards.


    Time is short

    Friday, March 09, 2012 2:55 AM