Introduction
This very simple function creates a region from a bitmap (.bmp) file. 8, 16, 24 and 32 bit color modes are supported.
The function takes two parameters:
hBmp
- a handle to the bitmap image color
- transparent color
HRGN CreateRgnFromFile( HBITMAP hBmp, COLORREF color );
Using the function is very simple. For example, if you wish to set the window shape of your dialog, then in your OnInitDialog
handler, do this:
BOOL CFileRgnDlg::OnInitDialog()
{
CDialog::OnInitDialog();
HBITMAP hBmp = (HBITMAP)LoadImage( AfxGetInstanceHandle(),
"Rgn.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
if ( hBmp == NULL ) return TRUE;
HRGN hRgn = CreateRgnFromFile( hBmp, RGB(255,0,0) );
CDC* dc = GetDC();
m_dcBkGrnd = CreateCompatibleDC( dc->m_hDC );
ReleaseDC( dc );
SelectObject( m_dcBkGrnd, hBmp );
SetWindowPos( NULL, 0, 0, m_dwWidth, m_dwHeight,
SWP_NOZORDER | SWP_NOMOVE );
SetWindowRgn( hRgn, FALSE );
return TRUE;
}
History
- December 08, 2001
- Cut & paste bug for 16-bit mode (white color as transparent did not work)
- Pixels in a last column has not been used
- Now you can use non-aligned (by width) images
- June 11, 2001
ExtCreateRegion
NT-problem (personal thanks to Martin for reporting it)
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.