CreateRectRgn returns different results? 
Author Message
 CreateRectRgn returns different results?

I have been experimenting a bit with regions and was just wondering if
anyone could tell me why the function CreateRectRgn delivers different
results every time I start my little test program even though the x an y
values are exactly the same.

Thanks
Meini



Thu, 10 Feb 2005 15:46:30 GMT  
 CreateRectRgn returns different results?


Quote:
>I have been experimenting a bit with regions and was just wondering if
>anyone could tell me why the function CreateRectRgn delivers different
>results every time I start my little test program even though the x an y
>values are exactly the same.

You need to explain a bit more. In what way are the results "different"
every time. Post the minimum code that gives you unexpected results.

--
Richard Mason



Fri, 11 Feb 2005 06:24:34 GMT  
 CreateRectRgn returns different results?
Thanks for you reply Mason,
here we go:

    Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1
As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Sub Main()
        Debug.Print CreateRectRgn(0, 0, 10, 10)
        Debug.Print CreateRectRgn(0, 0, 10, 10)
    End Sub

The immediate window will show two different results, e.g.
 1409552255
-150730053
it is like a random number generator...
I thought I could just save the region value and use it again on the same
shape later on. But that does not seem to be the case. Very strange.
Meini


Quote:


> >I have been experimenting a bit with regions and was just wondering if
> >anyone could tell me why the function CreateRectRgn delivers different
> >results every time I start my little test program even though the x an y
> >values are exactly the same.

> You need to explain a bit more. In what way are the results "different"
> every time. Post the minimum code that gives you unexpected results.

> --
> Richard Mason



Fri, 11 Feb 2005 16:27:36 GMT  
 CreateRectRgn returns different results?
Sorry for the mix up with the name--- *Richard* ----let me try again

Thanks for your reply Richard,
here we go:

     Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1
 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
     Sub Main()
         Debug.Print CreateRectRgn(0, 0, 10, 10)
         Debug.Print CreateRectRgn(0, 0, 10, 10)
     End Sub

 The immediate window will show two different results, e.g.
  1409552255
 -150730053
 it is like a random number generator...
 I thought I could just save the region value and use it again on the same
 shape later on. But that does not seem to be the case. Very strange.
 Meini





 > >I have been experimenting a bit with regions and was just wondering if
 > >anyone could tell me why the function CreateRectRgn delivers different
 > >results every time I start my little test program even though the x an y
 > >values are exactly the same.
 >
 > You need to explain a bit more. In what way are the results "different"
 > every time. Post the minimum code that gives you unexpected results.
 >
 > --
 > Richard Mason



Fri, 11 Feb 2005 16:34:14 GMT  
 CreateRectRgn returns different results?


Quote:

>     Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1
> As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
>     Sub Main()
>         Debug.Print CreateRectRgn(0, 0, 10, 10)
>         Debug.Print CreateRectRgn(0, 0, 10, 10)
>     End Sub

> The immediate window will show two different results, e.g.
>  1409552255
> -150730053
> it is like a random number generator...

Definitely not. The function returns a handle to a rectangular region (a
GDI object).
handle1 = CreateRectRgn(0, 0, 10, 10)
handle2 = CreateRectRgn(0, 0, 10, 10)

and you can use these independently.

Quote:
> I thought I could just save the region value and use it again on the same
> shape later on. But that does not seem to be the case. Very strange.

The data that describes a region can be obtained with GetRegionData and
then written to a file. The file can then be read and the region
recreated with ExtCreateRegion.

--
Richard Mason



Sat, 12 Feb 2005 08:00:13 GMT  
 CreateRectRgn returns different results?
Thanks Richard, that makes sense.
I haven't done much API coding yet but I am starting to get the hang of it.

In the meanitme I have written some code to save all x and y data for each
rectangular region for recreation of the region later with CombineRgn. Feels
very clumsy now after looking into other region-APIs like GetRegionData as
you suggested.

I have now tried  to make use of GetRegionData and put this code in my
program but get the runtime error 453 "Can't find DLL entry point
GetRegionDataA in gdi32". What's wrong?

Public Type RGNDATAHEADER
        dwSize As Long
        iType As Long
        nCount As Long
        nRgnSize As Long
        rcBound As Rect
End Type

Public Type RGNDATA
        rdh As RGNDATAHEADER
        Buffer As Byte
End Type

Public Declare Function GetRegionData Lib "gdi32" Alias "GetRegionDataA"
(ByVal hRgn As Long, ByVal dwCount As Long, lpRgnData As RGNDATA) As Long

