CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38

Thread: Controlling CWaitCursor from different methods

  1. #16
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by DP TWO
    Have you tried to NOT move the mouse until your anwer is received back in your dialog class? My theory is that in this case, you should have the hour glass until the answer processing is done (and Endwaitcursor is called). If that works, you need to handle WM_SETCURSOR in all your OTHER classes that might change the cursor, based on your desires originating from your dialog class. A possibly daunting task...
    I do not move it as much as I can, but for caliing the function I press a button, si I necessarily release the button, and maybe move it a bit...

    Marina
    Please go vote for your country!

  2. #17
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by Marina Vaillant
    Ok, I'll try this.
    I allocate the CWaitCursor * pWaitCursor in my beginning function.

    Then I make a SetCursor(WHAT?) ??

    And then to stop it, a SetCursor(WHAT?), or a Delete(pWaitcursor) ??
    Yes, you would delete it - but as said above, that's not the intended use of CWaitCursor. Instead of creating it with new and deleting it with delete, you might just as well use BeginWaitCursor() / EndWaitCursor() (that's what CWaitCursor does anyway). The only reason for using CWaitCursor at all is the (very common) situation where you would call BeginCursor() when entering a block and EndCursor() when leaving it. The only benefit in using CWaitCursor at all is that you don't need to remember to call EndWaitCursor() yourself. In your case (with begin/end required in different functions) there's simply no value in using CWaitCursor - just call BeginWaitCursor() / EndWaitCursor(), and you're done.

  3. #18
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by Marina Vaillant
    Don't you think Alin is right when s/he says that if another class or thread or whatever takes control of the Cursor, it gets back to normal even before my EndWaitCursor() is called ??
    Well...no...the wait cursor will be displayed until you call 'EndWaitCursor()'...unless someone else is changing the cursor...

  4. #19
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by Marina Vaillant
    Don't you think Alin is right when s/he says that if another class or thread or whatever takes control of the Cursor, it gets back to normal even before my EndWaitCursor() is called ??

    Marina
    I didn't really say that. I only wanted to say that setting/resetting of CWaitCursor should be done by your UI thread. This is what I was trying to get at.

  5. #20
    Join Date
    Aug 2002
    Location
    Covington, LA, USA
    Posts
    101

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by Andreas Masur
    Well...no...the wait cursor will be displayed until you call 'EndWaitCursor()'...unless someone else is changing the cursor...
    If I'm not mistaken, ANY UI class can set ANY cursor, regardless of what some other class might want to do, if you let it. There is only one cursor, and it takes the shape you tell it to, and stays that way until you (or someone else) tell it to be different. If you want it back to your own shape, you have to do it manually.

    I think there is some cursor manipulation going on somewhere that you don't know or think about. In principle, your code should work as you intended.
    "Soccer - it is not a matter of life and death - it's far more important than that" Bill Shankly

  6. #21
    Join Date
    Aug 2002
    Location
    Covington, LA, USA
    Posts
    101

    Re: Controlling CWaitCursor from different methods

    Quote Originally Posted by Marina Vaillant
    I do not move it as much as I can, but for caliing the function I press a button, si I necessarily release the button, and maybe move it a bit...

    Marina
    This got me thinking somewhat more. The sample I gave earlier deals with CMainFrame. What if CDialog does something under the hood that we haven't thought about? So, after spending most of the day on this thread, although I should be doing something way different (don't tell my boss!), here is a very simple solution, that makes sure your intention works (at least as long as the mouse is inside the dialog where your button to fire your message is):
    Simply handle WM_SETCURSOR in your dialog class and make sure that the default handler isn't called. Like this:
    Code:
    BOOL CYourDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {
    	// TODO: Add your message handler code here and/or call default
    
    	//return CDialog::OnSetCursor(pWnd, nHitTest, message); // Don't invoke this.
    	return TRUE; // Do this instead
    }
    It seems like CDialog sets the cursor by default, thus you need to block its default action. Why it is like this I don't know. Maybe someone else can elaborate more on that?

    Now code like this works:
    Code:
    void CYourDlg::OnBnClickedBtn1()
    {
    BeginWaitCursor(); // Or RestoreWaitCursor() for that matter
    }
    
    void CYourDlg::OnBnClickedBtn2()
    {
    EndWaitCursor();
    }
    Clicking one button shows hour glass, clicking another removes it. No need for any more complicated stuff than that. Of course, if you move the mouse to another dialog (which handles WM_SETCURSOR the default way), or some other GUI that specifies cursor, the cursor will change. I have tested this with 2 dialogs open, a view in between that doesn't change cursor, and moving from my dialog which handles WM_SETCURSOR to one that doesn't. Result: The cursor changes to arrow as I enter the dialog which doesn't override OnSetCursor...
    "Soccer - it is not a matter of life and death - it's far more important than that" Bill Shankly

  7. #22
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Thank you for spending so much time on this problem (hey, if it works you can write an article on this because it's missing!!
    Please go vote for your country!

  8. #23
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Thank you DP TWO, handling the WM_SETCURSOR seems to work.
    I'll have to do it in both my dialogs since I'll need to be able to make an hourglass on both dialogs...


    Thank you very much to the others who tried to help and made us move forward in finding the solution!!
    I can't rate all of you, Codeguru asks me to spread some rating around before rating you again ...

    Marina
    Please go vote for your country!

  9. #24
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Except that now... i don't see any cursor when it's not an hourglass...
    How do I set cursor manually to a normal cursor?

    Marina
    Please go vote for your country!

  10. #25
    Join Date
    Aug 2002
    Location
    Covington, LA, USA
    Posts
    101

    Re: Controlling CWaitCursor from different methods

    That was strange... Doesn't EndWaitCursor restore the default arrow? Could be some issues with dialog-focus? I don't know, but maybe if you have focus on your "other" dialog (the one which doesn't start Wait cursor), the EndWaitCursor called from the one which doesn't have focus, might not restore the cursor because it is on another dialog? I'm guessing, but if you can test and see if there are difference whether or not focus is on the dialog that started the hour glass when it's supposed to end, and we could work more on it from there. I'm not surprised if there are any un-desired side-effects by handling WM_SETCURSOR in the way I suggested. I don't get easily surprised when dealing with MFC...

    But, setting cursor manually is straight-forward. Example:
    Code:
    SetCursor(::LoadCursor(NULL,IDC_ARROW));
    Challenge is to find the best place to do it to ensure desired effect. You want to make sure this is not done if the desired cursor is the hour glass, in your case possibly determined by a completely different GUI class (ref. your two dialogs).
    "Soccer - it is not a matter of life and death - it's far more important than that" Bill Shankly

  11. #26
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Thank you!!!

    I was a bit mixed up for a while.
    I think I'm ok now... until I find some other problem with it.
    Explanation of my problem and solution.

    When my dialog was initialising, some actions were already done, the same actions that requested the use of an hourglass when done manually.
    So the dialog started with a cursor as an hourglass. And the EndWaitCursor() was only making the cursor disappear. So putting the SetCursor(::LoadCursor(NULL,IDC_ARROW)); right after the EndWaitCursor() restored it ok.
    Maybe since the cursor was never an arrow on this dialog, it could not find any restoration shape... ??

    It seems ok now. I still wonder why it started with an hourglass cursor since I put breakpoints on all my BeginWaitCursor() and it did not stop anywhere...

    Thank you
    Marina
    Please go vote for your country!

  12. #27
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Re: Controlling CWaitCursor from different methods

    Except I really need to know why it starts with an hourglass. Even when there is not treatment to do at the beginning, it starts with an hourglass. But then, since there is no reception of confirmation message, it stays like this for ever.
    Please go vote for your country!

  13. #28
    Join Date
    Aug 2002
    Location
    Covington, LA, USA
    Posts
    101

    Re: Controlling CWaitCursor from different methods

    Well, according to MSDN documentation of EndWaitCursor() it restores the PREVIOUS cursor, not necessarily the arrow. Since we have already blocked the default handling of WM_SETCURSOR, it could probably happen that there is no previous cursor to find in your case. That could be an explanation as to why you have to do the manual cursor selection after EndWaitCursor().

    The start up issue I don't understand if there are no calls to BeginWaitCursor(). How is your dialog invoked? Could it be that for instance the default handling of menu clicks displays a wait cursor for a while? Without us noticing it? Does your dialog take a long time to open?

    If this theory holds, it explains why it will stay with hour glass; We don't let the dialog use its own cursor, because we handle WM_SETCURSOR the way we do? Again, I'm guessing/shooting from the hip. Don't really know, but I've learned during this thread that there are stuff going on with cursors that is not necessarily easily appearant.
    "Soccer - it is not a matter of life and death - it's far more important than that" Bill Shankly

  14. #29
    Join Date
    Feb 2000
    Location
    Rennes, France
    Posts
    624

    Talking Re: Controlling CWaitCursor from different methods

    Well, ok, I solved this by setting the cursor to the arrow during the OnInitDialog, before any of the treatment may be done, then using BeginWaitCursor is some treatment is necessary.

    Then it stops when it receives confirmation, having the default one to get back to.
    And if no treatment is necessary, the cursor stays to what it is iset to during the OnInitDialog()!

    Marina
    Please go vote for your country!

  15. #30
    Join Date
    Aug 2002
    Location
    Covington, LA, USA
    Posts
    101

    Re: Controlling CWaitCursor from different methods

    Well, Marina, you seem to be a very good engineer; If you can't solve a problem, work around it and then move on. A strategy according to my heart... It was an interesting and chellenging problem, though. And no, there won't be any article. I won't risk exposing my shortcomings to such a broad audience. I really don't consider myself an expert to the level where I can start publishing articles on this subject. My field is actually in control theory. This UI programming is something I do only to let the people who use my company's real products a nice view of, and means of interacting with, the really interesting stuff of being able to make big boats stay on a certain spot and move in a controlled manner to another spot. It's called Dynamic Positioning. Look it up on Google for instance. That's really interesting.
    "Soccer - it is not a matter of life and death - it's far more important than that" Bill Shankly

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)