Dave's Brain

Browse - Programming Tips - How can my Windows application display an hour glass.

Date: 2008mar8
Language: C/C++
Platform: win32
Keywords: hourglass

Q.  How can my Windows application display an hour glass.

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

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.