本文整理汇总了C++中QPixmap::toPmHBITMAP方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::toPmHBITMAP方法的具体用法?C++ QPixmap::toPmHBITMAP怎么用?C++ QPixmap::toPmHBITMAP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::toPmHBITMAP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toPmHPOINTER
// static
HPOINTER QPixmap::toPmHPOINTER(const QIcon &icon, bool isPointer,
int hotX, int hotY, bool embedRealAlpha,
bool isMini)
{
if (icon.isNull())
return NULLHANDLE;
// get the system icon size
int w = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CXPOINTER : SV_CXICON);
int h = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CYPOINTER : SV_CYICON);
if (!isPointer && isMini) {
w = w / 2;
h = h / 2;
}
// obtain the closest (but never larger) icon size we have
QSize size = icon.actualSize(QSize(w, h));
QPixmap pm = icon.pixmap(size);
if (pm.isNull())
return NULLHANDLE;
// if we got a smaller pixmap then center it inside the box matching the
// system size instead of letting WinCreatePointerIndirect() scale (this
// covers a usual case when we get 32/16 px pixmaps on a 120 DPI system
// where the icon size is 40/20 px respectively): scaling such small images
// looks really ugly.
if (!pm.isNull() && (pm.width() < w || pm.height() < h)) {
Q_ASSERT(pm.width() <= w && pm.height() <= h);
QPixmap pmNew(w, h);
pmNew.fill(Qt::transparent);
QPainter painter(&pmNew);
int dx = (w - pm.width()) / 2;
int dy = (h - pm.height()) / 2;
painter.drawPixmap(dx, dy, pm);
pm = pmNew;
hotX += dx;
hotY += dy;
}
POINTERINFO info;
info.fPointer = isPointer;
info.xHotspot = hotX;
info.yHotspot = pm.height() - hotY - 1;
info.hbmColor = pm.toPmHBITMAP(&info.hbmPointer, embedRealAlpha);
info.hbmMiniPointer = NULLHANDLE;
info.hbmMiniColor = NULLHANDLE;
HPOINTER hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &info);
GpiDeleteBitmap(info.hbmPointer);
GpiDeleteBitmap(info.hbmColor);
return hIcon;
}