Solved

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

Posted on 2004-05-02
936 Views
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
Question by:mSchmidt
• 7
• 5

LVL 8

Expert Comment

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

Author Comment

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

Author Comment

ID: 11026875
_corey_ do you have an idea how to do this ???
0

LVL 8

Expert Comment

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

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

_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

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

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
dwSize As Long
iType As Long
nCount As Long
nRgnSize As Long
rcBound As RECT
End Type
Private Type RGNDATA
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

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

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

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

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

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 303
squareUp  challenge 22 107
countHi challenge 25 85
wordcount challenge 11 78
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to thâ€¦
Having just graduated from college and entered the workforce, I donâ€™t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back toâ€¦R. Â  So â€¦
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!