Re: wait cursor

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Vlad Simionescu (vsimionescu_at_softwin.ro)
Date: 10/22/04


Date: 22 Oct 2004 12:55:59 -0700

Robert Jordan <robertj@gmx.net> wrote in message news:<cl427g$nkl$05$1@news.t-online.com>...
> Hi Vlad,
>
> > I'm trying to let my Windows Form application perform a lengthy
> > operation ...

>
> I think you've found a bug.
>
> The Windows API requires that the cursor must be periodically
> (on WM_SETCURSOR) repainted, when it doesn't match the window's
> class cursor. WinForms seems not to repaint the cursor, when the
> form is blocked by a modal dialog.
>
> Here a workaround using the plain old WndProc. Put the code
> into your main form.
>
> const int WM_SETCURSOR = 32;
>
> protected override void WndProc(ref Message m)
> {
> base.WndProc(ref m);
> if (m.Msg == WM_SETCURSOR && Cursor == Cursors.WaitCursor)
> {
> // refresh the cursor
> Cursor = Cursors.WaitCursor;
> }
> }
>
> Not very smart, but it does its job.
>
> Salut
> Rob

Thanks a lot.
It worked, though not exactly as you wrote it. I had to replace

  Cursor = Cursors.WaitCursor;

with

  Cursor.Current = Cursors.WaitCursor;

otherwise it issued a stack overflow exception. I don't know exactly
why, I'm not an expert in Win API details, I just supposed it had to
do with the fact that setting Cursor might trigger other events that
in turn lead to a new call of WndProc. Since I knew that setting
Cursor.Current is "local", I tried it and it worked. So, for others
interested, the exact code that worked for me is:

const int WM_SETCURSOR = 32;

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    if (m.Msg == WM_SETCURSOR && Cursor == Cursors.WaitCursor)
    {
        // refresh the cursor
        Cursor.Current = Cursors.WaitCursor;
    }
}

So I guess it really was a bug. Curious, isn't it ? Not that there was
a bug, but that it seems no one noticed it before, I would think that
setting the cursor to hourglass on the main window during a progress
dialog is the obvious thing to do. Maybe they did notice it and I
didn't find their postings.

One last "personal touch" - did you say Salut on purpose ? It's
romanian for Hello, and I am romanian, as can be seen from my e-mail
(or maybe from my name).

Salut yourself, and thanks again.
Vlad



Relevant Pages

  • Re: Why RosAsm Breaks on a large number of symbols
    ... > Windows message loop is a good starting point. ... But of course this is not a genuine bug report, ... > preservation convention for Windows programing, ... You need to preserve register in callbacks - that's the only _rule_ about ...
    (alt.lang.asm)
  • RE: Windows TCP TimeStamp not compliant to (RFC 1323) !?!?
    ... Windows TCP TimeStamp not compliant to!?!? ... Hello, I don't know if this place is the good one for a 'bug report', but I ...
    (microsoft.public.windows.server.networking)
  • Re: bad experience with Suse 9.1 on Inspiron 8200
    ... > it is an M$ bug, such technicalities are irrelevant to the end user. ... :-) Windows has ... work as long as they work, trying to install a nitrous ... Linux are at least a *little* bit curious about how their computer works ...
    (alt.os.linux.suse)
  • I think I have been hijacked.
    ... I am running windows xp on my Compaq Presario and Toshiba laptop, ... An internet connection appears to have been added through a USB. ... R - Registry, StartPage/SearchPage changes ... Fixed crashing bug on certain Win2000 and WinXP systems at O23 listing ...
    (microsoft.public.windowsxp.security_admin)
  • Ten Mouse Cursor Problems
    ... While using the mouse (windows xp) I may encounter any of the below ... Mouse cursor unmanageable. ... just one word will highlight, I make several attempts to do the same click ...
    (microsoft.public.windowsxp.help_and_support)