Change the global cursor
-
Hello I have currently made a small colorpicker application. I want to know if it is possible to change the global cursor when I press a button in my application, the reason is I want to see the crooshair cursor outside my application too. I have searched the internet and the best thing I could find was to use the "user32.dll" with the function SetSystemCursor, however I have no clue if this is the right thing to do. the SetSystemCursor needs an 'IntPtr hcur, uint id' but I do not know how to get the correct values for them. I searched the msdn from my vs05 and it said the id could must be some constants which needs to be defined before loading the windows.h header. To help people help me, the link for pinvoke.net is here: pinvoke.net and the link for the info I used on msdn: msdn I hope someone can help me regards QzRz
-
Hello I have currently made a small colorpicker application. I want to know if it is possible to change the global cursor when I press a button in my application, the reason is I want to see the crooshair cursor outside my application too. I have searched the internet and the best thing I could find was to use the "user32.dll" with the function SetSystemCursor, however I have no clue if this is the right thing to do. the SetSystemCursor needs an 'IntPtr hcur, uint id' but I do not know how to get the correct values for them. I searched the msdn from my vs05 and it said the id could must be some constants which needs to be defined before loading the windows.h header. To help people help me, the link for pinvoke.net is here: pinvoke.net and the link for the info I used on msdn: msdn I hope someone can help me regards QzRz
Well, this works for me:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsCursorTest { public partial class Form1 : Form { private const int OCR_NORMAL = 32512; [DllImport("user32.dll")] static extern bool SetSystemCursor(IntPtr hcur, uint id); [DllImport("user32.dll")] static extern bool DestroyCursor(IntPtr hcur); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { IntPtr cursor = Cursors.Cross.CopyHandle(); SetSystemCursor(cursor, OCR_NORMAL); DestroyCursor(cursor); } } }
Deja View - the feeling that you've seen this post before.
-
Well, this works for me:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsCursorTest { public partial class Form1 : Form { private const int OCR_NORMAL = 32512; [DllImport("user32.dll")] static extern bool SetSystemCursor(IntPtr hcur, uint id); [DllImport("user32.dll")] static extern bool DestroyCursor(IntPtr hcur); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { IntPtr cursor = Cursors.Cross.CopyHandle(); SetSystemCursor(cursor, OCR_NORMAL); DestroyCursor(cursor); } } }
Deja View - the feeling that you've seen this post before.
-
It works for me too, thanks :) I just have 2 questions now. Where did you find the number for ORC_NORMAL? and how to chance the cursor back to normal again? I will assume what you need to do is add another const int with another value which?
Well, the normal way to do this is to copy the old cursor (using CopyCursor) and then reinstate it when you need to.
QzRz wrote:
Where did you find the number for ORC_NORMAL?
I googled OCR_NORMAL to find the value. BTW - the value for OCR_CROSS is 32515.
Deja View - the feeling that you've seen this post before.
-
Well, the normal way to do this is to copy the old cursor (using CopyCursor) and then reinstate it when you need to.
QzRz wrote:
Where did you find the number for ORC_NORMAL?
I googled OCR_NORMAL to find the value. BTW - the value for OCR_CROSS is 32515.
Deja View - the feeling that you've seen this post before.
-
No problem. Glad to help.
Deja View - the feeling that you've seen this post before.