Visual C++ 7.1Visual C++ 7.0Windows 2003Windows 2000Visual C++ 6.0Windows XPMFCIntermediateDevVisual StudioWindowsC++
BitMap Contour To Windows Region
An article on how to generate an outline of a bitmap. Used when designing user shaped dialogs.
Introduction
The CBitmapHandling
class was designed to calculate the contour points in a bitmap. It looks at the bitmap and finds pixel points different from white, it then places these start and stop pixel points in a Vertex of CPoint
class. When it has found the outline of the bitmap, it then generates a Windows region. If you use this region in your OnInitDialog
and then set the window region using SetWindowRgn(m_WinRgn, TRUE )
, your window will then be shaped like the outline.
Using the code
The code consists of a header file and a CPP file.
// #include "BitMapHandling.h" using namespace HandlingBitmaps; BOOL CMyShapedWindowDlg::OnInitDialog() { CDialog::OnInitDialog(); VERIFY( SetWindowPos( NULL, 0, 0, m_nW, m_nH, SWP_NOMOVE | SWP_NOOWNERZORDER ) ); // size and pos. of window // cut of areas of region, which you do not really need. // fx. maybe you have bitmap buttons drawn under your bitmap window. CBitmapHandling bh; bh.BitMapContourToWinRgn(&m_WinRgn, IDB_BITMAP); VERIFY( SetWindowRgn(m_WinRgn , TRUE ) ); return TRUE; // return TRUE unless you set the focus to a control } //