5

我使用此代码在屏幕上获取鼠标位置并且它正在工作。我还得到了光标的宽度和高度。我需要的是在我调用函数 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);

        }
    }
  }
4

2 回答 2

2
  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);
  }
于 2010-08-18T07:51:38.877 回答
-2

the cursor informations are formatted like explained here : http://www.daubnet.com/en/file-format-cur

you have to get each pixel from each bit of the data buffer, and not from each byte, so 1 byte = 8 pixels. Also, be careful with some applications wich may have special sized cursors (not multiple of 8), like 26x23 In this case you'll have to ignore the last bits of each line. with a line of 26 pixels, you'll get 4 bytes, you'll read the first 3 bytes to get the 24 first pixels, and then read 2 bits of the 4th byte to get the last 2 pixels, and then ignore the last 6 bits before jumping to the next line.

于 2011-05-13T13:09:01.657 回答