Click here to Skip to main content
6,595,854 members and growing! (17,940 online)
Email Password   helpLost your password?
Multimedia » GDI » Regions     Intermediate

Useful functions for Region

By jedyking

Functions for tiling region and stretching region.
VC6, VC7Win2K, WinXP, MFC, GDI, Dev
Posted:11 Mar 2003
Views:33,933
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 1.80 Rating: 2.13 out of 5
3 votes, 42.9%
1

2
1 vote, 14.3%
3
2 votes, 28.6%
4
1 vote, 14.3%
5

Sample Image - appspeed.gif

Introduction

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.

Using the code

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.

History

Date Posted: 03-13-2003

Copyright

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.

Acknowledgements

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.

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

jedyking


Member

Location: China China

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 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralSeem not function PinmemberGianfranco3:10 13 Mar '03  

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

PermaLink | Privacy | Terms of Use
Last Updated: 11 Mar 2003
Editor: Smitha Vijayan
Copyright 2003 by jedyking
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project