![]() |
Multimedia »
GDI »
Regions
Intermediate
Useful functions for RegionBy jedykingFunctions for tiling region and stretching region. |
VC6, VC7Win2K, WinXP, MFC, GDI, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
When I wrote the software SkinMagic Toolkit for my company, I needed to tile a region or stretch a region within a bound rectangle. I implemented it in two functions CreateTileRegion and CreateStretchRegion.
To use the code, just add rgntool.cpp and rgntool.h to your project. Call CreateTileRegion or CreateStretchRegion to create the new region. When you run the demo project, please double click mouse left button in the window's client, to show the effect.
HRGN CreateStretchRgn( HRGN hSrcRgn, //the source region handle float xScale , //x-axis scale float yScale , //y-axis scale int xOffset , //x-axis offset int yOffset ) //y-axis offset { XFORM xForm; xForm.eDx = 0; xForm.eDy = 0; xForm.eM11 = xScale; xForm.eM12 = 0; xForm.eM21 = 0; xForm.eM22 = yScale; HRGN hRgn = NULL ; DWORD dwCount = GetRegionData( hSrcRgn , 0 , NULL ); BYTE* pRgnData =(BYTE*) malloc( dwCount ); if( pRgnData ) { dwCount = GetRegionData( hSrcRgn , dwCount , (RGNDATA*)pRgnData ); hRgn = ExtCreateRegion( &xForm , dwCount , (RGNDATA*)pRgnData ); free( pRgnData ); if( hRgn ) { OffsetRgn( hRgn , xOffset, yOffset ); return hRgn; } } return NULL; } HRGN CreateTitleRgn( HRGN hSrcRgn, //the source region handle SIZE szSize , //the source region rect size RECT rcBound ) //the bound rectangle { HRGN hRgn = CreateRectRgn( 0,0,10,10 ); HRGN hTempRgn1 = CreateRectRgn( 0,0,10,10 ); HRGN hTempRgn2 =CreateRectRgn( 0,0,10,10 ); CombineRgn( hTempRgn2 , hSrcRgn , hTempRgn1 , RGN_COPY ); CombineRgn( hRgn , hSrcRgn , hTempRgn1 , RGN_COPY ); OffsetRgn( hRgn , rcBound.left , rcBound.top ); int xOffset=0 , yOffset=0; for (yOffset = rcBound.top ; yOffset < rcBound.bottom ; yOffset += szSize.cy) { for (xOffset=rcBound.left ; xOffset < rcBound.right ; xOffset += szSize.cx) { CombineRgn( hTempRgn1 , hTempRgn2 , hSrcRgn , RGN_COPY ); OffsetRgn( hTempRgn1 , xOffset , yOffset ); CombineRgn( hRgn , hRgn , hTempRgn1 , RGN_OR ); } } DeleteObject( hTempRgn1 ); DeleteObject( hTempRgn2 ); hTempRgn1 = CreateRectRgnIndirect( &rcBound ); CombineRgn( hRgn , hRgn , hTempRgn1 , RGN_AND ); DeleteObject( hTempRgn1 ); return hRgn; }
Visit here for my other Win32 software.
Date Posted: 03-13-2003
The code is free, if you want to change the source code in order to improve the features, performance, etc., please send me the new source code so that I can have a look at it. The changed source code should contain descriptions of what you have changed, and of course your name. The only thing you MAY NOT CHANGE is the ORIGINAL COPYRIGHT INFORMATION.
First thanks to my boss who permitted me to post the code in this site.
Second thanks to the author (I'm sorry for not getting his/her name) who wrote CreateRgnFromBitmap.
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 11 Mar 2003 Editor: Smitha Vijayan |
Copyright 2003 by jedyking Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |