Click here to Skip to main content
13,352,280 members (73,484 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 25 Nov 2003

BitMap Contour To Windows Region

, 16 Sep 2005
Rate this:
Please Sign up or sign in to vote.
An article on how to generate an outline of a bitmap. Used when designing user shaped dialogs.

Sample screenshot


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()
 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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) serupIT
Denmark Denmark
I have been working with languages ranging from assembly 68000 to COBOL, OOC, MySQL, Perl, Java 8, JavaScript, C#, C++17, VC++ MFC and WinSockets.

I am currently working as a freelance software developer

You may also be interested in...

Comments and Discussions

GeneralDemo Project Pin
gancev18-Apr-07 4:14
membergancev18-Apr-07 4:14 
GeneralBitmap Pin
Sangeetha_J25-Jan-07 21:17
memberSangeetha_J25-Jan-07 21:17 
Generalembedded systems Pin
jamal odibat18-Sep-05 22:05
memberjamal odibat18-Sep-05 22:05 
GeneralBetter solution Pin
serup31-Aug-05 3:15
memberserup31-Aug-05 3:15 
GeneralRe: Better solution Pin
serup31-Aug-05 3:35
memberserup31-Aug-05 3:35 
GeneralSome Bugs Pin
nebbi27-Jan-04 22:47
membernebbi27-Jan-04 22:47 
GeneralRe: Some Bugs Pin
serup28-Jan-04 21:32
memberserup28-Jan-04 21:32 
GeneralA guess (or two) at your low mark... Pin
Iain Clarke26-Nov-03 6:10
memberIain Clarke26-Nov-03 6:10 
GeneralRe: A guess (or two) at your low mark... Pin
Uwe Keim26-Nov-03 6:25
sitebuilderUwe Keim26-Nov-03 6:25 
GeneralRe: A guess (or two) at your low mark... Pin
Iain Clarke26-Nov-03 6:33
memberIain Clarke26-Nov-03 6:33 
I confess I haven't read it in a while (most of my development is paid for, so
not really "put-up-here"able). I remember thinking he went over the top in some
places, but at least people should _actively_ choose to disregard bits, rather
than just ignoring them...


GeneralRe: A guess (or two) at your low mark... Pin
serup27-Nov-03 4:38
memberserup27-Nov-03 4:38 
GeneralRe: A guess (or two) at your low mark... Pin
gordon8824-Jul-08 13:50
membergordon8824-Jul-08 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 16 Sep 2005
Article Copyright 2003 by serup
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid