Newsgroup: it.comp.lang.visual-basic
Titolo: Chi conosce la DrawText (funzione Api)?

Ciao sono Alessandra, mi potete aiutare sul funzionamento della DrawText
in VB 5.0?
la mia e-mail è : 
cam...@hotmail.com

La funzione DrawText é una potente funzione per la stampa di testo
all'interno di un device context, gli attibuti del testo stampato
(forecolor,font...) sono stabiliti dal device context.
La potenza di drawtext sta nella capacitá di stampare il testo all'interno
di un rettangolo da te passato come parametro secondo determinati flag
impostati nella drawtext.
L'esempio seguente usa drawtext per stampare del testo nel centro del form,
usando la seconda opzione il testo é giustificato a destra.
'///////////////////////////////////////////////////////////////////////////
////
Option Explicit
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Const DT_CENTER = &H1
Const DT_VCENTER = &H4
Const DT_SINGLELINE = &H20
Const DT_RIGHT = &H2
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc
As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal
wFormat As Long) As Long
Private Sub Command1_Click()
Dim sBuf As String, lpRect As RECT
With lpRect
    .Left = 0
    .Top = 0
    .Right = Me.ScaleWidth / Screen.TwipsPerPixelX
    .Bottom = Me.ScaleHeight / Screen.TwipsPerPixelY
End With
sBuf = "Ciao"
DrawText Me.hdc, sBuf, Len(sBuf), lpRect, DT_CENTER Or DT_VCENTER Or
DT_SINGLELINE
'DrawText Me.hdc, sBuf, Len(sBuf), lpRect, DT_VCENTER Or DT_RIGHT Or
DT_SINGLELINE
'///////////////////////////////////////////////////////////////////////////
////
La descrizione di drawtext é la seguente :
DrawText
VB Declaration
Declare Function DrawText& Lib "user32" Alias "DrawTextA" (ByVal hdc As
Long,_
ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat
As_
Long)
Description
Draws text into the specified rectangle.
Parameter Type/Description
hdc Long—A handle to a device context on which to draw.
lpStr String—The text string to draw.
nCount Long—The number of characters to draw. If the entire string is to be
drawn (up to the null terminator), this may be set to –1.
lpRect RECT—The formatting rectangle to use for drawing (logical
coordinates).
wFormat Long—An array of flag bits that determines how the drawing will be
performed. Refer to the list of constants in Table 11.12
Return Value
Long—The height of the text drawn.
Table 11.12 Text Drawing Flags
Flag Constant Description
DT_BOTTOM DT_SINGLE must also be specified. Aligns text with the bottom of
the formatting rectangle.
DT_CALCRECT Calculates the formatting rectangle as follows: On multiline
drawing, the bottom of the rectangle is extended as needed to hold the text.
On single line drawing the right of the rectangle is extended. No text is
drawn. The rectangle specified by the lpRect parameter is loaded with the
calculated values.
DT_CENTER Text is centered horizontally.
DT_EXPANDTABS Tabs are expanded when text is drawn. The default tab spacing
is eight characters; however, this may be changed using the DT_TABSTOP flag.
DT_EXTERNALLEADING Use the external leading attribute of the current font
when calculating the line height.
DT_LEFT Text is left-aligned.
DT_NOCLIP Draws without clipping to the specified rectangle.
DT_NOPREFIX Normally, this function assumes that the & character indicates
that the next character should be underlined. This flag turns off this
behavior.
DT_RIGHT Text is right-aligned.
DT_SINGLELINE Draws a single line only.
DT_TABSTOP Specifies the new tab spacing in the high eight bits of this
integer.
DT_TOP DT_SINGLE must also be specified. Aligns text with the top of the
formatting rectangle.
DT_VCENTER DT_SINGLE must also be specified. Aligns text at the center of
the formatting rectangle.
DT_WORDBREAK Performs word wrapping. Starts a new line whenever a word would
exceed the rectangle boundary or a carriage return linefeed sequence is met.
Has no effect if the TA_UPDATECP flag has been set using the SetTextAlign
function.
Ciao
Corrado