Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

BitMap Contour To Windows Region

0.00/5 (No votes)
16 Sep 2005 1  
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

}
//

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