我使用此代码来获得鼠标在屏幕上的位置,它的工作。我也得到光标的宽度和高度。我需要的是当我调用函数GetIconInfo时的光标图标。 ii ii我有ii.hbmColor和ii.hbmMask。 hbmColor的值是0x0,hbmMask是0x2f0517f1。我能从这两个指针中提取鼠标光标吗?如何获取鼠标光标图标VS C++
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);
}
}
}
哇,你不能只是随机存储器作为一个HDC。你需要'CreateDC' /'CreateCompatibleDC' /'GetDC'。 Windows GDI很难习惯,但最终它是有意义的。 确保您一次执行一个错误检查并处理问题,并保持MSDN密切关注。 – tenfour 2010-08-18 16:02:57
@tenfour:当我看到那个时,我的眼睛突然出现。高兴地说,我戴眼镜... – peterchen 2010-08-18 17:48:25
有点帮助吗?一些例子? – Nikola 2010-08-18 18:18:25