Re: wait cursor
From: Vlad Simionescu (vsimionescu_at_softwin.ro)
Date: 10/22/04
- Next message: hazz: "Re: what is the purpose of this declarative [XmlRootAttribute.....] ?"
- Previous message: Jon Skeet [C# MVP]: "Re: Problem with inherited events"
- In reply to: Robert Jordan: "Re: wait cursor"
- Next in thread: Robert Jordan: "Re: wait cursor"
- Reply: Robert Jordan: "Re: wait cursor"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: hazz: "Re: what is the purpose of this declarative [XmlRootAttribute.....] ?"
- Previous message: Jon Skeet [C# MVP]: "Re: Problem with inherited events"
- In reply to: Robert Jordan: "Re: wait cursor"
- Next in thread: Robert Jordan: "Re: wait cursor"
- Reply: Robert Jordan: "Re: wait cursor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|