home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch11 / textdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  5.3 KB  |  158 lines

  1. VERSION 4.00
  2. Begin VB.Form TextDemo 
  3.    Caption         =   "Text Draw Demo"
  4.    ClientHeight    =   4185
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   8190
  8.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    ForeColor       =   &H80000008&
  18.    Height          =   4590
  19.    Left            =   1035
  20.    LinkMode        =   1  'Source
  21.    LinkTopic       =   "Form1"
  22.    ScaleHeight     =   4185
  23.    ScaleWidth      =   8190
  24.    Top             =   1140
  25.    Width           =   8310
  26.    Begin VB.PictureBox PicText 
  27.       Height          =   2115
  28.       Left            =   240
  29.       ScaleHeight     =   2085
  30.       ScaleWidth      =   7725
  31.       TabIndex        =   1
  32.       Top             =   1920
  33.       Width           =   7755
  34.    End
  35.    Begin VB.PictureBox PicFrame 
  36.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  37.          Name            =   "MS Sans Serif"
  38.          Size            =   9.75
  39.          Charset         =   0
  40.          Weight          =   400
  41.          Underline       =   0   'False
  42.          Italic          =   0   'False
  43.          Strikethrough   =   0   'False
  44.       EndProperty
  45.       Height          =   1575
  46.       Left            =   3120
  47.       ScaleHeight     =   1545
  48.       ScaleWidth      =   4785
  49.       TabIndex        =   2
  50.       Top             =   240
  51.       Width           =   4815
  52.    End
  53.    Begin VB.ListBox FontList 
  54.       Height          =   1590
  55.       Left            =   240
  56.       Sorted          =   -1  'True
  57.       TabIndex        =   0
  58.       Top             =   240
  59.       Width           =   2715
  60.    End
  61. Attribute VB_Name = "TextDemo"
  62. Attribute VB_Creatable = False
  63. Attribute VB_Exposed = False
  64. Option Explicit
  65. ' Copyright 
  66.  1997 by Desaware Inc. All Rights Reserved.
  67. ' Redraw the demo pictures in the new font
  68. Private Sub FontList_Click()
  69.     PicText.FontName = FontList.Text
  70.     PicFrame.FontName = FontList.Text
  71.     PicText.Refresh
  72.     PicFrame.Refresh
  73. End Sub
  74. '   Load the font list dialog box with the available fonts
  75. Private Sub Form_Load()
  76.     Dim x%
  77.     Dim a$
  78.     Screen.MousePointer = 11
  79.     For x% = 1 To Screen.FontCount
  80.         a$ = Screen.Fonts(x%)
  81.         If a$ <> "" Then FontList.AddItem a$
  82.     Next x%
  83.     Screen.MousePointer = 0
  84.     FontList.ListIndex = 0
  85. End Sub
  86. '   Use of drawtext to do some powerful text drawing
  87. Private Sub PicFrame_PAINT()
  88.     Dim demo$, demo2$
  89.     Dim rc As RECT
  90.     Dim atab$
  91.     Dim heightused%
  92.     Dim crlf$
  93.     Dim di&
  94.     atab$ = Chr$(9)
  95.     crlf$ = Chr$(13) + Chr$(10)
  96.     demo$ = "This is a line of text that will show how "
  97.     demo$ = demo$ + "automatic word wrapping can take place while drawing text."
  98.     demo$ = demo$ + crlf$ + "Line breaks also work"
  99.     demo2$ = "And" + atab$ + "Tabs" + atab$ + "Work" + atab$ + "Too" + atab$
  100.     ' Get the dimensions of the control
  101.     di = GetClientRect(PicFrame.hWnd, rc)
  102.     heightused% = DrawText(PicFrame.hDC, demo$, -1, rc, DT_WORDBREAK)
  103.     rc.Top = heightused%
  104.     ' Tabs are set 10 characters apart (based on average char width)
  105.     heightused% = DrawText(PicFrame.hDC, demo2$, -1, rc, DT_EXPANDTABS Or DT_TABSTOP Or &HA00)
  106. End Sub
  107. '   Draw a multiple font demo in the picture control
  108. Private Sub PicText_Paint()
  109.     ReDim demo$(4)
  110.     Dim lf As LOGFONT
  111.     #If Win32 Then
  112.         Dim oldfont&, newfont&
  113.         Dim alignorig&
  114.         Dim vpos&
  115.     #Else
  116.         Dim oldfont%, newfont%
  117.         Dim alignorig%
  118.         Dim vpos%
  119.     #End If
  120.     Dim rc As RECT
  121.     Dim todraw%
  122.     Dim di&
  123.     Dim prevpoint As POINTAPI
  124.     demo$(1) = "Watch "
  125.     demo$(2) = "the "
  126.     demo$(3) = "Fonts "
  127.     demo$(4) = "Grow "
  128.     ' Get the dimensions of the control
  129.     di = GetClientRect(PicText.hWnd, rc)
  130.     ' We get the current logical font by selecting in
  131.     ' temporarily a stock font
  132.     oldfont = SelectObject(PicText.hDC, GetStockObject(SYSTEM_FONT))
  133.     di = GetObjectAPI(oldfont, Len(lf), lf)
  134.     ' Restore the original font
  135.     di = SelectObject(PicText.hDC, oldfont)
  136.     ' Reset current position and alignment
  137.     ' Be sure to keep the original alignment
  138.     ' Since we're changing font sizes, align to the baseline
  139.     ' To make life easier, we use the current position
  140.     alignorig = SetTextAlign(PicText.hDC, TA_LEFT Or TA_BASELINE Or TA_UPDATECP)
  141.     ' Draw the text about 3/4 of the way down.
  142.     vpos = rc.Bottom - rc.Bottom / 4
  143.     di = MoveToEx(PicText.hDC, 0, vpos, prevpoint)
  144.     ' Draw the first word
  145.     di = TextOut(PicText.hDC, 0, 0, demo$(1), Len(demo$(1)))
  146.     ' Now start drawing the rest of the words
  147.     For todraw% = 2 To 4
  148.         ' Debug.Print lf.lfHeight
  149.         lf.lfHeight = lf.lfHeight * 2
  150.         newfont = CreateFontIndirect(lf)
  151.         oldfont = SelectObject(PicText.hDC, newfont)
  152.         di = TextOut(PicText.hDC, 0, 0, demo$(todraw%), Len(demo$(todraw)))
  153.         newfont = SelectObject(PicText.hDC, oldfont)
  154.         di = DeleteObject(newfont)
  155.     Next todraw%
  156.     di = SetTextAlign(PicText.hDC, alignorig)
  157. End Sub
  158.