Click here to Skip to main content
Click here to Skip to main content

Automatic Application Wait Cursor

By , 16 Mar 2005
 

Sample Screen Shot from Demo

Introduction

Making your WinForm applications User Friendly is important. One aspect of a good user experience is informing your user that your application is unresponsive during short periods of work. This article introduces an effective and simple way of adding application wide WaitCursors using one line of start-up code.

Background

Recently, I have been working on a WinForms project at home that occasionally performs some short (less than 5 seconds) running tasks. I wanted the user to be informed that during that short period the UI is unresponsive, so I chose to use the Cursors.WaitCursor to indicate this. This article shows how I came to my final WaitCursor library implementation which I believe is a completely re-usable library.

Using the code

From a developer's point of view, using the WaitCursor library could not get any simpler. Add a reference to the WaitCursor assembly and then add the following line to your application start-up code:

ApplicationWaitCursor.Cursor = Cursors.WaitCursor;

That’s it!

You can of course use any Cursor you like, you can use one of the predefined Cursors or you can create a new cursor and use that instead. You can also fine tune the amount of work time that will elapse before the Cursor is shown:

ApplicationWaitCursor.Delay = 
             new TimeSpan(0, 0, 0, 1, 0);  // Delay of 1 second

How the library came about

During development of a recent WinForms project at home, I had decided to use the cursor to indicate short running tasks to the user, like so:

private void DoShortRunningTask()
{
    Cursor.Current = Cursors.WaitCursor; 

    .. do some work .. 

    Cursor.Current = Cursors.Default; 
}

Now, before you say "Where’s the exception handling code?", I am trying to illustrate how I eventually came to my final cut of the WaitCursor library.

The above code works, or, at least it works most of the time. I, of course, found that without any exception handling I could end up with the WaitCursor on permanently, so I quickly came up with:

private void DoShortRunningTask()
{
  Cursor.Current = Cursors.WaitCursor;
  try
  {
    .. do some work ..
  }
  finally
  {
    Cursor.Current = Cursors.Default;
  }
}

Now that’s better, I've guaranteed that the Cursor will always be returned to the Default cursor even if an exception occurs. However, I found it arduous to wrap that code around every short running task that I was developing.

Then I remembered how I used to use C++ stack based destructors to perform tear down work upon exiting of a method:

void DoShortRunningTask()
{
StWaitCursor cursor = new StWaitCursor();

  .. do some work .. 
// Implicitly called ~StWaitCursor returns the Cursor to Default


}

But I couldn't use C# destructors the same way since you can't guarantee when a C# destructor is called since the Garbage Collector thread is responsible for that.

Instead, C# uses a different language feature, the using statement which implicitly calls the Dispose method of objects that implement IDisposable. Although (I find it's) not quite as easy to use as the C++ destructor, you can achieve the same result with the using statement:

private void DoShortRunningTask()
{
    using (new StWaitCursor())
    { 
        .. do some work .. 
    } 
}

This code, of course, requires the StWaitCursor class:

public class StWaitCursor : IDisposable
{
  public StWaitCursor()
  {
    Cursor.Current = Cursors.WaitCursor;
  }
  public void Dispose()
  {
    Cursor.Current = Cursors.Default;
  }
}

There, nice and simple. I found, however, that if my short running task was too short then the user sees a quick flickering of the Cursor to and from the WaitCursor, quite annoying. So I decided I needed a way of turning the WaitCursor on after a predefined amount of time during a task.

After quite a few iterations and refactorings, I came up with what I called the StDelayedCallback class (see source code) which is a generic class that once instantiated will wait for a specified amount of time before calling the Start method of an IDelayedCallbackHandler, and if Start was called that it was guaranteed to call the Finish method of the same interface. Once I had this, I could easily implement the interface such that the WaitCursor was turned on when Start was called and returned the Default cursor when Finish was called.

Some things I found

During development of the WaitCursor library, I discovered that I could not set Cursor.Current on any thread other than the GUI thread. This is where the Win32 AttachThreadInput method can be used to get around this problem effectively. So I developed the StThreadAttachedDelayedCallback class which wraps up the call to the AttachThreadInput.

So eventually I ended up with a generic StDelayedCallback class, a ThreadInput attached version of it called StThreadAttachedDelayedCallback and a specific Cursor implementation called StWaitCursor. Incidentally, I used the prefix St since I had originally intended on using these classes in a similar way to the C++ Stack based classes I had used in the past. So up until now, I had intended on using the following:

