How to get mouse cursor icon VS c++

前端 未结 2 1714
后悔当初
后悔当初 2020-12-21 00:37

I use this code to get mouse position on screen and it\'s working. I also get cursor width and height. What I need is cursor icon in the moment I call function GetIconInfo.

相关标签:
2条回答
  • 2020-12-21 01:06

    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.

    0 讨论(0)
  • 2020-12-21 01:14
      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);
      }
    
    0 讨论(0)
提交回复
热议问题