HCURSOR QWindowsCursor::createPixmapCursor(const QPixmap &pixmap, int hotX, int hotY) { HCURSOR cur = 0; QBitmap mask = pixmap.mask(); if (mask.isNull()) { mask = QBitmap(pixmap.size()); mask.fill(Qt::color1); } HBITMAP ic = qt_pixmapToWinHBITMAP(pixmap, /* HBitmapAlpha */ 2); const HBITMAP im = qt_createIconMask(mask); ICONINFO ii; ii.fIcon = 0; ii.xHotspot = hotX; ii.yHotspot = hotY; ii.hbmMask = im; ii.hbmColor = ic; cur = CreateIconIndirect(&ii); DeleteObject(ic); DeleteObject(im); return cur; }
HICON QPixmap::toWinHICON() const { QBitmap maskBitmap = mask(); if (maskBitmap.isNull()) { maskBitmap= QBitmap(size()); maskBitmap.fill(Qt::color1); } ICONINFO ii; ii.fIcon = true; ii.hbmMask = qt_createIconMask(maskBitmap); ii.hbmColor = toWinHBITMAP(QPixmap::Alpha); ii.xHotspot = 0; ii.yHotspot = 0; HICON hIcon = CreateIconIndirect(&ii); DeleteObject(ii.hbmColor); DeleteObject(ii.hbmMask); return hIcon; }
static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy) { HCURSOR cur = 0; #if !defined(Q_WS_WINCE) QBitmap mask = pixmap.mask(); if (mask.isNull()) { mask = QBitmap(pixmap.size()); mask.fill(Qt::color1); } HBITMAP ic = pixmap.toWinHBITMAP(QPixmap::Alpha); HBITMAP im = qt_createIconMask(mask); ICONINFO ii; ii.fIcon = 0; ii.xHotspot = hx; ii.yHotspot = hy; ii.hbmMask = im; ii.hbmColor = ic; cur = CreateIconIndirect(&ii); DeleteObject(ic); DeleteObject(im); #elif defined(GWES_ICONCURS) QImage bbits, mbits; bool invb, invm; bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono); mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono); invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); int sysW = GetSystemMetrics(SM_CXCURSOR); int sysH = GetSystemMetrics(SM_CYCURSOR); int sysN = qMax(1, sysW / 8); int n = qMax(1, bbits.width() / 8); int h = bbits.height(); uchar* xBits = new uchar[sysH * sysN]; uchar* xMask = new uchar[sysH * sysN]; int x = 0; for (int i = 0; i < sysH; ++i) { if (i >= h) { memset(&xBits[x] , 255, sysN); memset(&xMask[x] , 0, sysN); x += sysN; } else { int fillWidth = n > sysN ? sysN : n; uchar *bits = bbits.scanLine(i); uchar *mask = mbits.scanLine(i); for (int j = 0; j < fillWidth; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) b ^= 0xFF; if (invm) m ^= 0xFF; xBits[x] = ~m; xMask[x] = b ^ m; ++x; } for (int j = fillWidth; j < sysN; ++j ) { xBits[x] = 255; xMask[x] = 0; ++x; } } } cur = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH, xBits, xMask); #else Q_UNUSED(pixmap); Q_UNUSED(hx); Q_UNUSED(hy); #endif return cur; }