private void DoShortRunningTask()
{
  using (new StWaitCursor(new TimeSpan(0, 0, 0, 0, 500))
  {
    .. do some work ..
  }
}

However, it still meant I had to be explicit about where I wanted my WaitCursor to show.

Then I had an attack of brilliance and came up with the ApplicationWaitCursor singleton class which neatly wraps the StWaitCursor such that whenever the application is working, or rather, whenever it’s not regularly calling OnApplicationIdle, then the StWaitCursor kicks in and shows the WaitCursor.

The only caveat I found was when I dragged a window around which blocks the OnApplicationIdle call. So, I also intercept the WM_NCLBUTTONDOWN message (which is sent at the beginning of the window dragging) to temporarily disable the StWaitCursor.

That's where I am up to with the current WaitCursor implementation and in brief how I got there. You can easily derive from the StDelayedCallback class to create similar effects. Perhaps you would like to show an Indefinite progress bar during your long running tasks, or indicate "Saving Changes..." in a StatusBar control:

private void SaveChanges()
{
  using (new StStatusBar(stbMain, "Saving Changes...")
  {
    .. do some work ..
  }
  // StStatusBar.IDispose could return the Text
  // of the StatusBar to its original value 
}

Note that the source code does not contain the StStatusBar class, I am just using it as an example of other ways you could use the StDelayedCallback class.

History

Version 1.0.0.0 (12th March 2005)

  • Initial version.

Version 1.0.1.0 (16th March 2005)

  • Updated to be CLS compliant (thanks to C a r l and Mathew Hall for pointing this out).

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

Steve Fillingham
Web Developer
Australia Australia
Member
I am a .NET Developer living in Melbourne, Australia. I am happily married with 2 gorgeous little girls, Georgia and Maddison.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4memberRafique Sheikh18 Mar '13 - 14:52 
Good article, shows a nice solution for a problem. It could be a bit more brief though Smile | :)
GeneralMy vote of 5memberfoxaxel17 Nov '11 - 0:39 
Simply perfect. The best way to control the cursor.
QuestionThank you, a small issue we are noticingmemberreddyp8213 Oct '11 - 12:14 
We have been using your binary file for atleast 2 to 3 years, It is very nice to have it in our app.
 
We have been noticing that some times waitcursor never shows up on a busy operation.We couldnt find a pattern when it does it, any ideas whats going on.
 
App Background : Windows.net 4.0,MDI
 
By the way,thank you for the good work.
GeneralAny solutions to the problems belowmemberMatthew Goldman21 Feb '11 - 4:21 
I was wondering if anyone had been able to come up with a solution to the following problems:
 
When Clicking and holding in a tree view without moving the busy cursor will be displayed.
When not doing anything every now and then the mouse will flash the busy cursor.
GeneralMy vote of 5membercrocher6 Feb '11 - 15:08 
So simple and bright idea. I love it!
GeneralGood jobmemberCIDev22 Oct '10 - 6:46 
This is a really handy utility. Also a clearly written article.
Just because the code works, it doesn't mean that it is good code.

GeneralNice articlemvp d@nish 14 Jun '10 - 6:23 
Good one. Thanks. Smile | :)
 
Sorry for shamelessly copying from your article here[^].
GeneralCursors goes to wait cursor in windows Copy paste menu dialogmembererikgenwise18 Feb '10 - 2:15 
How can i prevent the cursors from going to waitcursor when I call up the standard copy paste dialog ?
Select text in a text box, press right mouse key, The copy past dialog appears. 2 seconds in the dialog the cursor turns to waitcursor. Any ideas ?
The dialog is not mine but standard.
GeneralRe: Cursors goes to wait cursor in windows Copy paste menu dialogmemberMatthew Goldman4 Feb '11 - 11:43 
I handled this in by adding this code to the PreFilterMessage()
 
else if (m.Msg == WM_CONTEXTMENU) (for handling the keyboard)
_cursor.Enabled = false;
else if (m.Msg == WM_RBUTTONUP) (for handling the mouse)
_cursor.Enabled = false;
 

private const int WM_CONTEXTMENU = 0x7b;
private const int WM_RBUTTONUP = 0x0205;
 
Note: this will not catch the Shift+F10 call.
GeneralNice Job !!memberBorun8 Jun '09 - 8:08 
Nice Job...Love it.
 
