Solved

Color textbox.

Posted on 1998-04-14
22
693 Views
Last Modified: 2008-03-03
I want some code or a text box that can show different colors in the background and the foreground many times in the same box. The textbox mIRC is using in channels is a very perfect example, it can show different backgrounds and different forecolors in the same box. (It can show bold and underline too).

/Biot.
0
Comment
Question by:Biot
  • 11
  • 5
  • 3
  • +3
22 Comments
 
LVL 3

Expert Comment

by:Egore
Comment Utility
Have you tried using a Rich Text Box?  I think it comes with VB4 Pro Edition and better.
0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
The RichTextBox control, RICHTX32.OCX, is your best bet. It supports multiple point sizes, fonts and font styles, and colors. Also, it does not have the 64K limitation of the standard Textbox. The only drawback with this control is that it is only compatable with 32-bit systems, such as Win95 or NT.

Another, albeit complex, answer would be to use a picturebox control as a container and an array of label controls with their individual properties set for the required colors, and positioned as needed. Set the text to display by intercepting keypresses. (The array can be dynamic, so you can create as many labels as needed at runtime) If you required a 16-bit solution, and don't mind the headaches involved in coding the thing, that is.
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
The RichTextBox control is not exact the thing I am looking for..
It can show different forecolors but not backgroundcolors.

Foyal (or anyone else), can you describe the picturebox alternative little more, I have tried it a little but I don't really know how to create unlimted with labels and I want to buffer the text so I can use a scrollbar.

/Biot.
0
 

Expert Comment

by:ddsharp
Comment Utility
How about using a grid control.  You would be limited to using colors in rectangles (cells), but you could shade the background for each cell separately.
0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
To create new controls at runtime(up to the limits of system memory) do this:
  Make sure at least one instance of the control you want to create is loaded with an index of 0 (an array of 1 control),
 control(0),
 then at runtime go:
  Load control(n)
  where n = the index of the new control you want to create.
If you watch this index, you could have a corresponding array of words or phrases, in order to keep things organized. Watch for spaces in the keypresses, then Select Case predefined keywords to set up your various color combinations for display... If you detect one of your keywords, remove it from the last label and create a new label to hold it. Remember for a dynamic array to use Redim Preserve in order not to lose your original stuff when resizing your word/phrase array.
Big headache, but possible.
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Ok.. But I have a problem.. Shall I create a new label for every word or shall I have one for every row? I want it to work as a textbox.. If I create a new label for every word it would be easy to change row when it doesn't fit more.. But it would be pretty slow..

0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
 I wouldn't add a new label except when I needed to change the colors, or font. Maybe this would only occur after twenty or more words, in which case use one label per line. Sometimes it could occur for every word in a line. Use as few as possible to save memory.
If you are setting up an extremely large document, it won't work. But if your display area is relatively small, you don't have to have everything loaded at once (except in the word/phrase array) Change the thing as the user scrolls areas of the text into view. Instead of moving all the label controls, use one picturebox as a viewport, another as the display area. As an area in the display area moves out of view(behind the edge of the viewport), shift the text parts from the array to fill the contents of the labels, and reset the position of the display picturebox relative to the viewport. To do all this you will probably need to set up your word/phrase array as a user defined type and have variables in the array for relative positions, bgcolor, forecolor, font, etc.
  This is still a painfully complex method to use. The RichTextBox would definitely be better, if you can find a way to use it.
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Ok, the problem with scrolling I think the best solution is to set a variable to every line that goes of the "textbox" and that is not a very big problem, I think I can solve it pretty easy..
But the thing to have a label for each line is smart, but some sentences are longer than the "textbox" and that is for me a little problem.. Is there any smart way to check the sentence and then divide it into one or more labels? I have a tried a little but it didn't gave a smart solution. And maby some sentences are just one word with no spaces and that sentence cant be divied.. So if the word is longer than a certain length it must be divied.. All this must have a solution.. But I don't have it. :)
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Adjusted points to 400
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Adjusted points to 700
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
Your best bet is to draw the text directly on the form/control where you want it to appear.  Dan Appleman's "Visual Basic Prgrammer's Guide to the Win32 API" discusses how to do this at great length.  Rather than regurgitate what has already been written so well, here is an exceprt from the article.

If you do not have the book, I STRONGLY recommend purchasing it.  The $50 that it will cost you will be one of the best investments that you could make.

