diff --git a/src/winextras/qwinfunctions.cpp b/src/winextras/qwinfunctions.cpp index 3a2655101193ea4282b5b798a40417cc5081bfd1..ac68967f1d40ecc752b79bcde9d5213f12d54caf 100644 --- a/src/winextras/qwinfunctions.cpp +++ b/src/winextras/qwinfunctions.cpp @@ -207,6 +207,34 @@ HRGN QWinExtras::toHRGN(const QRegion ®ion) return resultRgn; } +/*! + \since 5.2 + + Returns a QRegion that is equivalent to the given \a hrgn. + */ +QRegion QWinExtras::fromHRGN(HRGN hrgn) +{ + DWORD regionDataSize = GetRegionData(hrgn, 0, NULL); + if (regionDataSize == 0) + return QRegion(); + + LPRGNDATA regionData = (LPRGNDATA)malloc(regionDataSize); + if (!regionData) + return QRegion(); + + QRegion region; + if (GetRegionData(hrgn, regionDataSize, regionData) == regionDataSize) { + LPRECT pRect = (LPRECT)regionData->Buffer; + for (DWORD i = 0; i < regionData->rdh.nCount; ++i) + region += QRect(pRect[i].left, pRect[i].top, + pRect[i].right - pRect[i].left, + pRect[i].bottom - pRect[i].top); + } + + free(regionData); + return region; +} + /*! \since 5.2 diff --git a/src/winextras/qwinfunctions.h b/src/winextras/qwinfunctions.h index c77fea0f404c57129ef85f9cd725f2e74303bc91..11a971c4fb432d10c9c2a885446ef9071d40d8eb 100644 --- a/src/winextras/qwinfunctions.h +++ b/src/winextras/qwinfunctions.h @@ -77,6 +77,7 @@ HICON Q_WINEXTRAS_EXPORT toHICON(const QPixmap &p); QImage Q_WINEXTRAS_EXPORT imageFromHBITMAP(HDC hdc, HBITMAP bitmap, int width, int height); QPixmap Q_WINEXTRAS_EXPORT fromHICON(HICON icon); HRGN Q_WINEXTRAS_EXPORT toHRGN(const QRegion ®ion); +QRegion Q_WINEXTRAS_EXPORT fromHRGN(HRGN hrgn); QString Q_WINEXTRAS_EXPORT stringFromHresult(HRESULT hresult); QString Q_WINEXTRAS_EXPORT errorStringFromHresult(HRESULT hresult); @@ -252,6 +253,7 @@ HICON toHICON(const QPixmap &p); QImage imageFromHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h); QPixmap fromHICON(HICON icon); HRGN toHRGN(const QRegion ®ion); +QRegion fromHRGN(HRGN hrgn); QString stringFromHresult(HRESULT hresult); QString errorStringFromHresult(HRESULT hresult); QColor colorizationColor(bool *opaqueBlend = 0);