Public Function BuildRegion...
    Dim FullRegion As Long, b as long, r As RGNDATA
    '...code to create a region and put results in FullRegion
    testresult = GetRegionData(FullRegion, b, r)
    '... more code
End Function

Also i don' t realy knwo what to do with b (dwCount). It realy is a bit hard
to to understand API without any VB-API documentation around, or is there?
Any good book you can recommend?

Cheers
Meini


Quote:


> >     Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal
Y1
> > As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
> >     Sub Main()
> >         Debug.Print CreateRectRgn(0, 0, 10, 10)
> >         Debug.Print CreateRectRgn(0, 0, 10, 10)
> >     End Sub

> > The immediate window will show two different results, e.g.
> >  1409552255
> > -150730053
> > it is like a random number generator...

> Definitely not. The function returns a handle to a rectangular region (a
> GDI object).
> handle1 = CreateRectRgn(0, 0, 10, 10)
> handle2 = CreateRectRgn(0, 0, 10, 10)

> and you can use these independently.

> > I thought I could just save the region value and use it again on the
same
> > shape later on. But that does not seem to be the case. Very strange.

> The data that describes a region can be obtained with GetRegionData and
> then written to a file. The file can then be read and the region
> recreated with ExtCreateRegion.

> --
> Richard Mason



Sun, 13 Feb 2005 09:07:14 GMT  
 CreateRectRgn returns different results?


Quote:
>I have now tried  to make use of GetRegionData and put this code in my
>program but get the runtime error 453 "Can't find DLL entry point
>GetRegionDataA in gdi32". What's wrong?

>Public Type RGNDATAHEADER
>        dwSize As Long
>        iType As Long
>        nCount As Long
>        nRgnSize As Long
>        rcBound As Rect
>End Type

>Public Type RGNDATA
>        rdh As RGNDATAHEADER
>        Buffer As Byte
>End Type

>Public Declare Function GetRegionData Lib "gdi32" Alias "GetRegionDataA"
>(ByVal hRgn As Long, ByVal dwCount As Long, lpRgnData As RGNDATA) As Long

You can define the RGNDATA structure as below, though I'm not actually
using it here.

Public Type RGNDATA
  rdh As RGNDATAHEADER
  RectBuffer() As Byte
End Type

or

Public Type RGNDATA
  rdh As RGNDATAHEADER
  RectBuffer() As RECT
End Type

With an arbitrary region one doesn't know how much data there
actually is i.e. What size to make RectBuffer so GetRegionData
is usually declared as:

Public Declare Function GetRegionData Lib "gdi32" _
               (ByVal hRgn As Long, ByVal dwCount As Long, _
                ByVal lpRgnData As Long) As Long

Public Declare Sub CopyMemory Lib "kernel32" _
                Alias "RtlMoveMemory" (Destination As Any, _
                Source As Any, ByVal Length As Long)

Dim bytearr() as Byte
Dim header as RGNDATAHEADER
Dim rectdata() As RECT

Get the size in bytes required for the _entire_ RGNDATA info i.e. The
header and the data.

numbytes = GetRegionData(hRgn, 0, 0)
ReDim bytearr(1 To numbytes)
lret = GetRegionData(hRgn, numbytes, VarPtr(bytearr(1)))

'Get the header
Call CopyMemory(header, bytearr(1), Len(header))

ReDim rectdata(1 To header.nCount) 'ncount is number of rectangles
Call CopyMemory(rectdata(1), _
        bytearr(header.dwSize + 1), header.nRgnSize)

There are variations of this, but you'll get the idea.

Quote:

>Also i don' t realy knwo what to do with b (dwCount). It realy is a bit hard
>to to understand API without any VB-API documentation around, or is there?
>Any good book you can recommend?

The only API book I've ever bought is Daniel Appleman's "Programmers
Guide To The Win32 API". The latest edition may be a bit out of date by
now, I don't know, but it has been highly recommended many times in VB
ng's.

You can also get the API-Guide from www.allapi.net which has a lot of
declarations and examples, but some of the examples aren't as good as
they could be.

--
Richard Mason



Sun, 13 Feb 2005 15:57:05 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Quereies Return Different Results ADO vice Access

2. UBound returns different result when array is created using Split()

3. HELP...Queries return different results in VB than Access

4. Two identical queries returning different results

5. DAO/ADO return different results

6. DAO/ADO return different results

7. Native code results different from p-code results

8. SQL select different results on different forms

9. cr6 prof - different printers = different results

10. problem using component with asp page -- result of function not returned, instead original value returned

11. CreateRectRgn, SetWindowRgn, GetWindowRgn

12. Sort query results according to criteria from different table

 

 
Powered by phpBB® Forum Software