*** NOTE: I am posting this document under the premise that it is for educational purposes only.  If I have violated any copyright issues (the notice for which appears at the end of the article), please tell me and I will remove the article from this post.

Hope this helps!

zsi

===================================
In the process of hiding much of the complexity of Windows from programmers, Visual Basic has in a way done a disservice, at least to those who are in the early stages of the transition from DOS to Windows. Visual Basic makes it easy to place text on the screen by using the Text and Label controls. The Text control is based on the standard Windows Edit class, which means that it provides a bi-directional interface that allows you read and write text stored within the control. The label control also provides a bi-directional interface, though it is not based on a Windows control. Labels are implemented entirely within the Visual Basic system. Since using these controls is easy, it is not uncommon for Visual Basic programmers to create large forms that contain dozens of these controls. Since these controls (especially text controls) take up memory and resources and require time to load, the result is frequently an application that loads slowly and is inefficient.

In many cases all a programmer really wants to do is display text on a form. There may be no need to read the text from the control, thus any storage used by the control is wasted memory. In these cases it may be better to draw the text directly onto the form. This should be done during the Paint event, which is triggered any time the form needs to be updated. It is true that this requires additional work on the part of the programmer, but this approach can improve performance and resource use considerably.

Visual Basic provides the Print command for drawing text, a command that is not particularly flexible. Fortunately, the Windows API includes a number of powerful text drawing functions that can be easily used from within Visual Basic. This article will focus on the two most important of these functions, DrawText and TextOut. The dtxt1 project demonstrates the use of these functions. dtxt1.bas declares the functions and some of the constants and structures that they use.

Option Explicit

Type RECT   '8 Bytes
    left As Integer
    top As Integer
    right As Integer
    bottom As Integer
End Type

''  Text Alignment Options
Global Const TA_NOUPDATECP = 0
Global Const TA_UPDATECP = 1

Global Const TA_LEFT = 0
Global Const TA_RIGHT = 2
Global Const TA_CENTER = 6

Global Const TA_TOP = 0
Global Const TA_BOTTOM = 8
Global Const TA_BASELINE = 24

'' ExtTextOut flags
Global Const ETO_GRAYED = 1
Global Const ETO_OPAQUE = 2

Global Const ETO_CLIPPED = 4

''  DrawText() Format Flags
Global Const DT_TOP = &H0
Global Const DT_LEFT = &H0
Global Const DT_CENTER = &H1
Global Const DT_RIGHT = &H2
Global Const DT_VCENTER = &H4
Global Const DT_BOTTOM = &H8
Global Const DT_WORDBREAK = &H10
Global Const DT_SINGLELINE = &H20
Global Const DT_EXPANDTABS = &H40
Global Const DT_TABSTOP = &H80
Global Const DT_NOCLIP = &H100
Global Const DT_EXTERNALLEADING = &H200
Global Const DT_CALCRECT = &H400

Global Const DT_NOPREFIX = &H800
Global Const DT_INTERNAL = &H1000

Declare Function DrawText% Lib "User" (ByVal hDC%, ByVal lpStr$, ByVal nCount%, lpRect As RECT, ByVal wFormat%)
Declare Function ExtTextOut% Lib "GDI" (ByVal hDC%, ByVal x%, ByVal y%, ByVal wOptions%, lpRect As Any, ByVal lpString$, ByVal nCount%, lpDx As Any)
Declare Function GetTabbedTextExtent& Lib "GDI" (ByVal hDC%, ByVal lpString$, ByVal nCount%, ByVal nTabPositions%, lpnTabStopPositions%)
Declare Function GetTextAlign% Lib "GDI" (ByVal hDC%)

Declare Function GetTextExtent& Lib "GDI" (ByVal hDC%, ByVal lpString$, ByVal nCount%)
Declare Sub InflateRect Lib "User" (lpRect As RECT, ByVal x%, ByVal y%)
Declare Function SetTextAlign% Lib "GDI" (ByVal hDC%, ByVal wFlags%)
Declare Function SetTextJustification% Lib "GDI" (ByVal hDC%, ByVal nBreakExtra%, ByVal nBreakCount%)
Declare Function TabbedTextOut& Lib "User" (ByVal hDC%, ByVal x%, ByVal y%, ByVal lpString$, ByVal nCount%, ByVal nTabPositions%, lpnTabStopPositions%, ByVal nTabOrigin%)

