' In answer to a Chris Boss challenge 
'
' This code allows you to convert a bitmap to a window region.
' It is based on the work from:
' Jean-Edouard Lachand-Robert
' Semen Matusovski
' Patrice Terrier
'
' The function could be used to build a region on the fly
'
------------------
Patrice Terrier
mailto
[email protected][email protected]</A>
http://www.zapsolution.com
Toolkit: WinLIFT (Skin Engine), GDI+ helper (Graphic package), dvBTree (Index manager)
Freeware: ZAP Audio Player, ZAP Picture Browser.
Artwork on demand.
[This message has been edited by Patrice Terrier (edited March 18, 2004).]

'
' This code allows you to convert a bitmap to a window region.
' It is based on the work from:
' Jean-Edouard Lachand-Robert
' Semen Matusovski
' Patrice Terrier
'
' The function could be used to build a region on the fly
'
Code:
FUNCTION ConvertBitmapToRgn& (BYVAL hBmp&, BYVAL TransColor&) EXPORT ' LOCAL bm AS BITMAP, rc AS RECT LOCAL bi AS BITMAPINFO, rdh AS RGNDATAHEADER PTR LOCAL os AS OSVERSIONINFO LOCAL lpRect AS RECT PTR ' MaxRegions& = 4000 ' IF hBmp& THEN CALL GetObject(hBmp&, SIZEOF(bm), bm) pWidth& = bm.bmWidth pHeight& = bm.bmHeight END IF ' hDC& = CreateIC ("DISPLAY", BYVAL %NULL, BYVAL %NULL, BYVAL %NULL) ' hMem1DC& = CreateCompatibleDC(hDC&) hMem2DC& = CreateCompatibleDC(hDC&) hTmpBmp& = CreateCompatibleBitmap(hDC&, pWidth&, pHeight&) CALL SelectObject(hMem1DC&, hBmp&) CALL SelectObject(hMem2DC&, hTmpBmp&) CALL BitBlt(hMem2DC&, 0, 0, pWidth&, pHeight&, hMem1DC&, 0, 0, %SRCCOPY) ' bi.bmiHeader.biSize = SIZEOF(bi.bmiHeader) bi.bmiHeader.biWidth = pWidth& bi.bmiHeader.biHeight = pHeight& bi.bmiHeader.biPlanes = 1 bi.bmiHeader.biBitCount = 32 bi.bmiHeader.biCompression = %BI_RGB ' hToDIB& = CreateDIBSection(hMem1DC&, bi, %DIB_RGB_COLORS, 0, 0, 0) ' CALL SelectObject(hMem1DC&, hToDIB&) CALL GetObject(hToDIB&, SIZEOF(bm), bm) CALL BitBlt(hMem1DC&, 0, 0, pWidth&, pHeight&, hMem2DC&, 0, 0, %SRCCOPY) ' REDIM Ar&(0) AT bm.bmBits: TT& = 0 ' ' Set up the transparent color IF TransColor& = -1 THEN T& = (Ar&((pHeight& - 1) * pWidth&) AND &HFFFFFF)'<--- (0, 0) ELSE T& = TransColor& ' Common Trancolor is magenta &HFF00FF END IF ' RegionData$ = STRING$(LEN(RGNDATAHEADER) + LEN(RECT) * MaxRegions&, 0) rdh = STRPTR(RegionData$) @rdh.nCount = MaxRegions& + 1 @rdh.dwSize = LEN(RGNDATAHEADER) @rdh.iType = %RDH_RECTANGLES @rdh.rcBound.nLeft = 0 @rdh.rcBound.nTop = 0 @rdh.rcBound.nRight = pWidth& @rdh.rcBound.nBottom = pHeight& FOR J& = 0 TO pHeight& - 1 TT& = pWidth& * (pHeight& - 1 - J&): M& = -1 FOR I& = 0 TO pWidth& IF I& = pWidth& THEN K& = T& ELSE K& = (Ar&(TT&) AND &HFFFFFF): INCR TT& IF K& <> T& THEN IF M& = -1 THEN M& = I& ELSEIF M& >= 0 THEN IF @rdh.nCount >= MaxRegions& THEN hRgn2& = ExtCreateRegion(BYVAL 0, LEN(RGNDATAHEADER) + (LEN(RECT) * @rdh.nCount), BYVAL rdh) IF hRgn1& = 0 THEN hRgn1& = hRgn2& ELSE CALL CombineRgn(hRgn1&, hRgn1&, hRgn2&, %RGN_OR) CALL DeleteObject(hRgn2&) END IF lpRect = LEN(RGNDATAHEADER) + rdh @rdh.nCount = 0 END IF INCR @rdh.nCount @lpRect.nLeft = M& @lpRect.nRight = I& @lpRect.nTop = J& @lpRect.nBottom = J& + 1 lpRect = lpRect + LEN(RECT) M& = -1 END IF NEXT NEXT hRgn2& = ExtCreateRegion(BYVAL 0, LEN(RGNDATAHEADER) + (LEN(RECT) * @rdh.nCount), BYVAL rdh) IF hRgn1& = 0 THEN hRgn1& = hRgn2& ELSE CALL CombineRgn(hRgn1&, hRgn1&, hRgn2&, %RGN_OR) CALL DeleteObject(hRgn2&) END IF ' CALL DeleteDC(hMem1DC&) CALL DeleteDC(hMem2DC&) CALL DeleteDC(hDC&) CALL DeleteObject(hTmpBmp&) CALL DeleteObject(hToDIB&) ' FUNCTION = hRgn1& ' END FUNCTION
------------------
Patrice Terrier
mailto

http://www.zapsolution.com
Toolkit: WinLIFT (Skin Engine), GDI+ helper (Graphic package), dvBTree (Index manager)
Freeware: ZAP Audio Player, ZAP Picture Browser.
Artwork on demand.
[This message has been edited by Patrice Terrier (edited March 18, 2004).]
Comment