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

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 ?
mSchmidtAsked:
Who is Participating?
 
_corey_Connect With a Mentor Commented:
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
 
_corey_Commented:
Do you want the largest rectangle parallel to the horizontal?
0
 
mSchmidtAuthor Commented:
yes the largest horizontal rectangle...
if possible the largest horizontal rectangle within each region that is not connected...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
mSchmidtAuthor Commented:
_corey_ do you have an idea how to do this ???
0
 
_corey_Commented:
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
 
mSchmidtAuthor Commented:
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
 
mSchmidtAuthor Commented:
Could you please elaborate a bit more... What you just wrote was the same that i got out of MSDN
0
 
mSchmidtAuthor Commented:
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
 
_corey_Commented:
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
 
mSchmidtAuthor Commented:
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
 
mSchmidtAuthor Commented:
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
 
_corey_Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.