Try yourself before you get anything from anyother else

GeneralA Few More Bugsmemberchewmon3420 Mar '09 - 5:54 
Hi Steve,
 
Thanks for the Code, it's just what I was looking for. But i'm noticing a few other bugs that noone has mentioned.
 
The main one is that when you start typing in a textbox, the cursor disappears. Moving the mouse or tabbing to the next control brings it back.
[interesting side note: it doesn't happen if you are only Backspacing the text in the textbox]
 
Also, a very small bug. If you are using a DateTimePicker and either:
a. click the calendar drop-down button and don't move the mouse
or b. use F4 to open the calendar
Then the WaitCursor will appear until the mouse is moved or the calendar is closed.
 
I don't expect you to fix these, I just wanted to add them to the bug list.
 
Thanks Again,
Jim
GeneralWorks... mostlymemberJakub Janda4 Mar '09 - 1:10 
Testing for a few minutes, the hourglass cursor also appears:
1) When scrolling through a long datagridview
2) When you press (and don't release) the mouse button on a treeview item
3) Once you start drag operation
4) A few times it appeared when scrolling through a multiline textbox, but I was unable to reproduce it coherently
 
Although I appreciate the concern and effort put into this utility, I don't think it's really ready for primetime until these issues are dealt with. Good luck with fixing them, tho.
GeneralStill brilliant after 3 years!memberseankearon5 Feb '09 - 12:21 
I'm back here downloading your code to include in a home project. I saw my earlier post below - nearly three years ago now I was here saying how brilliant this was, and it still is!
 
We've been using your automatic application wait cursor at work in our rich client apps for nearly three years and have had no problems at all. In htat time I have been working for a large UK government organisation with a team of about 10 developers shipping custom apps to various "business units". Your code has given us no problems at all in that time and has saved us a load of work.
 
Thanks again, Steve!
 
Sean Smile | :)
GeneralBrilliant, thanks a lot!memberHerribert117 Oct '08 - 0:21 
Demo tested, integrated in my application, running.
 
Thank you very much for saving a lot of developer time!
 
Heribert
GeneralIs it possible to use this in a VS2008 C++ Windows Forms applicationmemberbencbr16 Sep '08 - 8:52 
Any pointers?
GeneralRe: Is it possible to use this in a VS2008 C++ Windows Forms applicationmemberSteve Fillingham19 Sep '08 - 1:08 
If your using managed C++ then it should be usable without any changes at all.
 
If your not using managed C++ then I would imagine the code is easily translated to C++ anyway.
QuestionRe: Is it possible to use this in a VS2008 C++ Windows Forms applicationmemberTheBerk9 Jan '09 - 10:29 
I'm pretty new to to Managed C++, does managed C++ have its own version of the 'using' statement? If not, how would I go about getting this to work in managed c++? Thanks!
AnswerRe: Is it possible to use this in a VS2008 C++ Windows Forms applicationmemberHowitZer2623 Feb '09 - 11:08 
First download the source and then build it in C# to create the dll. This dll can be used in a C++ Forms application. Add a reference to your C++ project and select the WaitCursor.dll.
 
The using statement for c++ is "using namespace ConceptCave::WaitCursor;"
QuestionCan this work with WPFmembersreeni7320 Jul '08 - 10:10 
Steve, can you modify this for WPF windows applications too?
Or Any one has done this already?
GeneralWait cursor shows when holding mouse button down on a scroll barmemberQStarin9 Jul '08 - 7:03 
Seems like the mentioned bug during development where the wait cursor would activate when dragging a window around. It does the same thing when dragging a scroll bar up and down. Anyone got a fix?
GeneralRe: Wait cursor shows when holding mouse button down on a scroll barmembergezanal16 Dec '08 - 7:58 
I have not been able to reproduce this. I used the following line of code in my application initialization
 
ConceptCave.WaitCursor.ApplicationWaitCursor.Cursor = Cursors.WaitCursor;
QuestionWhat version of the .NET Framework has this been tested on?memberMatt Christenson28 May '08 - 6:09 
I just came across this in 2008, it was posted in 2005. Were you using 1.0, 1.1, or 2.0 at the time? Have you upgraded your projects to 3.0 or 3.5?
 
Thanks!
AnswerRe: What version of the .NET Framework has this been tested on?memberQStarin9 Jul '08 - 6:50 
I've linked to this library in .Net v2.0, v3.0, and v3.5 projects. I've also opened and compiled the project in Visual Studio 2005 & 2008. If I recall correctly, it was a VS2003 project file and needed to be upgraded for both VS 2005 & 2008 and both worked perfectly.
GeneralRe: What version of the .NET Framework has this been tested on?memberSteve Fillingham11 Jul '08 - 15:44 
Originally developed and tested in VS 2003 .NET 1.1. Have not done much on it since, but it looks like I need to fix up some of those reported problems ..
Generalvery good.memberali_reza_zareian17 Apr '08 - 0:43 
realy its a usefull article
GeneralBeyond what I neededadminChris Maunder16 Apr '08 - 2:11 
I was looking for a simple CWaitCursor style implementation but having it appear automatically, and having the ability to set a delay is above and beyond the call of duty.
 
Noice!
 
cheers,
Chris Maunder
CodeProject.com : C++ MVP

GeneralGreat work this was just what i was looking formembergshea1 Dec '07 - 3:39 
Big Grin | :-D
 
Gabe
GeneralThanksmembermark.deraeve10 Oct '07 - 21:12 
I used your code in my application,
it saved me a lot of work.
At first sight there are no complications,
but after reading these posts I will test the application again completely.
 
Thanks!!
 
MRD ICT Engeneer!
GeneralRe: Thanksmembermark.deraeve11 Oct '07 - 1:53 
After testing a while I'm still excited about your solution.
I only encountered 1 minor fault.
When I push a scroll bar and slide, then the wait timer is shown.
I tried using prefilteredmessages, but when I disable the leftdown, then the wait cursor is never shown on a left mouse down.
Have yo uencountered this problem?
For now I will keep the waitcursor when scrolled, because everuthing works normally, only they get to see a waitcursor when scrolling.
I tried setting the timeout to 1 sec, but scrolling can take up to a few seconds, so that didn't helped either.
Greetz...
 
MDR ICT Engeneer
GeneralThanks! Awesome idea!!memberBit-Smacker31 Aug '07 - 10:05 
You saved me lots of irritation from having to manage my own cursor changes!
 
I copied the two setup lines from your example into my app. and deleted about 20 lines of my cursor changes. It now works much better than my original code ever did!!
 
This should be a standard .NET control in the Windows Forms tool collection!
GeneralSo sweet, I call it ninja-code!memberBrad_Isbell27 Oct '06 - 12:26 
Excellent job. Thank you very much.
GeneralMinor Issuemembersecovel22 May '06 - 3:18 
In tight loops that effect how the GUI is displayed it is typical to call Application.DoEvents(); so that the GUI has some time to repaint. Otherwise the GUI appears to be completely locked up and you get strange paint artifacts. When I simulate this in your test project the WaitCursor turns off at the first DoEvents, and never turns back on.
 
private void button2_Click(object sender, System.EventArgs e)
{
// Simulate some really hard work ..
statusBar1.Text = "Working Really Hard...";
for (int i = 0; i < 6; i++)
{
Application.DoEvents();
Thread.Sleep(500);
}
 
statusBar1.Text = "Ready";
}
 
If I set the Sleep() time a little higher then the cursor flashes on and off.
 
Perhaps a delay timer for turning off the wait cursor would help?
 
Sean

GeneralRe: Minor IssuememberSteve Fillingham23 May '06 - 1:22 
Hi Sean, I think you missed the point, there is already a (configurable) delay before the wait cursor appears. The reason why it flashes when you increase your sleep time is that the wait cursor delay expires during the Sleep and the WaitCursor appears which is then turned off again during the DoEvents.
 
I try really hard not to use DoEvents() since it can cause stack overflow issues if not done cautiously. Any real intensive work that you want to the user to see some progress on should be done on a seperate thread with asynchronous Invokes back to the GUI thread for UI updates only.
 
The WaitCursor is meant for really short delays where 1 or 2 seconds of unresponsiveness is not too harsh for the user. Form_Loads are a good example, particularly on control rich Forms and slower machines, during a Form_Load the user cannot do anything anyway, so informing them of a slight delay via the wait cursor is neat.
 
Cheers

GeneralBrilliant - thanks!memberseankearon4 Apr '06 - 14:27 
It's 1:00 am and I've just finished sweeping the app prototype that I'm going to show to customers tomorrow, wanted to add in some wait cursors and came across your automatic version. It just works and has saved me adding any code to my app at all.
 
