我使用此代码来获取鼠标在屏幕上的位置,并且可以正常工作.我也得到光标的宽度和高度.我需要的是在我调用函数GetIconInfo时出现的光标图标.在ii中,我具有ii.hbmColor和ii.hbmMask. hbmColor的值为0x0,hbmMask的值为0x2f0517f1.我可以从这两个指针中提取鼠标光标吗?
CURSORINFO cursorInfo = { 0 };
cursorInfo.cbSize = sizeof(cursorInfo);
HDC memoryDC = (HDC)malloc(100);
memset(memoryDC, 0x00, 100);
if (::GetCursorInfo(&cursorInfo)) {
ICONINFO ii = {0};
GetIconInfo(cursorInfo.hCursor, &ii);
BITMAP bm;
GetObject(ii.hbmMask,sizeof(BITMAP),&bm);
DeleteObject(ii.hbmColor);
DeleteObject(ii.hbmMask);
::DrawIcon(memoryDC, cursorInfo.ptScreenPos.x - ii.xHotspot, cursorInfo.ptScreenPos.y - ii.yHotspot, cursorInfo.hCursor);
for(int i = 0; i < bm.bmWidth; i++){
for(int j = 0; j < bm.bmHeight; j++){
COLORREF c = GetPixel(memoryDC, i, j);
printf("%x", c);
}
}
}
解决方法:
CURSORINFO cursorInfo = { 0 };
cursorInfo.cbSize = sizeof(cursorInfo);
if (::GetCursorInfo(&cursorInfo))
{
ICONINFO ii = {0};
GetIconInfo(cursorInfo.hCursor, &ii);
DeleteObject(ii.hbmColor);
DeleteObject(ii.hbmMask);
::DrawIcon(memoryDC, cursorPos.x - ii.xHotspot, cursorPos.y - ii.yHotspot, cursorInfo.hCursor);
}