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();
// load image
HBITMAP hBmp = (HBITMAP)LoadImage( AfxGetInstanceHandle(),
"Rgn.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
// if fail - nothing to do
if ( hBmp == NULL ) return TRUE;
// create region, let the RED color be transparent
HRGN hRgn = CreateRgnFromFile( hBmp, RGB(255,0,0) );
// build memory dc for background
CDC* dc = GetDC();
m_dcBkGrnd = CreateCompatibleDC( dc->m_hDC );
ReleaseDC( dc );
// select background image
SelectObject( m_dcBkGrnd, hBmp );
// set window size the same as image size
SetWindowPos( NULL, 0, 0, m_dwWidth, m_dwHeight,
SWP_NOZORDER | SWP_NOMOVE );
// assign region to window
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
about it).