One trick I use if your programming in C++ is to use a wait cursor object
like so...
class CWaitCursor
{
public:
CWaitCursor();
~CWaitCursor();
protected:
HCURSOR m_hCursor;
};
CWaitCursor::CWaitCursor()
{
m_hCursor = ::SetCursor(LoadCursor(NULL,IDC_WAIT));
}
CWaitCursor::~CWaitCursor()
{
::SetCursor(m_hCursor);
}
this way you can just create a CWaitCursor object off the state at the
begining of your function call and it will be destroyed automatically
at the end.
--
.__o Ed McCreary "The Information Superhighway, sanitized
_-\ <,- Compaq Computers for your protection."
(*)/ (*) e...@twisto.compaq.com
In letter
>From: e...@gocart.eng.hou.compaq.com (Ed McCreary)
>In-Reply-To: b...@tcomeng.com's message of 19 Jan 1995 10:03:50 -0800
>Date: Mon, 23 Jan 95 15:25:36 GMT
was written
>
> Ernest Crvich (ecr...@vt.edu) wrote:
> : I've looked high and low for a way to change the mouse pointer to the
> : hourglass and back again, but have had no luck. I'm using BC++. How?
>
>One trick I use if your programming in C++ is to use a wait cursor object
>like so...
>
>class CWaitCursor
>{
>public:
> CWaitCursor();
> ~CWaitCursor();
>protected:
> HCURSOR m_hCursor;
>};
>
>CWaitCursor::CWaitCursor()
>{
> m_hCursor = ::SetCursor(LoadCursor(NULL,IDC_WAIT));
>}
>
>CWaitCursor::~CWaitCursor()
>{
> ::SetCursor(m_hCursor);
>}
>
But in the Windows SDK v3.1 for function SetCursor() is written:
A window should set the cursor only when the cursor is in the window's
client area or when the window is capturing all mouse input.
So, when I used such class there were a lot of situations, when
original cursor was not restored (it was restored, when mouse is moving).
I suggest follow class to set busy-wait mouse pointer:
----------------------------------------------------------------------------
#ifndef _WAITCURSOR_H
#define _WAITCURSOR_H
// Special class to change current Cursor shape to IDC_WAIT
// It allows do not forget ReleaseCapture!
class CWaitCursor
{
protected:
BOOL m_Started;
HCURSOR m_hCursor; // Save cursor
HWND m_hWnd; // Current window
HWND m_hCapWnd; // Previous captured window
public:
void Init( HWND hWnd = NULL, HCURSOR hCursor = NULL )
{
if( m_Started )
EndWaitCursor();
if( hWnd == NULL )
hWnd = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
if( hCursor == NULL )
hCursor = ::LoadCursor( NULL, IDC_WAIT );
if( hWnd == NULL || hCursor == NULL )
return;
m_Started = TRUE;
m_hCapWnd = SetCapture( m_hWnd = hWnd );
m_hCursor= SetCursor( hCursor );
};
void EndWaitCursor()
{
if( m_Started )
{
SetCursor( m_hCursor );
if( m_hCapWnd == NULL )
ReleaseCapture();
else
SetCapture( m_hCapWnd );
m_Started = FALSE;
}
}
CWaitCursor( HWND hWnd = NULL, HCURSOR hCursor = NULL,
BOOL Start = TRUE ) : m_Started( FALSE )
{ if( Start ) Init( hWnd, hCursor ); }
CWaitCursor( HWND hWnd, BOOL Start ) : m_Started(FALSE)
{ if( Start ) Init( hWnd ); }
CWaitCursor( BOOL Start ) : m_Started(FALSE)
{ if( Start ) Init(); }
~CWaitCursor() { EndWaitCursor(); }
};
#endif
-----------------------------------------------------------------------------
This class works fine and allows nested calls, but there is no function
RestoreWaitCursor(). It is useful function for the WinExec() function.
I do not understand exactly why, but I should use follows code:
[...]
CWaitCursor WaitCursor;
AfxGetApp()->BeginWaitCursor();
UINT rc = WinExec(...);
if( rc < 32 )
{
[...] // error
}
AfxGetApp()->RestoreWaitCursor();
[...] // Wait task will finish, Yield and RestoreWaitCursor()!
AfxGetApp()->EndWaitCursor();
[...]
May be there is not necessary functions BeginWaitCursor() and EndWaitCursor()
from MFC library and function RestoreWaitCursor() can be implemented as:
static CWaitCursor::RestoreWaitCursor()
{
::SetCursor( ::LoadCursor( NULL, IDC_WAIT ) );
}
Best regards,
--
Konstantin L. Topanov
tel. 863-2-64-98-00, RMTS, Rostov-na-Donu, RUSSIA
>CWaitCursor::~CWaitCursor()
>{
> ::SetCursor(m_hCursor);
>}
OTOH, if your function calls contain explicit or implicit calls to GetMessage
or other potentially task-switching functions (for example, using WinSock
functions does this implicitly), you may lose your hourglass anyway.
One solution is to respond to WM_SETCURSOR (OnSetCursor in MFC)...
Later,
Kit Kauffmann - ki...@mudshark.sunquest.com
AKA 73363,447 (Compu$erve)
Finger me for my public key
: > Ernest Crvich (ecr...@vt.edu) wrote:
: > : I've looked high and low for a way to change the mouse pointer to the
: > : hourglass and back again, but have had no luck. I'm using BC++. How?
: >One trick I use if your programming in C++ is to use a wait cursor object
: >like so...
[C++ code removed]
: OTOH, if your function calls contain explicit or implicit calls to GetMessage
: or other potentially task-switching functions (for example, using WinSock
: functions does this implicitly), you may lose your hourglass anyway.
: One solution is to respond to WM_SETCURSOR (OnSetCursor in MFC)...
I have got this problem. I posted the following question in the powerbuilder
group:
----------
Hello,
I'm using Power Builder 3.0a. My application calls a third party
DLL. The DLL performs communcation tasks, and waits a few seconds
for data.
During that time, the DLL somehow returns control to Windows,
however the script that called the DLL does not return until
the DLL received data and returns control to the script.
Before calling the DLL the script sets the mouse-pointer to an
hourglass. However, as soon as the DLL returns control to Windows
(not my script), the pointer changes back to an arrow.
Any ideas how to prevent this?
-----------
Responding to WM_SETCURSOR may be the solution.
Questions: When do I receive the event?
Does it have implications for the cursor in other applications?
Thanks, Sietse.
--
_
Sietse Visser | sie...@vogon1.xs4all.nl
`--+--O--+--'
Standards are good... o o Everybody should have one!
WM_SETCURSOR is your answer. This message is sent to any window over which
the mouse passes. Your window's message handler intercepts this message then
calls SetCursor() to the the hourglass cursor when you need it. In MFC, the
message handler is OnSetCursor(). The mouse then changes to the hourglass
cursor only when it passes over that window.
Peter.
--
Peter C. Jahans mailto:jah...@corte-madera.geoquest.slb.com
Corte Madera, CA telephone:415-927-6229
This works for me:
HCURSOR pCursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
//-- long bit of processing goes here
SetCursor(pCursorOld);
Jussi Jumppanen "If you've got to code, do it with Zeus."
ju...@sydney.dialix.oz.au