CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Graphics & Multimedia >> Bitmaps & Palettes >> Using regions


A tool to convert bitmaps to region files
Rating:

Till Toenshoff (view profile)
January 24, 1999

Environment: VC++ 4.2

Since the arcticle Transparent Window by Franz Polzer helped me a lot, I would like to contribute a little tool that converts bitmaps to region-files suitable to use as a window-mask (SetWindowRgn).

Why does anybody need this tool?

  • its flexible; its possible to adjust the key-color
  • its fast (not the tool, but your app); loading a region is better than creating it online
  • its free; source is included

How to use it?

    enter a source bitmap path (or press browse)
  • enter a key color (or click onto any pixel of the source bitmap)
  • press "calc !" wait and see the result
  • enter a destination path (or press browse)
  • press "write"

(continued)



To use those region-files in your own project, you need to do the following: Import the *.RGN-file into your project-resources. The type of that resource needs to be set to "Data".

You can also import it manually by editing your *.rc file. Just insert something like the following:


IDR_SAMPLE_REGION    RCDATA  DISCARDABLE     "res\\sample.rgn"

Below is some example code that loads and activates a region, it should be called from something like "OnInitDialog".


//nRegionID - resource ID of the region data
BOOL CTransparentWnd::InitRegion (unsigned short nRegionID)
{
	const char *MSGCAPTION="Init Region";
	HRSRC hrsrc;		//handle of the resource
	HGLOBAL hmem;		//handle to resource memory
	DWORD dwSize;		//size of our resource
	RGNDATA *rd;		//region data
	CRgn rgn;			//the region itself

	//try to locate the resource
	if ((hrsrc=FindResource(NULL,
	                        (LPCSTR)nRegionID,
	                         RT_RCDATA)) == NULL)
	{
		MessageBox ("failed to find region",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//load the resource
	if ((hmem=LoadResource (NULL,hrsrc)) == NULL)
	{
		MessageBox ("failed to load region",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//get the size of the region-data structure (= header + data)
	if ((dwSize=SizeofResource (NULL,hrsrc)) == 0)
	{
		MessageBox ("region has an invalid size",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//lock the resource to get a pointer for it
	if ((rd=(RGNDATA *)LockResource (hmem)) == NULL)
	{
		MessageBox ("failed to lock resource memory",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//create a region from our data
	if (!rgn.CreateFromData (NULL,dwSize,rd))
	{
		MessageBox ("failed to create a region from that data",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//setup
	if (!SetWindowRgn (GetSafeHwnd(),(HRGN)rgn,TRUE))
	{
		MessageBox ("failed to set the region for that window",MSGCAPTION,MB_OK);
		return FALSE;
	}
	//NOTE: win32-based apps do not need to unlock or free loaded resources (not manually)
	return TRUE;
}

Download project files - 34 KB

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Problems with RCDATA in Visual Studio .NET ? - Legacy CodeGuru (01/01/2004)
Small Fix for memory leak and load diferent type bitmaps - Legacy CodeGuru (03/30/2001)
A Wrote a MUCH Better Tool for Regions - Legacy CodeGuru (02/07/2001)
problem loading 256 bit bitmaps - Legacy CodeGuru (10/31/2000)
More info about region file please - Legacy CodeGuru (03/29/2000)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES