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.
Code:
static class NativeMethods
{
[DllImport("user32.dll")]
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);
}
/*...*/
}
And I use it like this:
Code:
// When calling the slow form
NativeMethods.SwitchWaitCursor(this.Handle);
using (SlowForm diag = new SlowForm())
{
diag.ShowDialog(this);
}
// OnShow() of the SlowForm
private void SlowForm_Shown(object sender, EventArgs e)
{
NativeMethods.SwitchWaitCursor(this.Handle);
}
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?