Dear friends,

I need a help with a Wait (Hour Glass) cursor. In my MFC program, I have the following code:

void CBookDoc::SomeMethod() 
{
	AfxGetApp()->DoWaitCursor(1); // display the hourglass cursor
...
// Some stuff is done
...
	AfxGetApp()->DoWaitCursor(-1); // -1->>remove the hourglass cursor
}

I wonder why the cursor never changes to show the hour glass?

Last week I had a major run in with that problem. Perhaps check out this link at www.cplusplus.com...

http://www.cplusplus.com/forum/windows/14189/

I know it doesn't sound like a cursor related thread, that was indeed the cause of the problem. I really can't help you with the issue from the standpoint of MFC because I don't know it or use it, but in nterms of the Win32 Api, your issue involves the cursor set into the Window Class Structure. Basically, to change the cursor you have to LoadCursor() the one you want, then SetClassLong() it into the WindowClass. Then you have to call SetCursor(). This sequence of operations will change the cursor for every window of the class. If for example its your main dialog and you don't anticipate having multiple instances of it running at the same time, then there is no problem. If you specifically want to only change the cursor for tye specific window, then you need in addition to handle the WM_SETCURSOR message.

That thread's pretty longish. If you want to cut right to the heart go to reply 16.

Frederick2 may well be right, though I would also look at more basic issues.

Getting an hour glass cursor using MFC is generally a simple case of declaring:

CWaitCursor myWaitCursor;

inside a method. The wait cursor is then displayed for the duration of that method. It is removed when the object is destroyed. Very little for you to do.
By calling DoWaitCursor(1) you increment a reference count on the cursor. I don't know if you are calling this elsewhere in your code, but is it possible that the count is getting out of synch and you are not controlling the cursor as you expect? Using CWaitCursor would avoid this.
Even more basic, I assume that you have tried adding Sleep(10000); between those cursor calls to ensure that your code isn't just running more quickly than you expect and the cursor change is too fast to be visible.

Thank you Frederick. But I really prefer to use MFC if possible.

Getting an hour glass cursor using MFC is generally a simple case of declaring:
CWaitCursor myWaitCursor;
inside a method. The wait cursor is then displayed for the duration of that method. It is removed when the object is destroyed. Very little for you to do.

Thank you. I like it very much. But because of some reason, the wait cursor still does not show up. What can the reason be?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.