如何获取鼠标光标图标VS c ++ [英] How to get mouse cursor icon VS c++

查看:694
本文介绍了如何获取鼠标光标图标VS c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这段代码来获得鼠标在屏幕上的位置,它的工作。我也得到光标的宽度和高度。我需要的是光标图标在我调用函数GetIconInfo的时刻。在ii中有ii.hbmColor和ii.hbmMask。 hbmColor的值为0x0,hbmMask为0x2f0517f1。我可以从这两个指针中提取鼠标光标吗?

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. In ii iI have ii.hbmColor and ii.hbmMask. Value of hbmColor is 0x0, hbmMask is 0x2f0517f1. Can I extract mouse cursor from that two pointer and how?

  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);
  }

这篇关于如何获取鼠标光标图标VS c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