Declare Function TextOut% Lib "GDI" (ByVal hDC%, ByVal x%, ByVal y%, ByVal lpString$, ByVal nCount%)

The DrawText function, like all Windows API drawing functions, has an hDC parameter that is a handle to a device context to use when drawing. The easiest way to obtain this device context is to use the hDC property of a form or control. You can also use the hDC property of the printer object when drawing text to the printer. The function also requires the text string and the length of the string. A length of -1 indicates that the string is null terminated and that the function should calculate the length for itself. DrawText also takes a pointer to a rectangle structure that generally represents the location and area on which to draw, though this can change based on the wFormat parameter. The wFormat parameter includes one or more of the DT_ flags that control the operation of the function. These flags can be combined using the OR operator.

The DT_BOTTOM, DT_LEFT, DT_CENTER, DT_VCENTER, DT_RIGHT and DT_TOP flags indicate the horizontal and vertical alignment of the text within the rectangle (The vertical alignment flags only apply to single line text).
DrawText is able to draw multiple lines of text. It normally starts a new line when it sees a carriage return line feed pair (chr$(13) & chr$(10)) in the string, but line breaks will be ignored if the DT_SINGLELINE flag is specified. The DT_WORDBREAK flag tells the function to automatically start a new line whenever a word would go beyond the right side of the rectangle - this makes word wrapping very easy to implement.

DrawText is used internally by many Windows controls to draw captions, thus by default whenever it sees an '&' character it interprets it as a request to underline the next character. This behavior can be defeated using the DT_NOPREFIX flag.
The DT_EXPANDTABS flag tells the DrawText function to expand tab characters (chr$(9)). The default tabstop is every 8 characters (based on the average character width of the current font), but this can be reset using the DT_TABSTOP flag. When this flag is used you should use the OR operator to set the high byte of the format parameter to the number of characters per tab stop.

The DT_NOCLIP flag tells the function not to clip the output to the rectangle.
The DT_CALCRECT flag prevents the actual drawing of text, but sets the rectangle size to the size needed to display the entire string. If the text is multiline or word wrap is turned on, the rectangle will grow in size vertically, if it is a single line, the rectangle's right margin will be extended.
File dtxt1.frm contains a program that demonstrates the use of the DrawText program. It calculates a rectangle that fits in the upper quarter of the window, shrinking it slightly to provide a margin. During the form Paint event, this rectangle is filled with yellow to help illustrate how the drawing relates to the rectangle. The definition of the form is shown below and in figure 2.

VERSION 2.00
Begin Form frmDrawText
   Caption         =   "Draw Text Example"
   ClientHeight    =   4305
   ClientLeft      =   585
   ClientTop       =   1770
   ClientWidth     =   7005
   FontBold        =   -1  'True
   FontItalic      =   0   'False
   FontName        =   "Arial"
   FontSize        =   12
   FontStrikethru  =   0   'False
   FontUnderline   =   0   'False
   Height          =   4995
   Left            =   525
   LinkTopic       =   "Form1"

   ScaleHeight     =   287
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   467
   Top             =   1140
   Width           =   7125
   Begin CommandButton cmdJustify
      Caption         =   "Justify"
      Height          =   435
      Left            =   5640
      TabIndex        =   6
      Top             =   3720
      Width           =   1215
   End
   Begin CommandButton cmdTest
      Caption         =   "Adjust Size"
      Height          =   495

      Index           =   2
      Left            =   5640
      TabIndex        =   5
      Top             =   1320
      Width           =   1215
   End
   Begin CommandButton cmdTest
      Caption         =   "Expand Tabs"
      Height          =   495
      Index           =   5
      Left            =   5640
      TabIndex        =   4
      Top             =   3120
      Width           =   1215
   End
   Begin CommandButton cmdTest
      Caption         =   "Right Align"

      Height          =   495
      Index           =   4
      Left            =   5640
      TabIndex        =   3
      Top             =   2520
      Width           =   1215
   End
   Begin CommandButton cmdTest
      Caption         =   "No Clipping"
      Height          =   495
      Index           =   3
      Left            =   5640
      TabIndex        =   2
      Top             =   1920
      Width           =   1215
   End
   Begin CommandButton cmdTest

      Caption         =   "MultiLine"
      Height          =   495
      Index           =   1
      Left            =   5640
      TabIndex        =   1
      Top             =   720
      Width           =   1215
   End
   Begin CommandButton cmdTest
      Caption         =   "Simple"
      Height          =   495
      Index           =   0
      Left            =   5640
      TabIndex        =   0
      Top             =   120
      Width           =   1215

   End
   Begin Menu mnuClear
      Caption         =   "Clear"
   End
