鼠标光标的位图 [英] Mouse cursor bitmap

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

问题描述

我试图摆脱鼠标光标的位图,但旁边code,我只是无法得到的颜色。

 关于cursorinfo cursorinfo段= {0};
cursorInfo.cbSize = sizeof的(cursorinfo段);如果(GetCursorInfo(安培;关于cursorinfo)){    ICONINFO II = {0};
    INT p值=的GetIconInfo(cursorInfo.hCursor,和II);    //获取屏幕
    HDC直流=的GetDC(NULL);
    HDC memDC = CreateCompatibleDC(DC);
    //选择对象(memDC,ii.hbmColor);    INT计数器= 0;    //
    字节*位[1000]; // =新的字节[W * 4];
    BITMAPINFO BMI;
    memset的(安培; BMI,0,sizeof的(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof的(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = 16;
    bmi.bmiHeader.biHeight = 16;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biCom pression = BI_RGB;
    bmi.bmiHeader.biSizeImage = 0;
    bmi.bmiHeader.biXPelsPerMeter = 0;
    bmi.bmiHeader.biYPelsPerMeter = 0;
    bmi.bmiHeader.biClrUsed = 0;
    bmi.bmiHeader.biClrImportant = 0;
    INT RV = ::的GetDIBits(memDC,ii.hbmColor,0,1,(无效**)及位和放大器; BMI,DIB_RGB_COLORS);
}


解决方案

通过获取位图的参数记录由Windows启动:

  BITMAP位= {0};
GetObject的(ii.hbmColor,sizeof的(位图),和放大器;位图);

您可以使用返回值来填充 BMI 结构。

和有关 BMI 结构: BITMAPINFO 做的不可以预留足够空间调色板。您应该创建自己的结构是:

 结构BitmapPlusPalette
{
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD调色板[256];
};

计算所需的位图的字节数是有点棘手,因为它需要四舍五入:

  W =((bitmap.bmWidth * bitmap.bmBitsPixel)+ 31)/ 8;
BYTE *位=新的字节[W * bitmap.bmHeight]。

和这里是你的最后一行的一个修正版本:

  INT RV = ::的GetDIBits(DC,ii.hbmColor,0,bitmap.bmHeight,位(BITMAPINFO *)及BMI,DIB_RGB_COLORS);

I am trying to get bitmap from mouse cursor, but with next code, i just can't get colors.

CURSORINFO cursorInfo = { 0 };
cursorInfo.cbSize = sizeof(cursorInfo);

if (GetCursorInfo(&cursorInfo))  {

    ICONINFO ii = {0};
    int p = GetIconInfo(cursorInfo.hCursor, &ii);

    // get screen
    HDC dc = GetDC(NULL);
    HDC memDC = CreateCompatibleDC(dc);
    //SelectObject(memDC, ii.hbmColor);

    int counter = 0;

    //
    byte* bits[1000];// = new byte[w * 4]; 
    BITMAPINFO bmi;
    memset(&bmi, 0, sizeof(BITMAPINFO)); 
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = 16;
    bmi.bmiHeader.biHeight = 16;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biSizeImage     = 0;
    bmi.bmiHeader.biXPelsPerMeter = 0;
    bmi.bmiHeader.biYPelsPerMeter = 0;
    bmi.bmiHeader.biClrUsed       = 0;
    bmi.bmiHeader.biClrImportant  = 0;
    int rv = ::GetDIBits(memDC, ii.hbmColor, 0, 1, (void**)&bits, &bmi, DIB_RGB_COLORS);
}

解决方案

Start by getting the parameters of the bitmap as recorded by Windows:

BITMAP bitmap = {0};
GetObject(ii.hbmColor, sizeof(bitmap), &bitmap);

You can use the returned values to populate the bmi structure.

And about the bmi structure: BITMAPINFO does not reserve enough space for a palette. You should create your own structure for this:

struct BitmapPlusPalette
{
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD palette[256];
};

Calculating the number of bytes needed for the bitmap is a bit tricky because it needs to be rounded up:

w = ((bitmap.bmWidth * bitmap.bmBitsPixel) + 31) / 8;
byte* bits = new byte[w * bitmap.bmHeight];

And here's a corrected version of your final line:

int rv = ::GetDIBits(dc, ii.hbmColor, 0, bitmap.bmHeight, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS);

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

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