Sending WM_SETCURSOR to different windows
Let's see if I can get this answered here instead...
A little background just in case you are wondering why I am doing this:
In C#, Application.UseWaitCursor changes the cursor shape to the default hourglass shape without waiting for WM_SETCURSOR response. This means that the cursor shape doesn't last. It is set again immediately to Cursor.Current based on whatever control my mouse cursor is currently hovering.
As I understand this is by design and I'm fine with it. It only means I have to manually send WM_SETCURSOR after Application.UseWaitCursor. Without doing it, I cannot have the behavior I intend below.
I need for the mouse cursor to change to an hourglass while waiting for a form to load that it's taking a few seconds to display. This form does some data processing before displaying its contents.
This is what I came up with.
And I use it like this:
static class NativeMethods
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
public static void SwitchWaitCursor(IntPtr handle)
Application.UseWaitCursor = !Application.UseWaitCursor;
SendMessage(handle, 0x20, handle, (IntPtr)1);
It is working exactly as expected. However, I do have one thought nagging me. Is it alright in this SendMessage usage pattern, for hWnd to refer to two different windows?
// When calling the slow form
using (SlowForm diag = new SlowForm())
// OnShow() of the SlowForm
private void SlowForm_Shown(object sender, EventArgs e)