Date: 2008mar8
Language: C/C++
Platform: win32
Keywords: hourglass
Q. Win32: display an hour glass in my Windows application
A.
In a regular Win32 application use this function:
void SetHourGlass(const BOOL bWaiting)
{
static HCURSOR hHourGlass = NULL;
static HCURSOR hNorm = NULL;
if (bWaiting)
{
if (hHourGlass == NULL)
{
hHourGlass = LoadCursor(NULL, IDC_WAIT);
}
if (hHourGlass != NULL)
{
hNorm = SetCursor(hHourGlass);
}
}
else
{
if (hNorm != NULL)
{
SetCursor(hNorm);
}
}
}
Use it like this:
SetHourGlass(TRUE); // Turns on the hour glass
// Do a long task
SetHourGlass(FALSE); // Turns off the hour glass
In MFC use these methods:
BeginWaitCursor(); // Turns on the hour glass
// Do a long task
EndWaitCursor(); // Turns off the hour glass
A count of the number of times you have turned on/off the wait cursor
is kept. If you wish to override it do:
AfxGetApp()->DoWaitCursor(1); // Force an hour glass
// Do a long task
AfxGetApp()->DoWaitCursor(-1); // Force the hour glass to end