home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "EM_FMTLINES DEMO"
- ClientHeight = 1995
- ClientLeft = 1740
- ClientTop = 1500
- ClientWidth = 6885
- Height = 2400
- Left = 1680
- LinkTopic = "Form1"
- ScaleHeight = 1995
- ScaleWidth = 6885
- Top = 1155
- Width = 7005
- Begin CommandButton Command3
- Caption = "&Print"
- Height = 375
- Left = 3000
- TabIndex = 3
- Top = 1320
- Width = 1335
- End
- Begin CommandButton Command2
- Caption = "CR-CR-LF = O&FF"
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 375
- Left = 3000
- TabIndex = 2
- Top = 840
- Width = 1335
- End
- Begin CommandButton Command1
- Caption = "CR-CR-LF = &ON"
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 375
- Left = 3000
- TabIndex = 1
- Top = 360
- Width = 1335
- End
- Begin TextBox Text1
- Height = 1095
- Left = 360
- MultiLine = -1 'True
- TabIndex = 0
- Text = "This text does not return CR-CR-LF when it wraps text at the end of the line."
- Top = 600
- Width = 2295
- End
- Begin Label Label2
- Caption = "Select the desired command button to turn EM_FMTLINES on or off. Then select Print to see the results."
- Height = 1455
- Left = 4560
- TabIndex = 7
- Top = 360
- Width = 2055
- End
- Begin Label LabelOFF
- Caption = "OFF"
- ForeColor = &H000000FF&
- Height = 255
- Left = 1560
- TabIndex = 6
- Top = 240
- Width = 495
- End
- Begin Label LabelON
- Caption = "ON"
- ForeColor = &H00008000&
- Height = 255
- Left = 1560
- TabIndex = 5
- Top = 240
- Width = 495
- End
- Begin Label Label1
- Caption = "CR-CR-LF = "
- Height = 255
- Left = 360
- TabIndex = 4
- Top = 240
- Width = 1095
- End
- Option Explicit
- Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
- Const WM_USER = &H400
- Const EM_FMTLINES = WM_USER + 24
- Sub Command1_Click ()
- Dim rtn%
- 'Turning ON and OFF the CR-CR-LF could be done at various
- 'points and times within program execution. If desired,
- 'this could be done when the form is loaded and be the
- 'default for all remaining operations on the text, or it
- 'could be turned on and off when needed. It all depends
- 'on what the programmer needs to do with the text and when.
- 'For this example set text
- Text1 = "This text will return CR-CR-LF when it wraps text at the end of the line."
- 'Turn on CR-CR-LF combination
- rtn% = SendMessage(Text1.hWnd, EM_FMTLINES, True, 0&)
- 'Show ON label
- LabelON.ZOrder 0
- End Sub
- Sub Command2_Click ()
- Dim rtn%
- 'Turning ON and OFF the CR-CR-LF could be done at various
- 'points and times within program execution. If desired,
- 'this could be done when the form is loaded and be the
- 'default for all remaining operations on the text, or it
- 'could be turned on and off when needed. It all depends
- 'on what the programmer needs to do with the text and when.
- 'For this example set text
- Text1 = "This text does not return CR-CR-LF when it wraps text at the end of the line."
- 'Turn off CR-CR-LF combination
- rtn% = SendMessage(Text1.hWnd, EM_FMTLINES, False, 0&)
- 'Show ON label
- LabelOFF.ZOrder 0
- End Sub
- Sub Command3_Click ()
- Screen.MousePointer = 11 'Hourglass
- 'Set printer object to character mode for this example
- Printer.ScaleMode = 4
- 'Normally this is where we would set the CurrentY property
- 'Print textbox
- Call StripCR_Print(Text1, 15)
- '15 could be any valid character position. For this example we will
- 'use 15 as the character position (column) to print the text.
- 'The sub expects a Single, so, as an example, we could pass it 15.3
- 'if we needed to move the text slighty right or 14.8 to move it
- 'slightly left.
- Printer.EndDoc
- Screen.MousePointer = 0 'Default
- End Sub
- Sub StripCR_Print (ByVal Text$, ByVal CurXPos!)
- Dim Pos%, StartPos%, InStrPos%
- 'Before calling this sub the programmer must set the
- 'CurrentY position and pass the text and the CurrentX
- 'position as parameters. This sub uses the CurXPos!
- 'to set the printer object CurrentX position before
- 'printing each line.
- 'We use CurXPos here as a Single. That is because we
- 'are using the character scalemode (4) for the printer object
- 'and it can accept a single for precision placement of the
- 'CurrentX property.
- 'If we were to use some other scalemode then we must change
- 'the datatype of CurXPos to reflect the values that the
- 'printer object will accept. i.e. For twips use integer.
- 'If Text$ is empty then exit the sub - no need to print
- If Text$ = "" Then Exit Sub
- 'First strip the extra CR that is returned when setting
- 'the EM_FMTLINES message to True.
- Do While InStr(Text$, (Chr$(13) & Chr$(13)))
- Pos% = InStr(Text$, (Chr$(13) & Chr$(13)))
- 'Delete extra CR
- Text$ = Mid$(Text$, 1, Pos% - 1) + Mid$(Text$, Pos% + 1)
- StartPos% = 1 'Initialize
- InStrPos% = 1 'Initialize
- Do While StartPos% <= Len(Text$)
- 'Search for the last character in the CR-LF combination - chr$(10)
- InStrPos% = InStr(StartPos%, Text$, Chr$(10))
- 'If InStrPos% = 0 then print last line and exit sub
- If InStrPos% = 0 Then
- Printer.CurrentX = CurXPos!
- Printer.Print Mid$(Text$, StartPos%);
- Exit Sub
- End If
- 'Print line
- Printer.CurrentX = CurXPos!
- Printer.Print Mid$(Text$, StartPos%, InStrPos% - StartPos% + 1);
- 'Set new StartPos%
- StartPos% = InStrPos% + 1
- End Sub
-