Click here to Skip to main content
15,884,936 members
Articles / Desktop Programming / MFC
Article

BitMap Contour To Windows Region

Rate me:
Please Sign up or sign in to vote.
3.20/5 (12 votes)
16 Sep 2005CPOL 93.4K   1.6K   33   12
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)


Written By
Software Developer (Senior) serupIT
Denmark Denmark
(BS.E.E)
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

Comments and Discussions

 
GeneralDemo Project Pin
gancev18-Apr-07 3:14
gancev18-Apr-07 3:14 
GeneralBitmap Pin
Sangeetha_J25-Jan-07 20:17
Sangeetha_J25-Jan-07 20:17 
Hi Serup,

I came to know your article while searching for concepts related to contour. Am working as a software engineer in Visual C++ for the past two years. No one is here for me to train. Am reading for myself and doing things as much as my effort makes it possible. Now am in a need to accomplish the following one:

1. I need to show a bitmap in a full screen mode
2. Then i need to scatter that bitmap here and there all over the screen and then have to reassemble it to make it return back to its original form.

I had posted one message asking about this. Then i got the reply to look for finding contours of that bitmap and then to carry on from there. One more reply suggested me to study about 3DMax.

Now i posted this to have your ideas and suggestions. If there any book for me to read and proceed, please refer to me. I am ready to read and implement the procedure.

My email id is Anj.Sangeetha@gmail.com

Thanking you,

With Regards,
Sangeetha.

With Regards,
Sangeetha.

Generalembedded systems Pin
jamal odibat18-Sep-05 21:05
jamal odibat18-Sep-05 21:05 
GeneralBetter solution Pin
serup31-Aug-05 2:15
serup31-Aug-05 2:15 
GeneralRe: Better solution Pin
serup31-Aug-05 2:35
serup31-Aug-05 2:35 
GeneralSome Bugs Pin
nebbi27-Jan-04 21:47
nebbi27-Jan-04 21:47 
GeneralRe: Some Bugs Pin
serup28-Jan-04 20:32
serup28-Jan-04 20:32 
GeneralA guess (or two) at your low mark... Pin
Iain Clarke, Warrior Programmer26-Nov-03 5:10
Iain Clarke, Warrior Programmer26-Nov-03 5:10 
GeneralRe: A guess (or two) at your low mark... Pin
Uwe Keim26-Nov-03 5:25
sitebuilderUwe Keim26-Nov-03 5:25 
GeneralRe: A guess (or two) at your low mark... Pin
Iain Clarke, Warrior Programmer26-Nov-03 5:33
Iain Clarke, Warrior Programmer26-Nov-03 5:33 
GeneralRe: A guess (or two) at your low mark... Pin
serup27-Nov-03 3:38
serup27-Nov-03 3:38 
GeneralRe: A guess (or two) at your low mark... Pin
gordon8824-Jul-08 12:50
professionalgordon8824-Jul-08 12: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.