Click here to Skip to main content
Licence CPOL
First Posted 25 Nov 2003
Views 72,050
Bookmarked 27 times

BitMap Contour To Windows Region

By | 16 Sep 2005 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

serup

Software Developer (Senior)
Nokia
Denmark Denmark

Member

(BS.E.E)
I have been working with languages ranging from assembly 68000 to COBOL, OOC, MySQL, Perl, VC++ MFC and WinSockets.
 
I am currently working as a senior software architect at Nokia Mobile Phones Denmark

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDemo Project Pinmembergancev3:14 18 Apr '07  
GeneralBitmap PinmemberSangeetha_J20:17 25 Jan '07  
Generalembedded systems Pinmemberjamal odibat21:05 18 Sep '05  
GeneralBetter solution Pinmemberserup2:15 31 Aug '05  
GeneralRe: Better solution Pinmemberserup2:35 31 Aug '05  
GeneralSome Bugs Pinmembernebbi21:47 27 Jan '04  
GeneralRe: Some Bugs Pinmemberserup20:32 28 Jan '04  
GeneralA guess (or two) at your low mark... PinmemberIain Clarke5:10 26 Nov '03  
GeneralRe: A guess (or two) at your low mark... PinsitebuilderUwe Keim5:25 26 Nov '03  
GeneralRe: A guess (or two) at your low mark... PinmemberIain Clarke5:33 26 Nov '03  
GeneralRe: A guess (or two) at your low mark... Pinmemberserup3:38 27 Nov '03  
GeneralRe: A guess (or two) at your low mark... Pinmembergordon8812:50 24 Jul '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120517.1 | Last Updated 16 Sep 2005
Article Copyright 2003 by serup
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid