Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I have used wait cursor in my application until some processing finish, problem is still i can able to click the button..

I dont want button to be disabled and clicked during waitcursor comes.
Please help me with this.

Thnks.
Posted

Wait cursor is just an indication to show that something is going on. It won't stop any action.
 
Share this answer
 
Disabling the button is the only neat solution. However you have also two (ugly) alternatives:
  • In the button click handler, if you are in 'wait cursor' state then do nothing.
or
  • Make a owner drawn button, and represent the disabled state with the same image used for the active one.
 
Share this answer
 
Comments
bunathangaraj 25-Aug-11 6:56am    
I want to know how to make a "owner drawn button" .. entirely new thing for me ..
Pls ..
CPallini 25-Aug-11 6:59am    
There are a lot of articles about, here at CodeProject:
http://www.codeproject.com/search.aspx?q=Owner+draw+buttons&x=0&y=0&sbo=kw
Simon Bang Terkildsen 25-Aug-11 7:03am    
+5, disabling the button is the way to go, as for the (ugly) alternatives, they are very ugly :D
Philippe Mori 25-Aug-11 20:14pm    
I woun't not recommend doing an owner draw button for that. It is much simpler to simply ignore clicks. If fact, it never hurt to do so but you should not typically depend on "wait state" for that but an indicator specific for your task. That way, it is easier to modify the UI (wait cursor and/or disabling and/or progress bar...) depending on preliminary test on execution time.
It is possible to perform mouse operations even though it shows wait cursor.
So you have to handle the button click according to your situation.
 
Share this answer
 
v2
A wait cursor may indicate a running process but still allow interaction. E. g. for some operations it might be desirable for the user to be able to cancel the operation, so the [cancel] button should still be active. Therefore changing your cursor to a wait cursor should not (and does not) block all input. It is your task to disable all components that the user should not interact with during processing.

A common method to prevent user interaction during a process is show a dialog using the DoModal() function and maybe show the progress of your operation on that dialog. The DoModal() function opens the dialog in modal mode, preventing all input to the rest of the application. You can then put a [cancel] button on that dialog if your users are allowed to do that, or buttons for any other interactions that you still allow, but anything else will be blocked.
 
Share this answer
 
Just construct an instance of CSafeWaitCursor
at the begining of your OnClick()-reaction :) :
C++
class CYourApp : public CWinApp
{
  bool  m_bShielded;
  //...
public:
  //...
  void SetShielded(bool bSet) { m_bShielded = bSet; }
  bool IsShielded() const { return m_bShielded; }
};

/*virtual*/ BOOL CYourApp::PreTranslateMessage(MSG* pMsg)
{
  if (IsShielded()) {
    if ((pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST) ||
        (pMsg>= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)) {
      return TRUE;
    }
  }
  return CWinApp::PreTranslateMessage(pMsg);
}

class CSafeWaitCursor
{
public:
  CSafeWaitCursor()
  {
    CYourApp* pcApp = (CYourApp*) AfxGetApp();
    pcApp->SetShielded(true);
    pcApp->DoWaitCursor(1);
  }
  ~CSafeWaitCursor()
  {
    CYourApp* pcApp = (CYourApp*) AfxGetApp();
    pcApp->SetShielded(false);
    pcApp->DoWaitCursor(-1);
  }
};
 
Share this answer
 
Comments
Philippe Mori 25-Aug-11 20:01pm    
The problem with that solution is that if there is a "Cancel" button, you won't be able to click on it... and it might be a bit too drastic like preventing the windows from being moved by the mouse...)
Problem : If your application consists of multiple buttons, disabling all the controls might not be good idea.

Temp Solution : We can create a new empty form with no borders, titles etc and having an opacity of 10-20% and then when wait cursor is getting called at the same time we can open this form.
We can close the form along with the wait cursor.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 4-Apr-13 9:55am    
Please check the date of the question before posting an answer. If it is really old (in this case 1.5 years), and it has acceptable solutions it doesn't really need another new answer.
mohitsharma779 4-Apr-13 9:57am    
Actually I am facing same problem and I thought someone would correct me and give a better solution.
Point taken, I forgot to see the date of the post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900