Re: POLYTEXTOUT problems..( including declarations )

"Dan Hinrichs" <noreply@xxxxxxxxxxxx> wrote in message

> Hi J and Mike... thanks for replying... So, if I am beginning to
> understand this correctly, it is OK for me to change the
> declaration to fix this up? I had thought that the declarations
> were Holy Scriptures, and that they could not be changed
> under any circumstances....

I still think there will be another neater way to do this, but for the time
being I don't see why you cannot change the declaration. According to the
help files the pptxt parameter "points to an array of POLYTEXT structures
describing the strings to be drawn. The array contains one structure for
each string to be drawn". In other words, it is a "four byte" (Long) value
that points to an array of those PolyText structures, each immediately
following the other in one contiguous block. Therefore, as long as it is
left in the declaration as its default "byRef" setting and as long as the
value that gets passed to it is a pointer to our "array of UDTs within
another UDT" then all should be fine (as it certainly appears to be in
practice). Actually, thinking about it some more, and thinking about the
required layout of the data required by the PolyTextOut API, I've now come
up with another two alternative methods, both of which allow you to use your
original dynamic array and both of which allow you to use the declaration
unmodified. The first requires a conversion from Unicode (using the StrConv
function) and the second (which is shown below) is simpler because it does
not need such a conversion. In order to do this it uses the "PolyTextOutW"
version of the PolyTextOut API (rather than your existing "PolyTextOutA"
version). Actually, I said it used the declaration unmodified, but I've just
remembered that I changed the lpString parameter of the POLYTEXT Type from
String to Long, so it isn't all quite as shown "in the book"! I've left the
API declaration unchanged (except for using the W instead of the A version)
but I've made a slight change to the POLYTEXT type. Anyway, this version
works really well and it avoids any "under the hood" string conversions from
Unicode and it also allows you to easily use your dynamic array and it does
not come up with the "too many local non static variables error" that the
previous working version comes up with if you use more than a thousand or so
elements in the array. Actually, I quite like this one . . .


Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POLYTEXT
x As Long
y As Long
n As Long
lpStr As Long
uiFlags As Long
rcl As RECT
pdx As Long
End Type
Private Declare Function PolyTextOut& _
Lib "gdi32" Alias "PolyTextOutW" ( _
ByVal hdc As Long, _
pptxt As POLYTEXT, _
ByVal cStrings As Long)
Private p1() As POLYTEXT

Private Sub Command1_Click()
Dim sBuf1 As String
Dim sBuf2 As String
Dim res As Long
ReDim p1(0 To 1)
sBuf1$ = "String 1"
sBuf2$ = "String 2"
p1(0).y = 0
p1(0).n = Len(sBuf1$)
p1(0).lpStr = StrPtr(sBuf1$)
p1(1).y = 16
p1(1).n = Len(sBuf1$)
p1(1).lpStr = StrPtr(sBuf2$)
res = PolyTextOut(Me.hdc, p1(0), 2)
End Sub