Man, I just wanted to say 'thanks' for making that available - much appreciated Smile | :)
 
Cheers
 
Sean
GeneralRe: Brilliant - thanks!memberSteve Fillingham6 Apr '06 - 0:25 
Hi Sean,
 
Hope your demo goes well, just keep in mind the 'side effects' that this version comes with which are noted in other posts.
 
Cheers
QuestionStStatusbar?memberHyperX18 Aug '05 - 11:49 
Steve,
 
Thanks again for this beautiful code.
 
I have one question though. I have a contextmenu thats being drawn dynamically when the user hits Shift + F5. The popup comes up fine; but, the hour glass keeps on showing after the context menu has been shown.
 
This code din't help either.
 
if (m.Msg == WM_NCLBUTTONDOWN ||
m.Msg == WM_LBUTTONDOWN ||
m.Msg == WM_RBUTTONUP ||
m.Msg == WM_CONTEXTMENU ||
m.Msg == WM_ENTERMENULOOP ||
m.Msg == WM_SYSKEYUP ||
m.Msg == WM_SYSKEYDOWN)
_cursor.Enabled = false;
else
_cursor.Enabled = true;
 
Any ideas from your side on this?
 
Thanks,
 
HyperX.
 
BTW, WHen can we expect your StStatusBar? I'm very eagerly looking forward to it.
AnswerRe: StStatusbar?memberSteve Fillingham19 Aug '05 - 2:02 
Hi HyperX,
 
Not that I have tried it yet but Andy Baker (another post) has enhanced the Wait Cursor quite smartly such that it does not depend on the Application Idle event which is not posted during mouse operations.
 
I have no current plans to develop the StStatusBar class, I just used it as an example of other applications the technique could have, although I dont see StStatusBar as being overly complicated.
 
Cheers
 
Steve
GeneralInteresting, but has a few little bugs...memberspam2@vbusers.com12 Aug '05 - 6:05 
Interesting article, but I found a few bugs with this.
 
Firstly the hour glass stays on when you show right click content menus (including built in content menus). This can be fixed by checking for the right button down + content menu messages in your message callback.
 
Secondly (depending on how busy the application is) the hour glass will sometimes stay on indefinitely (due to the order in which the application idle event fires).
 
Finally, it also continuously sets and unsets the cursor even when the application is idle - this seems unnecessary.
 
Anyway, still a good post. I have coded a revised version to this that takes a different approach and seems to work well (so far!). See below for the alternative:
 
http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=58&PostID=1&NumReplies=0
 

Regards and thanks
 
andrew baker
www.vbusers.com
GeneralVery good job.memberHyperX11 Aug '05 - 12:35 
Nice features. Good coding practice. Well done overall.
 
Thank you,
 
HyperX.
 
Stress Comes From Making Things More Important Than They Are.
QuestionAm I missing anything?memberYaron Shkop6 Jun '05 - 1:36 
When you open a new thread (System.Thread) the cursor is overriden and returns to default.
I thought this solution should also overcome the problem of cursor being overriden on new threads... D'Oh! | :doh:
AnswerRe: Am I missing anything?memberSteve Fillingham6 Jun '05 - 4:30 
Not sure, can you send an example ?
 
Cheers
GeneralRe: Am I missing anything?memberYaron Sh14 Jun '05 - 0:15 
This is quite simple.
Guess we have some method that is called asynchronously and synchronously.
At synchronous way it works fine asynchronously it doesn't work. When you move the mouse you can see that the cursor is not consistent.
 
If you will locate two buttons on a form and bind them to the buttons events you will look what I'm talking about.
Button 1 click will open work on another thread in the process and in the mean time the cursor will not be consistent if you will move it over the form.
 
[STAThread]
static void Main()
{
//Set wait cursor with 150 ms delay
ApplicationWaitCursor.Cursor = Cursors.WaitCursor;
ApplicationWaitCursor.Delay = new TimeSpan(0, 0, 0, 0, 150);
 
Application.Run(new Form1());
}
 
//Async
private void button1_Click(object sender, System.EventArgs e)
{
SetCursor(Cursors.WaitCursor);
 
Thread workThread = new Thread(new ThreadStart(DoWork));
workThread.Start();
}
 
