Solved

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

Posted on 2004-05-02
12
940 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Powershell Script When New File Is In A Folder 3 63
sameEnds challenge 3 133
isEverywhere  challenge 19 71
Powershell Script need assistance to make some changes 4 58
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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now