65.9K
CodeProject is changing. Read more.
Home

BitMap Contour To Windows Region

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (12 votes)

Nov 26, 2003

CPOL
viewsIcon

94696

downloadIcon

1602

An article on how to generate an outline of a bitmap. Used when designing user shaped dialogs.

Sample screenshot

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
}
//