home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 4.00 Begin VB.Form frmDrawText Appearance = 0 'Flat BackColor = &H80000005& Caption = "Draw Text Example" ClientHeight = 4305 ClientLeft = 585 ClientTop = 1770 ClientWidth = 7005 BeginProperty Font name = "Arial" charset = 1 weight = 700 size = 12 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 4995 Left = 525 LinkTopic = "Form1" ScaleHeight = 287 ScaleMode = 3 'Pixel ScaleWidth = 467 Top = 1140 Width = 7125 Begin VB.CommandButton cmdJustify Appearance = 0 'Flat BackColor = &H80000005& Caption = "Justify" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 435 Left = 5640 TabIndex = 6 Top = 3720 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "Adjust Size" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 2 Left = 5640 TabIndex = 5 Top = 1320 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "Expand Tabs" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 5 Left = 5640 TabIndex = 4 Top = 3120 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "Right Align" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 4 Left = 5640 TabIndex = 3 Top = 2520 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "No Clipping" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 3 Left = 5640 TabIndex = 2 Top = 1920 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "MultiLine" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 1 Left = 5640 TabIndex = 1 Top = 720 Width = 1215 End Begin VB.CommandButton cmdTest Appearance = 0 'Flat BackColor = &H80000005& Caption = "Simple" BeginProperty Font name = "MS Sans Serif" charset = 1 weight = 700 size = 8.25 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 495 Index = 0 Left = 5640 TabIndex = 0 Top = 120 Width = 1215 End Begin VB.Menu mnuClear Caption = "Clear" End Attribute VB_Name = "frmDrawText" Attribute VB_Creatable = False Attribute VB_Exposed = False Option Explicit Const Sample1$ = "Large blocks of text can be easily displayed anywhere in a window or on the printed page using the powerful Windows DrawText function" Dim Sample2$ Dim OutputRect As RECT Private Sub cmdJustify_Click() Dim LineWidth% Dim CurrentLineWidth% Dim StartOfCurrentLine% Dim CurrentPosition% Dim NextPosition% Dim BreakCharCount% Dim CurrentYLocation% Dim di% Dim OutputString$ ' Determine the maximum length LineWidth% = OutputRect.right - OutputRect.left StartOfCurrentLine% = 1 CurrentPosition% = 1 BreakCharCount% = 0 CurrentYLocation% = OutputRect.top Do ' Find the next space NextPosition% = InStr(CurrentPosition%, Sample1$, " ") ' We're done with the loop If NextPosition% <= CurrentPosition% Then CurrentLineWidth = TextWidth(Mid$(Sample1$, StartOfCurrentLine%)) Else CurrentLineWidth = TextWidth(Mid$(Sample1$, StartOfCurrentLine%, NextPosition% - StartOfCurrentLine%)) End If ' Does the current line fit? If CurrentLineWidth < LineWidth Then ' This word fit into the line ' Add to the count of break characters BreakCharCount% = BreakCharCount% + 1 ' and set the new current position If NextPosition > 0 Then CurrentPosition% = NextPosition% + 1 Else ' The final line fits on one line - ' print it without justification Exit Do End If Else ' The new word does not fit - print the line OutputString$ = Mid$(Sample1$, StartOfCurrentLine%, CurrentPosition% - StartOfCurrentLine% - 1) ' Set the new current position StartOfCurrentLine% = CurrentPosition% ' If there is at least one break character, set the correct count If BreakCharCount% > 1 Then BreakCharCount% = BreakCharCount% - 1 ' Set the text justification di% = SetTextJustification(hDC, LineWidth - TextWidth(OutputString$), BreakCharCount%) ' And display the line di% = TextOut(hDC, OutputRect.left, CurrentYLocation%, OutputString$, Len(OutputString$)) CurrentYLocation% = CurrentYLocation% + TextHeight(OutputString$) BreakCharCount% = 0 ' Clear the text justification value di% = SetTextJustification(hDC, 0, BreakCharCount%) End If Loop While CurrentPosition% < Len(Sample1$) If CurrentPosition% < Len(Sample1$) Then ' Print the rest of the last line - no justification OutputString$ = Mid$(Sample1$, StartOfCurrentLine%) di% = TextOut(hDC, OutputRect.left, CurrentYLocation%, OutputString$, Len(OutputString$)) End If End Sub Private Sub cmdTest_Click(Index As Integer) Dim di% Select Case Index Case 0 di% = DrawText(hDC, Sample1$, Len(Sample1$), OutputRect, DT_LEFT) Case 1 di% = DrawText(hDC, Sample1$, Len(Sample1$), OutputRect, DT_LEFT Or DT_WORDBREAK) Case 2 di% = DrawText(hDC, Sample1$, Len(Sample1$), OutputRect, DT_LEFT Or DT_CALCRECT Or DT_WORDBREAK) Refresh di% = DrawText(hDC, Sample1$, Len(Sample1$), OutputRect, DT_LEFT Or DT_WORDBREAK) Case 3 di% = DrawText(hDC, Sample1$, Len(Sample1$), OutputRect, DT_NOCLIP) Case 4 di% = DrawText(hDC, Sample2$, Len(Sample2$), OutputRect, DT_RIGHT) Case 5 di% = DrawText(hDC, Sample2$, Len(Sample2$), OutputRect, DT_EXPANDTABS) End Select End Sub Private Sub Form_Load() ' We start with the upper left corner of the page OutputRect.right = ScaleWidth \ 2 OutputRect.bottom = ScaleHeight \ 2 ' And shrink it by 1/20 the width of the page to give ' it an extra margin InflateRect OutputRect, -CInt(ScaleWidth \ 20), -CInt(ScaleHeight \ 20) Sample2$ = "Line1" & Chr$(9) & "is 1" & Chr$(13) & Chr$(10) Sample2$ = Sample2$ & "Line2" & Chr$(9) & "is 2" & Chr$(13) & Chr$(10) Sample2$ = Sample2$ & "Line3" & Chr$(9) & "is 3" & Chr$(13) & Chr$(10) Sample2$ = Sample2$ & "Line4" & Chr$(9) & "is 4" & Chr$(13) & Chr$(10) End Sub Private Sub Form_Paint() Line (OutputRect.left, OutputRect.top)-(OutputRect.right, OutputRect.bottom), QBColor(14), BF End Sub Private Sub mnuClear_Click() frmDrawText.Refresh End Sub