End
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

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

Sub Form_Paint ()
    Line (OutputRect.Left, OutputRect.Top)-(OutputRect.right, OutputRect.Bottom), QBColor(14), BF

End Sub

Sub mnuClear_Click ()
    frmDrawText.Refresh
End Sub

The command buttons demonstrate some of the features of the DrawText function. You are encouraged to extend the example to demonstrate the effects of other combinations of flags.


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

One feature that is not supported by the DrawText function is text output with justification. Of course, this feature is not supported by the standard text box either, so the question frequently arises as to how to implement it. There are sophisticated custom controls available to Visual Basic programmers that can display justified text, however these typically contain all of the functionality of a small word processor - fine if you need that level of functionality, but overkill and a waste of resources for simple text display tasks.

Fortunately, Windows provides some support for justification within Windows itself. But the bulk of the work is up to the programmer. In this example the string is scanned one word at a time. Words are added to a string until it exceeds the width of the display area. The width of the line is calculated and subtracted from the display width. This difference needs to be divided evenly during printing among the break characters (typically spaces). The SetTextJustification function tells Windows how much space to divide up among a specified number of break characters during the next text output function. It is important to use this function to set the space to zero after drawing the line, since the function accumulates an error value that is useful when justifying a string with multiple fonts, but can lead to erroneous results from the TextWidth function otherwise.

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 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

Of course, this is a very simple example. But it indicates an approach that potentially has a great deal of flexibility. You could, for example, display the line one word at a time. This would allow you to change the color of individual words or even characters. You could even add a hyphenation capability. In truth, this approach to printing reflects the way word processors work internally, and one that you can take advantage of - even from Visual Basic.

All of the material presented here is copyrighted by either Desaware or Macmillan. No part of this material may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Expert Comment

by:od0
Comment Utility
hähä, jag tror att man ska köra mirc istället =)
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Thanks for the answer.. But i can't get it complied on Visual Basic 5.0 Enterprise.. Can anyone just translate for example the Begin command, which don't works.. There are a few problems that I can't solve.. Please help me.. If this where taken from a book, can't you mail the finished example? I'll increase the points if I can get it to work.

/Biot (robin@mbox316.swipnet.se)
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
Biot,

I'm sorry.  You must have thought that you had to copy the code directly into a form's code module.  What you see above is the complete listing for a VB form.  If you open Notepad.exe and copy this code in, then save it as WhatEver.frm, then open the WhatEver.frm file in VB, you will find that everything works fine.

To get a slightly better understanding of this, take a frm (or bas or cls) from a project that you have created and are familiar with the code.  Open this file up with Notepad and you will see items in the code listing that you do not recognize. These are things the VB uses internally.

If you still have problems, plese let me know.

zsi
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
I still can't get it to work.. I don't know whats wrong but for example it doesn't understand the Begin lines.
Please.. if you could mail me the form.. I don't know what i make wrong..
Please.
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Hmm.. I din't understand what you meant first, but know I solve the problem. :) There is just one little thing left, and it is the line:

InflateRect OutputRect, -CInt(ScaleWidth \ 20), -CIn (ScaleHeight \ 20)


Which is the in the module line:

Declare Sub InflateRect Lib "User" (lpRect As RECT, ByVal x%, ByVal y%)

When I start the program the error "File not found: User" appears. And it marks the InflateRect OutputRect, -CInt(ScaleWidth \ 20), -CIn (ScaleHeight \ 20) line. Do you know what is wrong?
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Adjusted points to 800
0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Well it didn't work with User32. VB5 crasches when I compile it.. So the answer does not work. Thanks anyway.
0
 
LVL 4

Accepted Solution

by:
zsi earned 800 total points
Comment Utility
Biot,

