Solved

GetRegionData API, trying to find the largest rectangle within a given Region...

Posted on 2004-05-02
12
965 Views
Last Modified: 2012-06-21
Using VisualBasic

I have currently created alot of PolyPolygon regions which i use to fill and outline alot of reservation, now what i need is to add text to these. I figured that by using the CreateFont, SelectObject and SetTextColor, i can print different types of font and colors on my grid.
Then by using DrawText API i can select a rectangle to clip the text within. So this is where iam stuck i now need to get the largest Rectangle from within a PolyPolygon area, actually what i need is to find the largest rectangle within every part of the PolyPolygon area which is not connected.

Can someone give me an example of doing both or just the first ?
0
Comment
Question by:mSchmidt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 8

Expert Comment

by:_corey_
ID: 10980772
Do you want the largest rectangle parallel to the horizontal?
0
 

Author Comment

by:mSchmidt
ID: 10986979
yes the largest horizontal rectangle...
if possible the largest horizontal rectangle within each region that is not connected...
0
 

Author Comment

by:mSchmidt
ID: 11026875
_corey_ do you have an idea how to do this ???
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 8

Expert Comment

by:_corey_
ID: 11031509
Well, I've been thinking about it and the issue is that the polygon isn't symmetrical so you cannot really just calculate using the points.

I guess I could suggest when looping through all the possible rectangle combinations, to try and find the point on either side of the polygon that is mid-way.

Let's say you have a diamond:  then find a point that is mid-way on the top left line, and then go right as much as you can, and then down and then back left.

This could turn into a lot of loops to find optimal though so perhaps you should just do a few iterations.

Move the starting point up or down the "polygon's lines" or points a set amount each time.

I don't know what kind of polygons you typically produce so I'm not going to try and write generic code I cannot test :)
0
 

Author Comment

by:mSchmidt
ID: 11031717
Well Corey ...
I only produce rectangular polygons look at this example
http://www.scoding.dk/needThis.JPG
and the thing it as i read up on GetRegionData, it retrieves all rectangles that is used to create the polygon...
i just need to know how to get the information out of GetRegionData
0
 
LVL 8

Accepted Solution

by:
_corey_ earned 500 total points
ID: 11031891
Oh yea, the obvious solution :)  I must have forgotten the question over the weekend.

Anyway, this looks straightforward enough:

1.  You need a HRGN so you might try CreatePolyPolygonRgn

2.  Once you have the HRGN, call GetRegionData

HRGN fakeRgn;
RGNDATA rgnData;

GetRegionData(fakeRgn, sizeof(RGNDATA), &rgnData);

3.  Loop through the rectangles and find the one you want:

int numRects = rgnData.rdh.nCount;
for(int i=0; i<numRects; i++)
{
  call_some_method_with_rect(  ((RECT*)rgnData.Buffer)[i] );
}

At least I think that's how you access the RECT's...a little fuzzy in the docs.
0
 

Author Comment

by:mSchmidt
ID: 11032018
Could you please elaborate a bit more... What you just wrote was the same that i got out of MSDN
0
 

Author Comment

by:mSchmidt
ID: 11032144
Oki i tried this... my program performs an illigal operation

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type
Private Type RGNDATAHEADER
        dwSize As Long
        iType As Long
        nCount As Long
        nRgnSize As Long
        rcBound As RECT
End Type
Private Type RGNDATA
        rdh As RGNDATAHEADER
        Buffer As Byte
End Type


Dim rgData As RGNDATA
nRegionSize = GetRegionData(hRegion, 0, ByVal 0)
Call GetRegionData(hRegion, nRegionSize, rgData)
0
 
LVL 8

Expert Comment

by:_corey_
ID: 11032250
Well, I wasn't sure what else you were looking for.

Where is the illegal operation thrown from? which line.

This documentation confuses me a little also which is why I was writing it out above.

I think that the nRegionSize returned is the size you need to allocate in the rgData.Buffer area before calling 'Call GetRegionData'  

So, instead of making Buffer as Byte, make it a pointer/array and then allocate THAT specific part based off of nRegionSize.  
0
 

Author Comment

by:mSchmidt
ID: 11032734
it throws the exceptiona this point
Call GetRegionData(hRegion, nRegionSize, rgData)

it simply closes the program.

Could you give me an example of how to do it in code instead of the code i did above ?
0
 

Author Comment

by:mSchmidt
ID: 11032735
it throws the exceptiona this point
Call GetRegionData(hRegion, nRegionSize, rgData)

it simply closes the program.

Could you give me an example of how to do it in code instead of the code i did above ?
0
 
LVL 8

Expert Comment

by:_corey_
ID: 11032791
I'll write a little test program and see if I cannot get the region info myself.

However, my code will be c++.  At least it should point out where to allocate the buffer if I get it right :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question