我使用这段代码来获取屏幕上的鼠标位置,它可以正常工作。我还获得了光标的宽度和高度。我需要的是在调用函数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);
}
}
}
CreateDC
/CreateCompatibleDC
/GetDC
。Windows GDI很棘手,但最终会让人感到合理。确保进行错误检查并一次处理一个问题,并且保持MSDN接近。 - tenfour