HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent) { HDC hdcMem; HDC hdcMem2; HBITMAP hbmMask; BITMAP bm; GetObject(hbmColour, sizeof(BITMAP), &bm); hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, nullptr); hdcMem = CreateCompatibleDC(nullptr); hdcMem2 = CreateCompatibleDC(nullptr); SelectObject(hdcMem, hbmColour); SelectObject(hdcMem2, hbmMask); SetBkColor(hdcMem, crTransparent); BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT); DeleteDC(hdcMem); DeleteDC(hdcMem2); //MessageBox(Handle_of_MainWindow, L"Created a bitmap mask", L"Created a bitmap mask", MB_OK | MB_ICONEXCLAMATION); return hbmMask; }
////// for ( iY = 0; iY < bmpInfo_001.bmHeight; iY++) ////// { ////// do ////// { ////// //skip over transparent pixels at start of lines. ////// while (iX < bmpInfo_001.bmWidth && GetPixel(hdcMem_001, iX, iY) == crTransparent) ////// { ////// iX++; ////// } ////// ////// //remember this pixel ////// int iLeftX = iX; ////// ////// //now find first non transparent pixel ////// while (iX < bmpInfo_001.bmWidth && GetPixel(hdcMem_001, iX, iY) != crTransparent) ////// { ////// ++iX; ////// } ////// ////// //create a temp region on this info ////// HRGN hRgnTemp = CreateRectRgn(iLeftX, iY, iX, iY+1); ////// ////// //combine into main region. ////// // int CombineRgn ////// // ( ////// // HRGN hrgnDst, // A handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn is called.) ////// // HRGN hrgnSrc1, // A handle to the first of two regions to be combined. ////// // HRGN hrgnSrc2, // A handle to the second of two regions to be combined. ////// // int iMode // A mode indicating how the two regions will be combined. ////// // ////// iRet = CombineRgn(hRgn_001, hRgn_001, hRgnTemp, RGN_OR); HBITMAP hSkinMBmp = NULL; iRet = CombineRgn(hRgn_001, hRgn_001, hBitmap_SOME_MASK_001, RGN_OR); if(iRet == ERROR) { return; } ////// ////// if(iRet == ERROR) ////// { ////// return; //////