c++ - How to change multiple cursors system-wide in Windows API
问题描述
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?
解决方案
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);
推荐阅读
- vue.js - 当子组件在视图中时,将 router-link-exact-active 添加到父组件
- c - 用标准 C 编写菜单的正确方法
- reactjs - 如何减少 Fabric UI 中链接组之间的间距
- flask - 从 SqlAlchemy_wtforms QuerySelectField 获取 id 不是值
- django - 如何通过外键创建模型实例
- python-3.x - 在 Python 中的 if 语句中调用函数
- mysql - 计算所有现有组合
- ada - 使用 Ravenscar 在嵌入式设备上执行多任务
- python - 要求为 Python 安装 JDK
- java - 计算出现次数。(初学者)