by Fenton Webb
Sometimes, you want to tell the user that your application is busy and what better way to do that then with an Hour Glass wait cursor… Obviously, you can create your own custom cursor and display it using the same technique…
Here’s how:
//////////////////////////////////////////////////////////////////////////
static HHOOK MyHook;
static HCURSOR hWaitCursor;
//////////////////////////////////////////////////////////////////////////
static LRESULT CALLBACK MyMsgProc (int nCode, WPARAM wParam, LPARAM lParam);
//////////////////////////////////////////////////////////////////////////
// This is command ‘WAITCURSOR, by Fenton Webb [14/10/2004], DevTech, Autodesk
void asdkWaitCursor()
{
// load the Wait cursor
hWaitCursor = LoadCursor(NULL, IDC_WAIT);
// and set it
HCURSOR hCursor = SetCursor(hWaitCursor);
// now set a hook so we can constantly keep our cursor set
MyHook = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)MyMsgProc, (HINSTANCE)
NULL, GetCurrentThreadId ());
// now do the wait intensive task…
ACHAR cResult [256];
acedGetString (0, _T("\nPretending to wait : "), cResult);
// and finally clean up
UnhookWindowsHookEx (MyHook) ;
SetCursor (hCursor) ;
}
//////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK MyMsgProc (int nCode, WPARAM wParam, LPARAM lParam)
{
// forward the other hook calls
if ( nCode < 0 )
return (CallNextHookEx(MyHook, nCode, wParam, lParam));
LRESULT ret = CallNextHookEx(MyHook, nCode, wParam, lParam);
// keep updating our cursor type
SetCursor (hWaitCursor);
return (ret) ;
}

Leave a Reply to Alexander RivilisCancel reply