GetRegionData API, how to use it to find the largest rectangle within a givin 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 horizontal rectangle within every part of the PolyPolygon region which are not connected.

Can someone give me an example of doing both or just the first ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I see that you ask this question number of times without success. There is no Windows API which can do this. I suggest you to ask this question in the Math area:

Since Math experts are not Windows programmers, describe GetRegionData API for them to give idea what is input for algorithm you need. I got number of excellent answers from Math experts, possibly they can help also in this case.
By the way, describe the whole problem there, possibly list of rectangles is better as algorithm input than region data.
mSchmidtAuthor Commented:
Please do look up on GetRegionData <--

it does ecsactly what i need i just can't find out how to get it working... it does do it...


The GetRegionData function fills the specified buffer with data describing a region. This data includes the dimensions of the rectangles that make up the region.

DWORD GetRegionData(
  HRGN hRgn,            // handle to region
  DWORD dwCount,        // size of region data buffer
  LPRGNDATA lpRgnData   // region data buffer
[in] Handle to the region.
[in] Specifies the size, in bytes, of the lpRgnData buffer.
[out] Pointer to a RGNDATA structure that receives the information. The dimensions of the region are in logical units. If this parameter is NULL, the return value contains the number of bytes needed for the region data.
Return Values
If the function succeeds and dwCount specifies an adequate number of bytes, the return value is always dwCount. If dwCount is too small or the function fails, the return value is 0. If lpRgnData is NULL, the return value is the required number of bytes.

If the function fails, the return value is zero.

Windows NT/2000/XP: To get extended error information, call GetLastError.

The GetRegionData function is used in conjunction with the ExtCreateRegion function.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I know how GetRegionData works. It returns list of rectangles. I don't see how you can solve this problem using this function. Is it enough for you to know how to call this function? By the way, what is the language you are working with?
mSchmidtAuthor Commented:
Iam using Visual basic
And well if i get returned all rectangles which is used to create my rectangular structure

cant i then quite easily figure out whether they are connected and not and which are the biggest ???
'It looks like the easiest way to provide a buffer for this
'function would be using an array of Longs.

Dim RgnData() as Long

'Now, you're going to have to call this function twice, with
'different argument types each time.  You can either use As Any or
'use two different declarations.  Using two declarations is
'probably safer.

Private Declare Function GetRegionDataSize lib "gdi32" alias "GetRegionData" (byval hRgn as Long, byval Zero1 as Long, byval Zero2 as Long) as Long

Private Declare Function GetRegionData lib "gdi32" (byval hRgn as Long, byval BufferSize as Long, byref FirstLong as Long) as Long

'We need to call the function once to find the size of the buffer.

Redim RgnData(1 to GetRegionDataSize(hRgn, 0, 0) / 4)

'We need to call it again to fill in the buffer.

Call GetRegionData(hRgn, LenB(RgnData), RgnData(1))

'Now, RgnData(1) to RgnData(8) are header information you probably
'don't need.  RgnData(9) is a Left, RgnData(10) is a Top,
'RgnData(11) is a Right, and RgnData(12) is a Bottom for a single
'rectangle, and the rest of the array will continue that pattern.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I beleive you can get list of rectangles using the way provided by JMoon5FTM. Having this, consider the following algorithm:
Input - list of rectangles (GetRegionData output).
Output - the largest horizontal rectangle within every part of the input list region which are not connected.

Algorithm may be implemented in VB, for example, using dynamic arrays. Written using pseudo-code.
Consider array (A) of elements (G). Each element (G) is array of rectangles. This is temporary variable used in algorithm. G is group of intersecting rectangles, number of elements in A is number of non-intersecting groups.
Let's call input array or rectangles I, output array of rectangles O.

For each rectangle r in I
    For each group g in A
        For each rectangle r1 in g
            if r1 and r are intersecting, add r to g and go to next r (external loop)
    Add new group to A which contains r (we are here if r doesn't intersect with any of existing rectangles)

For each group g in A
    Find maximal rectangle in g and add it to O

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.