Click here to Skip to main content
Licence 
First Posted 26 May 2000
Views 112,556
Bookmarked 59 times

CreateRegionFromFile

By | 10 Dec 2001 | Article
Very primitive function that creates region from *.bmp files.

Introduction

This very simple function creates a region from a bitmap (.bmp) file. 8, 16, 24 and 32 bit color modes are supported.

The function takes two parameters:

  • hBmp - a handle to the bitmap image.
  • color - transparent color.
HRGN CreateRgnFromFile( HBITMAP hBmp, COLORREF color );

Using the function is very simple. For example, if you wish to set the window shape of your dialog, then in your OnInitDialog handler, do this:

BOOL CFileRgnDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // load image
    HBITMAP hBmp = (HBITMAP)LoadImage( AfxGetInstanceHandle(), 
                     "Rgn.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
    // if fail - nothing to do
    if ( hBmp == NULL ) return TRUE;
    // create region, let the RED color be transparent

    HRGN hRgn = CreateRgnFromFile( hBmp, RGB(255,0,0) );

    // build memory dc for background
    CDC* dc = GetDC();
    m_dcBkGrnd = CreateCompatibleDC( dc->m_hDC );
    ReleaseDC( dc );
    // select background image
    SelectObject( m_dcBkGrnd, hBmp );
    // set window size the same as image size
    SetWindowPos( NULL, 0, 0, m_dwWidth, m_dwHeight, 
                           SWP_NOZORDER | SWP_NOMOVE );
    // assign region to window
    SetWindowRgn( hRgn, FALSE );

    return TRUE;
}

History

  • December 08 2001

    * cut & paste bug for 16-bit mode (white color as transparent did not work).

    * pixels in a last column has not been used.

    + Now you can use non-aligned (by width) images.

  • June 11 2001

    * ExtCreateRegion NT-problem (personal thanks to Martin for reporting about it).

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

About the Author

Yuriy Zaporozhets



Canada Canada

Member



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
GeneralNot working on Windows Seven PinmemberDom3021:19 6 May '11  
GeneralRe: Not working on Windows Seven PinmemberMember 112345010:01 26 May '11  
GeneralMy vote of 5 Pinmemberryan20fun20:15 9 Feb '11  
GeneralRotated Edit Box PinsussZAKIR3:57 2 Sep '04  
GeneralCreateRgnFromFile question Pinsussrioan10:23 31 Jul '04  
GeneralRe: CreateRgnFromFile question PinmemberYuriy_Zaporozhets13:59 5 Oct '04  
GeneralCustom controls ... PinmemberAdrian Datcu0:58 10 Jun '04  
GeneralFantastic !!! PinsussHarleyDude16:37 28 Apr '04  
GeneralGreat example PinmemberUbersnack0:42 10 Jun '03  
GeneralAdapting this PinmemberJudd3:27 11 Dec '02  
Generalfinally found it PinmemberKevin Smith9:10 1 Nov '02  
GeneralLarge Fonts PinmemberMatt Philmon11:11 5 Feb '02  
GeneralRegionToBitmap class... Pinmembersaturn1:53 5 Feb '02  
GeneralArticle screwed up... no links PinmemberMatt Philmon4:44 11 Dec '01  
GeneralRe: Article screwed up... no links PinmemberChris Maunder10:44 11 Dec '01  
Generaldoesn't work in 16bits, look at this valid code ... PinmemberF.Julien0:28 20 Sep '01  
Generaldoesn't work when you want white as transparent color Pinmemberbene3:47 29 Aug '01  
GeneralI found here how to load HBITMAP from file... PinmemberPavel Kurochkin12:42 26 Aug '01  
Questionit's not working .... why? Pinmemberscwpark20:15 30 Jul '01  
QuestionWhat it taje to get ::ExtCreateRegion work in NT PinsussAndy17:01 9 Oct '00  
AnswerRe: What it taje to get ::ExtCreateRegion work in NT PinmemberAnonymous23:04 1 Mar '01  
GeneralRe: What it taje to get ::ExtCreateRegion work in NT PinmemberAnonymous18:46 2 Apr '01  
may be that is why MSN Explorer does not have an NT Version.
 
Happy Programming!!!Cool | :cool:
Generalbuggy, slow code PinsussFeng Yuan www,fengyuan.com19:37 8 Sep '00  
GeneralRe: buggy, slow code PinsussLance Gordon4:04 29 Sep '00  
GeneralI need some help here... (rookie!) PinsussMatuX17:27 19 Jul '00  

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
Web02 | 2.5.120529.1 | Last Updated 11 Dec 2001
Article Copyright 2000 by Yuriy Zaporozhets
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid