Click here to Skip to main content
6,306,412 members and growing! (16,633 online)
Email Password   helpLost your password?
Multimedia » GDI » Regions     Intermediate

CreateRegionFromFile

By Yuriy Zaporozhets

Very primitive function that creates region from *.bmp files.
VC6Win2K, MFC, GDI, Dev
Posted:26 May 2000
Updated:10 Dec 2001
Views:89,998
Bookmarked:46 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
35 votes for this article.
Popularity: 6.93 Rating: 4.49 out of 5

1

2

3

4
9 votes, 100.0%
5

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


Member

Location: Canada Canada

Other popular GDI articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 28 (Total in Forum: 28) (Refresh)FirstPrevNext
GeneralRotated Edit Box PinsussZAKIR4:57 2 Sep '04  
GeneralCreateRgnFromFile question Pinsussrioan11:23 31 Jul '04  
GeneralRe: CreateRgnFromFile question PinmemberYuriy_Zaporozhets14:59 5 Oct '04  
GeneralCustom controls ... PinmemberAdrian Datcu1:58 10 Jun '04  
GeneralFantastic !!! PinsussHarleyDude17:37 28 Apr '04  
GeneralGreat example PinmemberUbersnack1:42 10 Jun '03  
GeneralAdapting this PinmemberJudd4:27 11 Dec '02  
Generalfinally found it PinmemberKevin Smith10:10 1 Nov '02  
GeneralLarge Fonts PinmemberMatt Philmon12:11 5 Feb '02  
GeneralRegionToBitmap class... Pinmembersaturn2:53 5 Feb '02  
GeneralArticle screwed up... no links PinmemberMatt Philmon5:44 11 Dec '01  
GeneralRe: Article screwed up... no links PinmemberChris Maunder11:44 11 Dec '01  
Generaldoesn't work in 16bits, look at this valid code ... PinmemberF.Julien1:28 20 Sep '01  
Generaldoesn't work when you want white as transparent color Pinmemberbene4:47 29 Aug '01  
GeneralI found here how to load HBITMAP from file... PinmemberPavel Kurochkin13:42 26 Aug '01  
Generalit's not working .... why? Pinmemberscwpark21:15 30 Jul '01  
GeneralWhat it taje to get ::ExtCreateRegion work in NT PinsussAndy18:01 9 Oct '00  
GeneralRe: What it taje to get ::ExtCreateRegion work in NT PinmemberAnonymous0:04 2 Mar '01  
GeneralRe: What it taje to get ::ExtCreateRegion work in NT PinmemberAnonymous19:46 2 Apr '01  
Generalbuggy, slow code PinsussFeng Yuan www,fengyuan.com20:37 8 Sep '00  
GeneralRe: buggy, slow code PinsussLance Gordon5:04 29 Sep '00  
GeneralI need some help here... (rookie!) PinsussMatuX18:27 19 Jul '00  
GeneralRe: I need some help here... (rookie!) Pinsussmemon2:53 26 Jul '00  
GeneralResource Leaks GALORE! PinsussRealCodeGuy15:50 13 Jul '00  
GeneralSample project? PinsussChris Holt1:35 19 Jun '00  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 10 Dec 2001
Editor: Smitha Vijayan
Copyright 2000 by Yuriy Zaporozhets
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project