The example is 16bit code.  To make it run in VB5, use the following BAS module instead of the one above
-----------------------------------------------------------------------------------------
Option Explicit

      Type RECT   '8 Bytes
          left As Integer
          top As Integer
          right As Integer
          bottom As Integer
      End Type

      ''  Text Alignment Options
      Global Const TA_NOUPDATECP = 0
      Global Const TA_UPDATECP = 1

      Global Const TA_LEFT = 0
      Global Const TA_RIGHT = 2
      Global Const TA_CENTER = 6

      Global Const TA_TOP = 0
      Global Const TA_BOTTOM = 8
      Global Const TA_BASELINE = 24

      '' ExtTextOut flags
      Global Const ETO_GRAYED = 1
      Global Const ETO_OPAQUE = 2

      Global Const ETO_CLIPPED = 4

      ''  DrawText() Format Flags
      Global Const DT_TOP = &H0
      Global Const DT_LEFT = &H0
      Global Const DT_CENTER = &H1
      Global Const DT_RIGHT = &H2
      Global Const DT_VCENTER = &H4
      Global Const DT_BOTTOM = &H8
      Global Const DT_WORDBREAK = &H10
      Global Const DT_SINGLELINE = &H20
      Global Const DT_EXPANDTABS = &H40
      Global Const DT_TABSTOP = &H80
      Global Const DT_NOCLIP = &H100
      Global Const DT_EXTERNALLEADING = &H200
      Global Const DT_CALCRECT = &H400

      Global Const DT_NOPREFIX = &H800
      Global Const DT_INTERNAL = &H1000

      Declare Function DrawText& Lib "User32" (ByVal hDC&, ByVal lpStr$, ByVal nCount&, lpRect As RECT,  ByVal wFormat&)
      Declare Function ExtTextOut& Lib "GDI32" (ByVal hDC&, ByVal x&, ByVal y&, ByVal wOptions&, lpRect As  Any, ByVal lpString$, ByVal nCount&, lpDx As Any)
      Declare Function GetTabbedTextExtent& Lib "GDI32" (ByVal hDC&, ByVal lpString$, ByVal nCount&, ByVal  nTabPositions&, lpnTabStopPositions&)
      Declare Function GetTextAlign& Lib "GDI32" (ByVal hDC&)

      Declare Function GetTextExtent& Lib "GDI32" (ByVal hDC&, ByVal lpString$, ByVal nCount&)
      Declare Sub InflateRect Lib "User32" (lpRect As RECT, ByVal x&, ByVal y&)
      Declare Function SetTextAlign& Lib "GDI32" (ByVal hDC&, ByVal wFlags&)
      Declare Function SetTextJustification& Lib "GDI32" (ByVal hDC&, ByVal nBreakExtra&, ByVal   nBreakCount&)
      Declare Function TabbedTextOut& Lib "User32" (ByVal hDC&, ByVal x&, ByVal y&, ByVal lpString$, ByVal  nCount&, ByVal nTabPositions&, lpnTabStopPositions&, ByVal nTabOrigin&)

      Declare Function TextOut& Lib "GDI32" (ByVal hDC&, ByVal x&, ByVal y&, ByVal lpString$, ByVal  nCount&)
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
biot,

Give me your e-mail address and I will mail a working copy for VB5 to you.

zsi
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
biot,

I changed my mind :)

Rather than get beseiged with e-mail requests, I am posting the full bas module here (the form does not require any changes).  I have tested this in Win95 and it works fine.  Please let me know if you have any questions.

As for copyrights, This is an excerpt from Daniel Appleman's "Visual Basic Programmers Guide to the Win32 API."

=========================================
Option Explicit
' Copyright © 1997 by Desaware Inc. All Rights Reserved.


'**********************************
'**  Type Definitions:

#If Win32 Then
Public Type RECT
    left As Long
    top As Long
    right As Long
    bottom As Long
End Type
#Else
Public Type RECT
    left As Integer
    top As Integer
    right As Integer
    bottom As Integer
End Type

#End If 'WIN32 Types


'**********************************
'**  Type Definitions:

#If Win32 Then
Public Type SIZE
    cx As Long
    cy As Long
End Type

#End If 'WIN32 Types

''  Text Alignment Options
Public Const TA_NOUPDATECP = 0
Public Const TA_UPDATECP = 1

Public Const TA_LEFT = 0
Public Const TA_RIGHT = 2
Public Const TA_CENTER = 6

Public Const TA_TOP = 0
Public Const TA_BOTTOM = 8
Public Const TA_BASELINE = 24

'' ExtTextOut flags
Public Const ETO_GRAYED = 1
Public Const ETO_OPAQUE = 2
Public Const ETO_CLIPPED = 4

''  DrawText() Format Flags
Public Const DT_TOP = &H0
Public Const DT_LEFT = &H0
Public Const DT_CENTER = &H1
Public Const DT_RIGHT = &H2
Public Const DT_VCENTER = &H4
Public Const DT_BOTTOM = &H8
Public Const DT_WORDBREAK = &H10
Public Const DT_SINGLELINE = &H20
Public Const DT_EXPANDTABS = &H40
Public Const DT_TABSTOP = &H80
Public Const DT_NOCLIP = &H100
Public Const DT_EXTERNALLEADING = &H200
Public Const DT_CALCRECT = &H400
Public Const DT_NOPREFIX = &H800
Public Const DT_INTERNAL = &H1000


'**********************************
'**  Function Declarations:

#If Win32 Then
Public 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)
Public Declare Function ExtTextOut& Lib "gdi32" Alias "ExtTextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal wOptions As Long, lpRect As RECT, ByVal lpString As String, ByVal nCount As Long, lpDx As Long)
Public Declare Function GetTabbedTextExtent& Lib "user32" Alias "GetTabbedTextExtentA" (ByVal hDC As Long, ByVal lpString As String, ByVal nCount As Long, ByVal nTabPositions As Long, lpnTabStopPositions As Long)
Public Declare Function GetTextAlign& Lib "gdi32" (ByVal hDC As Long)
Public Declare Function GetTextCharacterExtra& Lib "gdi32" (ByVal hDC As Long)
Public Declare Function GetTextExtentPoint32& Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE)
Public Declare Function InflateRect& Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long)
Public Declare Function SetTextAlign& Lib "gdi32" (ByVal hDC As Long, ByVal wFlags As Long)
Public Declare Function SetTextColor& Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long)
Public Declare Function SetTextJustification& Lib "gdi32" (ByVal hDC As Long, ByVal nBreakExtra As Long, ByVal nBreakCount As Long)
Public Declare Function TabbedTextOut& Lib "user32" Alias "TabbedTextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long, ByVal nTabPositions As Long, lpnTabStopPositions As Long, ByVal nTabOrigin As Long)
Public Declare Function TextOut& Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long)
#Else
Declare Function DrawText% Lib "user" (ByVal hDC%, ByVal lpStr$, ByVal nCount%, lpRect As RECT, ByVal wFormat%)
Declare Function ExtTextOut% Lib "gdi" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal wOptions%, lpRect As Any, ByVal lpString$, ByVal nCount%, lpDx As Any)
Declare Function ExtTextOutBynum% Lib "gdi" Alias "ExtTextOut" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal wOptions%, ByVal lpRect&, ByVal lpString$, ByVal nCount%, ByVal lpDx&)
Declare Function ExtTextOutByrect% Lib "gdi" Alias "ExtTextOut" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal wOptions%, lpRect As RECT, ByVal lpString$, ByVal nCount%, ByVal lpDx&)
Declare Function GetTabbedTextExtent& Lib "gdi" (ByVal hDC%, ByVal lpString$, ByVal nCount%, ByVal nTabPositions%, lpnTabStopPositions%)
Declare Function GetTextAlign% Lib "gdi" (ByVal hDC%)
Declare Function GetTextCharacterExtra% Lib "gdi" (ByVal hDC%)
Declare Function GetTextExtent& Lib "gdi" (ByVal hDC%, ByVal lpString$, ByVal nCount%)
Declare Sub InflateRect Lib "user" (lpRect As RECT, ByVal X%, ByVal Y%)
Declare Function SetTextAlign% Lib "gdi" (ByVal hDC%, ByVal wFlags%)
Declare Function SetTextColor& Lib "gdi" (ByVal hDC%, ByVal crColor&)
Declare Function SetTextJustification% Lib "gdi" (ByVal hDC%, ByVal nBreakExtra%, ByVal nBreakCount%)
Declare Function TabbedTextOut& Lib "user" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal lpString$, ByVal nCount%, ByVal nTabPositions%, lpnTabStopPositions%, ByVal nTabOrigin%)
Declare Function TextOut% Lib "gdi" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal lpString$, ByVal nCount%)
#End If 'WIN32


0
 
LVL 1

Author Comment

by:Biot
Comment Utility
Ah, thanks now it works. I shall try to add scrollbar, and different colors. I you have an idea so tell me, but I will grade your answer soon.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now