I am trying to implement a software like "Gyazo", a snippet tool that takes a screenshot. The program begins (nothing appears on the screen, other than the cursor changing), the user clicks to point A, then drags to point B (drawing a transparent rectangle), releases the mouse, then the screenshot gets saved and the program closes.
The way I draw that transparent rectangle, is that I re-size and re-position a form with a 30% transparency. So the cursor is never on the form! In order to change the cursor, since it is outside of the form, I tried using:
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
private int CROSS = 32515;
private const uint NORMAL = 32512;
//and then calling
SetSystemCursor(LoadCursor(IntPtr.Zero, CROSS), NORMAL);
The problem I had with this code is that it is really buggy. When the form closes, the cursor doesn't change back to normal. I don't know how to revert the cursor properly. Also, reverting the cursor when the form is closed from the task manager will be impossible, correct ?
What other way would you suggest to change the cursor to cross in this case ?
Edit: Just to clarify, because I tried asking a similar question before which was marked as duplicate of this question and I deleted it, what I am trying to do is similar, but a lot different, because in the answer provided in that question, the solution provided in the answers, is to make a full-screen borderless form, set a screenshot of the desktop as the background of that form, and then crop a rectangle from that. Firstly, that solution "freezes" the screen, since all you see a photo of your desktop while the cropping takes place, and secondly, it is near impossible to handle multi-monitor setups that way. Plus it does extra and unnecessary work.