//Synchronous
private void button2_Click(object sender, System.EventArgs e)
{
SetCursor(Cursors.WaitCursor);
 
DoWork();
}
 
private void DoWork()
{
int len = 30;
 
for(int i=0; i
GeneralRe: Am I missing anything?memberSteve Fillingham14 Jun '05 - 4:07 
Yaron,
 
The idea of the Application WaitCursor is to show when the Main thread is busy. If you are performing work on other threads then the UI will be fully responsive and a wait cursor is probably not necessary.
 
Having said that and without having tried it, you should still be able to show the Wait Cursor on another thread using ..
 
using (new StWaitCursor())
{
DoWork();
}
 
You would generally perform short (<3 seconds) tasks on the Main thread and the Wait Cursor makes good sense. Any more than 3 or so seconds then you probably should use either a progress bar, or like you said use a seperate thread to perform the work in the background. If using a background thread you would probably want some way of informing the user of progress and perhaps the ability to cancel the operation aswell. This however is beyond what the Wait Cursor is intended for.
 
Cheers

GeneralA little bugmemberNikolyv24 May '05 - 21:25 
Hello Steve!
 
Great work!
BUT..
 
When I use your sample with a SandDock (http://www.divil.co.uk/net/)
I have a trouble when mouse pointer stop over a pinned window( like a Toolbox in VisualStudio).
Normally ( sithout your component) this window must be popped up. Your component disable this functionality.
 
Best regards
Nikoly

GeneralSeparate threadsussnamsaray21 Apr '05 - 8:10 
First, thank you for the impressive contribution.
Can you please post sample code how to use this
in a separate thread? I tried everything I could think of,
nothing works.
GeneralVB versionmembermarcrobitaille29 Mar '05 - 3:01 
Hello!
 
Is there a vb version of this?
Thank you
 
Marc R.
GeneralRe: VB versionmembermarcrobitaille30 Mar '05 - 4:18 
I have translate the code in vb format. If you want it, just send me an email. Bye
 
Marc Robitaille
QuestionWhen to expect an updated version?memberC a r l28 Mar '05 - 9:01 
Hi!
 
When can we expect an updated (and fixed) version of this? It is a very nice and useful component, but some clients are wondering why the hourglass shows up for nothing sometimes Smile | :)
 
Thanks!

AnswerRe: When to expect an updated version?memberSteve Fillingham29 Mar '05 - 0:27 
Crikey !
 
Well Carl, for my uses I dont need any fixes currently. I can see (from other posts) that under some scenarios the cursor will show unexpectantly but you have the same source code that I do and you are quite welcome to make enhancements and fixes to suite your needs and if you feel generous enough you can email me your changes so I can post updates (with contributors thanked), this is after all a community of sharing.
 
As for your clients, and not to be rude, but I am not getting anything from them nor do I have any responsibility to them, they are your clients and your responsibilities. The source I posted comes with no warranties, I am sure it has potentially saved your at least a few hours of tedious coding, so for you to make a few fixes here and there won't harm. Cool | :cool:
 
Cheers
GeneralRe: When to expect an updated version?memberC a r l29 Mar '05 - 5:05 
The fix proposed in the forum seem to work...
 
--EDIT: I just found major problems implementing the proposed fix. I'll keep you posted.
 
--EDIT 2: The proposed fixes seem to work, except when filtering WM_LBUTTONUP. When I filter it, everything that is done upon leftclicking a button (pretty much everything is started by a left click!), the application wait cursor doesn't show up. So here are the fixes that I added to ApplicationWaitCursor.cs:
 

private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_RBUTTONUP = 0x0205;
private const int WM_CONTEXTMENU = 0x007B;
private const int WM_SYSKEYUP = 0x0105;
private const int WM_SYSKEYDOWN = 0x0104;
 
bool IMessageFilter.PreFilterMessage(ref Message m)
{
if (m.Msg == WM_NCLBUTTONDOWN ||
m.Msg == WM_LBUTTONDOWN ||
m.Msg == WM_RBUTTONUP ||
m.Msg == WM_CONTEXTMENU ||
m.Msg == WM_SYSKEYUP ||
m.Msg == WM_SYSKEYDOWN)
_cursor.Enabled = false;

else
_cursor.Enabled = true;
 
// Always let the real Message through
return false;
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 16 Mar 2005
Article Copyright 2005 by Steve Fillingham
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid