home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form TextDemo
- Caption = "Text Draw Demo"
- ClientHeight = 4185
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 8190
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 4185
- ScaleWidth = 8190
- Begin VB.PictureBox PicText
- Height = 2115
- Left = 240
- ScaleHeight = 2085
- ScaleWidth = 7725
- TabIndex = 1
- Top = 1920
- Width = 7755
- End
- Begin VB.PictureBox PicFrame
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1575
- Left = 3120
- ScaleHeight = 1545
- ScaleWidth = 4785
- TabIndex = 2
- Top = 240
- Width = 4815
- End
- Begin VB.ListBox FontList
- Height = 1590
- Left = 240
- Sorted = -1 'True
- TabIndex = 0
- Top = 240
- Width = 2715
- End
- Attribute VB_Name = "TextDemo"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- ' Copyright
- 1997 by Desaware Inc. All Rights Reserved.
- ' Redraw the demo pictures in the new font
- Private Sub FontList_Click()
- PicText.FontName = FontList.Text
- PicFrame.FontName = FontList.Text
- PicText.Refresh
- PicFrame.Refresh
- End Sub
- ' Load the font list dialog box with the available fonts
- Private Sub Form_Load()
- Dim x%
- Dim a$
- Screen.MousePointer = 11
- For x% = 1 To Screen.FontCount
- a$ = Screen.Fonts(x%)
- If a$ <> "" Then FontList.AddItem a$
- Next x%
- Screen.MousePointer = 0
- FontList.ListIndex = 0
- End Sub
- ' Use of drawtext to do some powerful text drawing
- Private Sub PicFrame_PAINT()
- Dim demo$, demo2$
- Dim rc As RECT
- Dim atab$
- Dim heightused%
- Dim crlf$
- Dim di&
- atab$ = Chr$(9)
- crlf$ = Chr$(13) + Chr$(10)
- demo$ = "This is a line of text that will show how "
- demo$ = demo$ + "automatic word wrapping can take place while drawing text."
- demo$ = demo$ + crlf$ + "Line breaks also work"
- demo2$ = "And" + atab$ + "Tabs" + atab$ + "Work" + atab$ + "Too" + atab$
- ' Get the dimensions of the control
- di = GetClientRect(PicFrame.hWnd, rc)
- heightused% = DrawText(PicFrame.hDC, demo$, -1, rc, DT_WORDBREAK)
- rc.Top = heightused%
- ' Tabs are set 10 characters apart (based on average char width)
- heightused% = DrawText(PicFrame.hDC, demo2$, -1, rc, DT_EXPANDTABS Or DT_TABSTOP Or &HA00)
- End Sub
- ' Draw a multiple font demo in the picture control
- Private Sub PicText_Paint()
- ReDim demo$(4)
- Dim lf As LOGFONT
- #If Win32 Then
- Dim oldfont&, newfont&
- Dim alignorig&
- Dim vpos&
- #Else
- Dim oldfont%, newfont%
- Dim alignorig%
- Dim vpos%
- #End If
- Dim rc As RECT
- Dim todraw%
- Dim di&
- Dim prevpoint As POINTAPI
- demo$(1) = "Watch "
- demo$(2) = "the "
- demo$(3) = "Fonts "
- demo$(4) = "Grow "
- ' Get the dimensions of the control
- di = GetClientRect(PicText.hWnd, rc)
- ' We get the current logical font by selecting in
- ' temporarily a stock font
- oldfont = SelectObject(PicText.hDC, GetStockObject(SYSTEM_FONT))
- di = GetObjectAPI(oldfont, Len(lf), lf)
- ' Restore the original font
- di = SelectObject(PicText.hDC, oldfont)
- ' Reset current position and alignment
- ' Be sure to keep the original alignment
- ' Since we're changing font sizes, align to the baseline
- ' To make life easier, we use the current position
- alignorig = SetTextAlign(PicText.hDC, TA_LEFT Or TA_BASELINE Or TA_UPDATECP)
- ' Draw the text about 3/4 of the way down.
- vpos = rc.Bottom - rc.Bottom / 4
- di = MoveToEx(PicText.hDC, 0, vpos, prevpoint)
- ' Draw the first word
- di = TextOut(PicText.hDC, 0, 0, demo$(1), Len(demo$(1)))
- ' Now start drawing the rest of the words
- For todraw% = 2 To 4
- ' Debug.Print lf.lfHeight
- lf.lfHeight = lf.lfHeight * 2
- newfont = CreateFontIndirect(lf)
- oldfont = SelectObject(PicText.hDC, newfont)
- di = TextOut(PicText.hDC, 0, 0, demo$(todraw%), Len(demo$(todraw)))
- newfont = SelectObject(PicText.hDC, oldfont)
- di = DeleteObject(newfont)
- Next todraw%
- di = SetTextAlign(PicText.hDC, alignorig)
- End Sub
-