Reputation: 79
I'm trying to replace multiple system cursors using SetSystemCursor
. My first call changes the cursor of OCR_NORMAL
but the subsequent calls are not working.
HCURSOR hWaitCur = LoadCursor(NULL, IDC_WAIT);
HCURSOR cursorCopy = CopyCursor(hWaitCur);
SetSystemCursor(cursorCopy, OCR_NORMAL); // This works
// Not working
SetSystemCursor(cursorCopy, OCR_APPSTARTING);
SetSystemCursor(cursorCopy, OCR_CROSS);
SetSystemCursor(cursorCopy, OCR_HAND);
SetSystemCursor(cursorCopy, OCR_HELP);
SetSystemCursor(cursorCopy, OCR_IBEAM);
SetSystemCursor(cursorCopy, OCR_NO);
SetSystemCursor(cursorCopy, OCR_WAIT);
What would be the correct way to update multiple system cursors at once?
Upvotes: 1
Views: 254
Reputation: 8598
From the docs (emphasize by me):
The system destroys hcur by calling the DestroyCursor function. Therefore, hcur cannot be a cursor loaded using the LoadCursor function. To specify a cursor loaded from a resource, copy the cursor using the CopyCursor function, then pass the copy to SetSystemCursor.
So you need to copy it before each call:
SetSystemCursor(CopyCursor(hWaitCur), OCR_NORMAL);
SetSystemCursor(CopyCursor(hWaitCur), OCR_APPSTARTING);
SetSystemCursor(CopyCursor(hWaitCur), OCR_CROSS);
SetSystemCursor(CopyCursor(hWaitCur), OCR_HAND);
SetSystemCursor(CopyCursor(hWaitCur), OCR_HELP);
SetSystemCursor(CopyCursor(hWaitCur), OCR_IBEAM);
SetSystemCursor(CopyCursor(hWaitCur), OCR_NO);
SetSystemCursor(CopyCursor(hWaitCur), OCR_WAIT);
Upvotes: 3
Reputation: 79
I've found the solution.
Since SetSystemCursor
destroys cursorCopy
after setting, there is a need to recopy hWaitCur
for every call.
/* ... */
HCURSOR cursorCopy = CopyCursor(cursor);
SetSystemCursor(cursorCopy, OCR_APPSTARTING);
cursorCopy = CopyCursor(cursor);
SetSystemCursor(cursorCopy, OCR_NORMAL);
cursorCopy = CopyCursor(cursor);
SetSystemCursor(cursorCopy, OCR_CROSS);
/* ... */
Upvotes: 1