Thread: Sending WM_SETCURSOR to different windows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    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.

    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?
    Last edited by Mario F.; 12-09-2009 at 08:38 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone using Windows 7?
    By Sharke in forum General Discussions
    Replies: 60
    Last Post: 07-12-2009, 08:05 AM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM