Author: Jonas Bilinkevicius
I am trying to do regioning backwards. I am writing an application that will read
in a bitmap, allow the user to set a transparent colour, and then calculate the
point set that would be needed to make that region transparent. I then want to
supply the user with the coordinates as a set of coordinates, i.e. I want to
extract it from a region format. Why? Because that's how Winamp takes the data in
to make its custom shaped forms. But I can't seem to figure out how to pull the
data out.
Answer:
One thing I found is that you must create a region prior to GetWindowRgn. I thought
that one was created by default. I made a function that does what you need:
1 procedure TForm1.ShowRgnInfo(Rgn: HRGN);
2 type3 RgnRects = array[0..1000] of TRect;
4 PRgnRect = ^RgnRects;
5 var6 RgnData: PRgnData;
7 Size: DWORD;
8 i: Integer;
9 R: TRect;
10 RgnPtr: PRgnRect;
11 begin12 Size := GetRegionData(Rgn, 0, nil);
13 Memo1.Lines.Add('Size = ' + IntToStr(Size));
14 GetMem(RgnData, Size);
15 GetRegionData(Rgn, Size, RgnData);
16 Memo1.Lines.Add('Number of Rectangles = ' + IntToStr(RgnData.rdh.nCount));
17 RgnPtr := @RgnData.Buffer;
18 for i := 0 to RgnData.rdh.nCount - 1 do19 begin20 R := RgnPtr[i];
21 Memo1.Lines.Add('Rect ' + IntToStr(i));
22 Memo1.Lines.Add(IntToStr(R.Left) + ', ' + IntToStr(R.Top) + ', ' +
23 IntToStr(R.Right) + ', ' + IntToStr(R.Bottom));
24 end;
25 end;